11/*
22 * MIT License
33 *
4- * Copyright (c) 2024 Hydrologic Engineering Center
4+ * Copyright (c) 2025 Hydrologic Engineering Center
55 *
66 * Permission is hereby granted, free of charge, to any person obtaining a copy
77 * of this software and associated documentation files (the "Software"), to deal
2424
2525package mil .army .usace .hec .cwms .data .api .client .controllers ;
2626
27- import mil .army .usace .hec .cwms .data .api .client .model .LocationLevel ;
28- import mil .army .usace .hec .cwms .data .api .client .model .LocationLevels ;
29- import mil .army .usace .hec .cwms .data .api .client .model .RadarObjectMapper ;
30- import mil .army .usace .hec .cwms .data .api .client .model .SpecifiedLevel ;
31- import mil .army .usace .hec .cwms .data .api .client .model .TimeSeries ;
32- import org .junit .jupiter .api .Test ;
27+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
28+ import static org .junit .jupiter .api .Assertions .assertEquals ;
29+ import static org .junit .jupiter .api .Assertions .assertFalse ;
30+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
31+ import static org .junit .jupiter .api .Assertions .assertTrue ;
3332
3433import java .io .IOException ;
3534import java .time .Instant ;
3837import java .util .List ;
3938import java .util .Optional ;
4039import java .util .Set ;
41-
42- import static org .junit .jupiter .api .Assertions .*;
40+ import mil .army .usace .hec .cwms .data .api .client .model .ConstantLocationLevel ;
41+ import mil .army .usace .hec .cwms .data .api .client .model .LocationLevel ;
42+ import mil .army .usace .hec .cwms .data .api .client .model .LocationLevelConstituent ;
43+ import mil .army .usace .hec .cwms .data .api .client .model .LocationLevels ;
44+ import mil .army .usace .hec .cwms .data .api .client .model .RadarObjectMapper ;
45+ import mil .army .usace .hec .cwms .data .api .client .model .SeasonalLocationLevel ;
46+ import mil .army .usace .hec .cwms .data .api .client .model .SpecifiedLevel ;
47+ import mil .army .usace .hec .cwms .data .api .client .model .TimeSeries ;
48+ import mil .army .usace .hec .cwms .data .api .client .model .TimeSeriesLocationLevel ;
49+ import mil .army .usace .hec .cwms .data .api .client .model .VirtualLocationLevel ;
50+ import org .junit .jupiter .api .Test ;
4351
4452class TestLevelController extends TestController {
4553
@@ -114,13 +122,51 @@ void testRetrieveLocationLevels() throws IOException {
114122 assertEquals ("Top of Flood" , level .get ().getSpecifiedLevelId ());
115123 assertEquals (LocationLevel .ParameterTypeIdEnum .INST , level .get ().getParameterTypeId ());
116124 assertEquals ("Elev" , level .get ().getParameterId ());
117- assertEquals (321.564 , level .get ().getConstantValue ());
125+ assertEquals (321.564 , (( ConstantLocationLevel ) level .get () ).getConstantValue ());
118126 assertEquals ("m" , level .get ().getLevelUnitsId ());
119127 ZonedDateTime effectiveDate = ZonedDateTime .of (1900 , 1 , 1 , 5 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
120128 assertEquals (effectiveDate .toInstant (), level .get ().getLevelDate ().toInstant ());
121129 assertEquals ("0" , level .get ().getDurationId ());
122130 }
123131
132+ @ Test
133+ void testRetrieveLocationLevelSubtypes () throws IOException {
134+ String resource = "radar/v2/json/location_levels.json" ;
135+ String collect = readJsonFile (resource );
136+ mockHttpServer .enqueue (collect );
137+ mockHttpServer .start ();
138+ LocationLevelEndpointInput .GetAll input = LocationLevelEndpointInput .getAll ()
139+ .officeId ("LRL" );
140+ LocationLevels locationLevels = new LevelController ().retrieveLocationLevels (buildConnectionInfo (), input );
141+ assertTrue (locationLevels .getLevels ().stream ()
142+ .anyMatch (l -> l instanceof VirtualLocationLevel ));
143+ assertTrue (locationLevels .getLevels ().stream ()
144+ .anyMatch (l -> l instanceof ConstantLocationLevel ));
145+ assertTrue (locationLevels .getLevels ().stream ()
146+ .anyMatch (l -> l instanceof TimeSeriesLocationLevel ));
147+ assertTrue (locationLevels .getLevels ().stream ()
148+ .anyMatch (l -> l instanceof SeasonalLocationLevel ));
149+ }
150+
151+ @ Test
152+ void testRetrieveVirtualLevel () throws IOException {
153+ String resource = "radar/v2/json/location_levels.json" ;
154+ String collect = readJsonFile (resource );
155+ mockHttpServer .enqueue (collect );
156+ mockHttpServer .start ();
157+ LocationLevelEndpointInput .GetAll input = LocationLevelEndpointInput .getAll ()
158+ .officeId ("LRL" );
159+ LocationLevels locationLevels = new LevelController ().retrieveLocationLevels (buildConnectionInfo (), input );
160+ VirtualLocationLevel virtualLevel = (VirtualLocationLevel ) locationLevels .getLevels ().stream ()
161+ .filter (l -> l instanceof VirtualLocationLevel )
162+ .findAny ()
163+ .get ();
164+ assertTrue (virtualLevel .getConstituents ().stream ()
165+ .anyMatch (l -> !(l instanceof LocationLevelConstituent )));
166+ assertTrue (virtualLevel .getConstituents ().stream ()
167+ .anyMatch (l -> l instanceof LocationLevelConstituent ));
168+ }
169+
124170 @ Test
125171 void testRetrieveLocationLevel () throws IOException {
126172 String resource = "radar/v2/json/location_level.json" ;
@@ -135,10 +181,12 @@ void testRetrieveLocationLevel() throws IOException {
135181 assertEquals ("Bottom of Inlet" , level .getSpecifiedLevelId ());
136182 assertEquals (LocationLevel .ParameterTypeIdEnum .INST , level .getParameterTypeId ());
137183 assertEquals ("Elev" , level .getParameterId ());
138- assertEquals (145.6944 , level .getConstantValue ());
184+ assertEquals (145.6944 , (( ConstantLocationLevel ) level ) .getConstantValue ());
139185 assertEquals ("m" , level .getLevelUnitsId ());
140186 assertEquals (instant , level .getLevelDate ().toInstant ());
141187 assertEquals ("0" , level .getDurationId ());
188+ Instant expiration = Instant .parse ("2900-01-01T06:00:00Z" );
189+ assertEquals (expiration , level .getExpirationDate ().toInstant ());
142190 }
143191
144192 @ Test
@@ -175,7 +223,7 @@ void testLevelAsTimeSeries() throws IOException {
175223 String collect = readJsonFile (resource );
176224 mockHttpServer .enqueue (collect );
177225 mockHttpServer .start ();
178- LocationLevel locationLevel = RadarObjectMapper .mapJsonToObject (collect , LocationLevel .class );
226+ LocationLevel locationLevel = RadarObjectMapper .mapJsonToObject (collect , TimeSeriesLocationLevel .class );
179227 Instant begin = Instant .parse ("2023-06-01T07:00:00Z" );
180228 Instant end = Instant .parse ("2023-06-11T07:00:00Z" );
181229 String unit = locationLevel .getLevelUnitsId ();
0 commit comments