1313import cwms .cda .formatters .ContentType ;
1414import cwms .cda .formatters .json .JsonV2 ;
1515import fixtures .TestAccounts ;
16+
17+ import java .util .HashMap ;
1618import java .util .List ;
1719import java .util .Objects ;
1820import java .util .stream .Collectors ;
4345import io .restassured .filter .log .LogDetail ;
4446import io .restassured .response .Response ;
4547import org .junit .jupiter .params .ParameterizedTest ;
48+ import org .junit .jupiter .params .provider .CsvSource ;
4649import org .junit .jupiter .params .provider .ValueSource ;
4750
4851import static org .hamcrest .Matchers .*;
4952
5053@ Tag ("integration" )
5154public class CatalogControllerTestIT extends DataApiTestIT {
5255
53- public static final String OFFICE = "SPK" ;
56+ public static final String OFFICE1 = "SPK" ;
57+ public static final String OFFICE2 = "MVP" ;
58+ public static final String OFFICE3 = "LRL" ;
5459
5560 //// These have to match the groups in ts_catalog_setup.sql
5661 public static final String A_TO_M = "A to M" ;
@@ -62,24 +67,34 @@ public class CatalogControllerTestIT extends DataApiTestIT {
6267 @ BeforeAll
6368 static void setup_data () throws Exception {
6469 // Create some locations and create some ts.
65- createLocation ("Alder Springs" ,true , OFFICE );
66- createLocation ("Wet Meadows" ,true , OFFICE );
67- createLocation ("Pine Flat-Outflow" ,true , OFFICE );
68- createLocation ("Flat Lake" ,true , OFFICE );
69-
70- createProject ("Flat Project" , OFFICE );
71- createTimeseries (OFFICE ,"Alder Springs.Precip-Cumulative.Inst.15Minutes.0.raw-cda" );
72- createTimeseries (OFFICE ,"Alder Springs.Precip-INC.Total.15Minutes.15Minutes.calc-cda" );
73- createTimeseries (OFFICE ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.raw-cda" );
74- createTimeseries (OFFICE ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.one" );
75- createTimeseries (OFFICE ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.two" );
76- createTimeseries (OFFICE ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.three" );
77- createTimeseries (OFFICE ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.four" );
78- createTimeseries (OFFICE ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.raw-cda" );
79- createTimeseries (OFFICE ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.one" );
80- createTimeseries (OFFICE ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.two" );
81- createTimeseries (OFFICE ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.three" );
82- createTimeseries (OFFICE ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.four" );
70+ createLocation ("Alder Springs" ,true , OFFICE1 );
71+ createLocation ("Wet Meadows" ,true , OFFICE1 );
72+ createLocation ("Pine Flat-Outflow" ,true , OFFICE1 );
73+ createLocation ("Flat Lake" ,true , OFFICE1 );
74+
75+ createLocation ("LockDam_10" , true , OFFICE2 );
76+ createLocation ("LockDam_01" , true , OFFICE2 );
77+ for (int i =0 ; i < 30 ; i ++) {
78+ createLocation (String .format ("LOckDam_%03d" , i *10 ), true , OFFICE2 );
79+ }
80+
81+ createLocation ("Barkley" , true , OFFICE2 );
82+ createLocation ("Franklin" , true , OFFICE2 );
83+ createLocation ("HorseBranch" , true , OFFICE2 );
84+
85+ createProject ("Flat Project" , OFFICE1 );
86+ createTimeseries (OFFICE1 ,"Alder Springs.Precip-Cumulative.Inst.15Minutes.0.raw-cda" );
87+ createTimeseries (OFFICE1 ,"Alder Springs.Precip-INC.Total.15Minutes.15Minutes.calc-cda" );
88+ createTimeseries (OFFICE1 ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.raw-cda" );
89+ createTimeseries (OFFICE1 ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.one" );
90+ createTimeseries (OFFICE1 ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.two" );
91+ createTimeseries (OFFICE1 ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.three" );
92+ createTimeseries (OFFICE1 ,"Pine Flat-Outflow.Stage.Inst.15Minutes.0.four" );
93+ createTimeseries (OFFICE1 ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.raw-cda" );
94+ createTimeseries (OFFICE1 ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.one" );
95+ createTimeseries (OFFICE1 ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.two" );
96+ createTimeseries (OFFICE1 ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.three" );
97+ createTimeseries (OFFICE1 ,"Wet Meadows.Depth-SWE.Inst.15Minutes.0.four" );
8398
8499 // Complicated
85100 loadSqlDataFromResource ("cwms/cda/data/sql/ts_catalog_setup.sql" );
@@ -89,7 +104,7 @@ static void setup_data() throws Exception {
89104
90105 private static void createProject (String id , String office ) throws SQLException {
91106 CwmsDataApiSetupCallback .getDatabaseLink ().connection (c -> {
92- DSLContext dsl = dslContext (c , OFFICE );
107+ DSLContext dsl = dslContext (c , OFFICE1 );
93108 ProjectDao projectDao = new ProjectDao (dsl );
94109 Project project = new Project .Builder ()
95110 .withLocation (new Location .Builder (id ,
@@ -107,7 +122,7 @@ private static void createProject(String id, String office) throws SQLException
107122
108123 private static void deleteProject (String id , String office ) throws SQLException {
109124 CwmsDataApiSetupCallback .getDatabaseLink ().connection (c -> {
110- DSLContext dsl = dslContext (c , OFFICE );
125+ DSLContext dsl = dslContext (c , OFFICE1 );
111126 ProjectDao projectDao = new ProjectDao (dsl );
112127
113128 projectDao .delete (office , id , DeleteRule .DELETE_KEY );
@@ -117,7 +132,7 @@ private static void deleteProject(String id, String office) throws SQLException
117132 @ AfterAll
118133 static void deload_data () throws Exception {
119134 loadSqlDataFromResource ("cwms/cda/data/sql/ts_catalog_cleanup.sql" );
120- deleteProject ("Flat Project" , OFFICE );
135+ deleteProject ("Flat Project" , OFFICE1 );
121136 cleanupBasins ();
122137 cleanupStreams ();
123138 }
@@ -128,7 +143,7 @@ void test_no_aliased_results_returned(String format) {
128143 given ()
129144 .accept (format )
130145 .log ().ifValidationFails (LogDetail .ALL , true )
131- .queryParam (Controllers .OFFICE , OFFICE )
146+ .queryParam (Controllers .OFFICE , OFFICE1 )
132147 .queryParam (EXCLUDE_EMPTY ,false )
133148 .queryParam (LIKE ,".*-cda$" )
134149 .when ()
@@ -148,7 +163,7 @@ void test_no_aliases_returned(String format) {
148163 Integer numAliases = given ()
149164 .accept (format )
150165 .log ().ifValidationFails (LogDetail .ALL , true )
151- .queryParam (Controllers .OFFICE , OFFICE )
166+ .queryParam (Controllers .OFFICE , OFFICE1 )
152167 .queryParam (EXCLUDE_EMPTY , false )
153168 .when ()
154169 .get ("/catalog/TIMESERIES" )
@@ -167,7 +182,7 @@ void test_no_aliases_returned(String format) {
167182 void test_aliases_returned (String format ) {
168183 Integer numAliases = given ().accept (format )
169184 .log ().ifValidationFails (LogDetail .ALL , true )
170- .queryParam (Controllers .OFFICE , OFFICE )
185+ .queryParam (Controllers .OFFICE , OFFICE1 )
171186 .queryParam (EXCLUDE_EMPTY ,false )
172187 .queryParam (INCLUDE_ALIASES ,true )
173188 .when ()
@@ -187,7 +202,7 @@ void test_aliases_returned(String format) {
187202 void test_alias_is_correct (String format ) throws JsonProcessingException {
188203 Response response = given ().accept (format )
189204 .log ().ifValidationFails (LogDetail .ALL , true )
190- .queryParam (Controllers .OFFICE , OFFICE )
205+ .queryParam (Controllers .OFFICE , OFFICE1 )
191206 .queryParam (EXCLUDE_EMPTY , false )
192207 .queryParam (INCLUDE_ALIASES , true )
193208 .when ()
@@ -225,7 +240,7 @@ void test_alias_is_correct(String format) throws JsonProcessingException {
225240 void test_queries_are_case_insensitive () {
226241 given ()
227242 .accept ("application/json;version=2" )
228- .queryParam (Controllers .OFFICE , OFFICE )
243+ .queryParam (Controllers .OFFICE , OFFICE1 )
229244 .queryParam (EXCLUDE_EMPTY ,false )
230245 .queryParam (LIKE ,"alder spRINgs.*-CDA$" )
231246 .when ()
@@ -240,18 +255,27 @@ void test_queries_are_case_insensitive() {
240255 }
241256
242257 @ ParameterizedTest
243- @ ValueSource (strings = {Formats .JSONV2 , Formats .DEFAULT })
244- void test_all_office_pagination_works (String format ) {
258+ @ CsvSource ({
259+ // Formats.JSONV2 + ",TIMESERIES",
260+ //Formats.DEFAULT + ",TIMESERIES",
261+ Formats .JSONV2 + ",LOCATIONS" //,
262+ // Formats.DEFAULT + ",LOCATIONS"
263+ })
264+ void test_all_office_pagination_works (String format , String endpoint ) {
245265 assertTimeout (Duration .ofMinutes (5 ), () -> {
246- final int pageSize = 50 ;
266+ final int pageSize = 10 ; // artificially low size to force pagination
267+ final HashMap <String ,Object > queryParams = new HashMap <>();
268+ queryParams .put ("page-size" , pageSize );
269+ if (endpoint .equals ("TIMESERIES" )) {
270+ queryParams .put (EXCLUDE_EMPTY ,false );
271+ }
247272 Response initialResponse =
248273 given ()
249274 .log ().ifValidationFails (LogDetail .ALL , true )
250275 .accept (format )
251- .queryParam ("page-size" ,pageSize )
252- .queryParam (EXCLUDE_EMPTY ,false )
276+ .queryParams (queryParams )
253277 .when ()
254- .get ("/catalog/TIMESERIES" )
278+ .get ("/catalog/{data}" , endpoint )
255279 .then ()
256280 .log ().ifValidationFails (LogDetail .ALL , true )
257281 .assertThat ()
@@ -268,7 +292,7 @@ void test_all_office_pagination_works(String format) {
268292 int totalRetrieved = initialResponse .path ("entries.size()" );
269293
270294 String lastRowPreviousPage = initialResponse .path ("entries.last().name" );
271-
295+ queryParams . remove ( "page-size" );
272296 do {
273297 Response pageN =
274298 given ()
@@ -277,7 +301,7 @@ void test_all_office_pagination_works(String format) {
277301 .queryParam ("page" ,nextPage )
278302 .queryParam (EXCLUDE_EMPTY ,false )
279303 .when ()
280- .get ("/catalog/TIMESERIES" )
304+ .get ("/catalog/{data}" , endpoint )
281305 .then ()
282306 .log ().ifValidationFails (LogDetail .ALL , true )
283307 .assertThat ()
@@ -309,7 +333,7 @@ void test_loc_group_with_ts_group() {
309333 // filter by loc group and ts group should find the intersection
310334 given ()
311335 .accept ("application/json;version=2" )
312- .queryParam (Controllers .OFFICE , OFFICE )
336+ .queryParam (Controllers .OFFICE , OFFICE1 )
313337 .queryParam (LOCATION_CATEGORY_LIKE , TEST_CATEGORY )
314338 .queryParam (LOCATION_GROUP_LIKE , N_TO_Z )
315339 .queryParam (TIMESERIES_CATEGORY_LIKE , TEST_CATEGORY )
@@ -339,7 +363,7 @@ void test_loc_group() {
339363 // filter by just loc group
340364 given ()
341365 .accept ("application/json;version=2" )
342- .queryParam (Controllers .OFFICE , OFFICE )
366+ .queryParam (Controllers .OFFICE , OFFICE1 )
343367 .queryParam (LOCATION_CATEGORY_LIKE , TEST_CATEGORY )
344368 .queryParam (LOCATION_GROUP_LIKE , A_TO_M )
345369 .queryParam (EXCLUDE_EMPTY ,false )
@@ -362,7 +386,7 @@ void test_loc_group() {
362386 // filter by just loc group
363387 given ()
364388 .accept ("application/json;version=2" )
365- .queryParam (Controllers .OFFICE , OFFICE )
389+ .queryParam (Controllers .OFFICE , OFFICE1 )
366390 .queryParam (LOCATION_CATEGORY_LIKE , TEST_CATEGORY )
367391 .queryParam (LOCATION_GROUP_LIKE , N_TO_Z )
368392 .queryParam (EXCLUDE_EMPTY ,false )
@@ -397,7 +421,7 @@ void test_ts_with_bounding() {
397421 // we create Wet Meadows with a bounding office of SPK
398422 given ()
399423 .accept ("application/json;version=2" )
400- .queryParam (BOUNDING_OFFICE_LIKE , OFFICE )
424+ .queryParam (BOUNDING_OFFICE_LIKE , OFFICE1 )
401425 .queryParam (LIKE , "^Wet Meadows.*" )
402426 .queryParam (EXCLUDE_EMPTY ,false )
403427 .when ()
@@ -422,7 +446,7 @@ void test_loc_kind() {
422446 // First with just the regex. This should match Flat Lake and Flat Project
423447 given ()
424448 .accept ("application/json;version=2" )
425- .queryParam (Controllers .OFFICE , OFFICE )
449+ .queryParam (Controllers .OFFICE , OFFICE1 )
426450 .queryParam (LIKE , pattern )
427451 .when ()
428452 .get ("/catalog/LOCATIONS" )
@@ -439,7 +463,7 @@ void test_loc_kind() {
439463 // Now add the LOCATION_KIND filter
440464 given ()
441465 .accept ("application/json;version=2" )
442- .queryParam (Controllers .OFFICE , OFFICE )
466+ .queryParam (Controllers .OFFICE , OFFICE1 )
443467 .queryParam (LIKE , pattern )
444468 .queryParam (LOCATION_KIND_LIKE , "PROJECT" ) // just Flat Project
445469 .when ()
@@ -464,7 +488,7 @@ void test_loc_aliases() {
464488 // Retrieve without aliases
465489 given ()
466490 .accept ("application/json;version=2" )
467- .queryParam (Controllers .OFFICE , OFFICE )
491+ .queryParam (Controllers .OFFICE , OFFICE1 )
468492 .queryParam (LIKE , pattern )
469493 .queryParam (INCLUDE_ALIASES , false )
470494 .when ()
@@ -483,7 +507,7 @@ void test_loc_aliases() {
483507 // retrieve with aliases
484508 given ()
485509 .accept ("application/json;version=2" )
486- .queryParam (Controllers .OFFICE , OFFICE )
510+ .queryParam (Controllers .OFFICE , OFFICE1 )
487511 .queryParam (LIKE , pattern )
488512 .queryParam (INCLUDE_ALIASES , true )
489513 .when ()
@@ -550,7 +574,7 @@ void testFilterLocations() throws Exception{
550574 given ()
551575 .log ().ifValidationFails (LogDetail .ALL ,true )
552576 .accept (Formats .JSON )
553- .queryParam (OFFICE , officeId )
577+ .queryParam (OFFICE1 , officeId )
554578 .queryParam (LIKE , String .format ("%s*" , baseLocationName ))
555579 .queryParam (UNIT_SYSTEM , UnitSystem .SI .getValue ())
556580 .when ()
@@ -571,7 +595,7 @@ void testFilterLocations() throws Exception{
571595 given ()
572596 .log ().ifValidationFails (LogDetail .ALL ,true )
573597 .accept (Formats .JSON )
574- .queryParam (OFFICE , officeId )
598+ .queryParam (OFFICE1 , officeId )
575599 .queryParam (LIKE , stringToMatch )
576600 .queryParam (UNIT_SYSTEM , UnitSystem .SI .getValue ())
577601 .when ()
@@ -591,7 +615,7 @@ void testFilterLocations() throws Exception{
591615 given ()
592616 .log ().ifValidationFails (LogDetail .ALL ,true )
593617 .accept (Formats .JSON )
594- .queryParam (OFFICE , officeId )
618+ .queryParam (OFFICE1 , officeId )
595619 .queryParam (LIKE , stringToMatch )
596620 .queryParam (LOCATION_KIND_LIKE , "^(BASIN)$" )
597621 .queryParam (NEGATE_LOCATION_KIND_LIKE , true )
@@ -612,7 +636,7 @@ void testFilterLocations() throws Exception{
612636 given ()
613637 .log ().ifValidationFails (LogDetail .ALL ,true )
614638 .accept (Formats .JSON )
615- .queryParam (OFFICE , officeId )
639+ .queryParam (OFFICE1 , officeId )
616640 .queryParam (LIKE , stringToMatch )
617641 .queryParam (LOCATION_KIND_LIKE , "^(STREAM)*$" )
618642 .queryParam (NEGATE_LOCATION_KIND_LIKE , true )
@@ -632,7 +656,7 @@ void testFilterLocations() throws Exception{
632656 given ()
633657 .log ().ifValidationFails (LogDetail .ALL ,true )
634658 .accept (Formats .JSON )
635- .queryParam (OFFICE , officeId )
659+ .queryParam (OFFICE1 , officeId )
636660 .queryParam (LIKE , stringToMatch )
637661 .queryParam (LOCATION_KIND_LIKE , "NOT:^(STREAM)*$" )
638662 .queryParam (UNIT_SYSTEM , UnitSystem .SI .getValue ())
@@ -651,7 +675,7 @@ void testFilterLocations() throws Exception{
651675 given ()
652676 .log ().ifValidationFails (LogDetail .ALL ,true )
653677 .accept (Formats .JSON )
654- .queryParam (OFFICE , officeId )
678+ .queryParam (OFFICE1 , officeId )
655679 .queryParam (LIKE , stringToMatch )
656680 .queryParam (LOCATION_KIND_LIKE , "NOT:^(STREAM)*$" )
657681 .queryParam (UNIT_SYSTEM , UnitSystem .SI .getValue ())
@@ -671,7 +695,7 @@ void testFilterLocations() throws Exception{
671695 given ()
672696 .log ().ifValidationFails (LogDetail .ALL ,true )
673697 .accept (Formats .JSON )
674- .queryParam (OFFICE , officeId )
698+ .queryParam (OFFICE1 , officeId )
675699 .queryParam (LIKE , stringToMatch )
676700 .queryParam (UNIT_SYSTEM , UnitSystem .SI .getValue ())
677701 .queryParam (LOCATION_KIND_LIKE , "^(BASIN|STREAM)*$" )
@@ -695,7 +719,7 @@ void test_locations_unsupported_param_single() {
695719 given ()
696720 .log ().ifValidationFails (LogDetail .ALL , true )
697721 .accept (Formats .JSON )
698- .queryParam (OFFICE , OFFICE )
722+ .queryParam (OFFICE1 , OFFICE1 )
699723 .queryParam (INCLUDE_EXTENTS , true )
700724 .when ()
701725 .get ("/catalog/LOCATIONS" )
@@ -720,7 +744,7 @@ void test_locations_unsupported_params_multiple() {
720744 given ()
721745 .log ().ifValidationFails (LogDetail .ALL , true )
722746 .accept (Formats .JSON )
723- .queryParam (OFFICE , OFFICE )
747+ .queryParam (OFFICE1 , OFFICE1 )
724748 .queryParam (INCLUDE_EXTENTS , true )
725749 .queryParam (EXCLUDE_EMPTY , true )
726750 .when ()
0 commit comments