2525package cwms .cda .data .dto ;
2626
2727import java .time .ZoneId ;
28+ import java .util .HashMap ;
29+ import java .util .Map ;
2830import static org .junit .jupiter .api .Assertions .*;
2931
3032import cwms .cda .api .errors .FieldException ;
3638import org .apache .commons .io .IOUtils ;
3739import org .junit .jupiter .api .Test ;
3840
39- final class AccessToWaterTimeSeriesIdentifierTest {
41+ final class TypedTimeSeriesIdentifierTest {
4042
4143 @ Test
4244 void createAccessToWaterTimeSeriesData_allFieldsProvided_success () {
@@ -47,16 +49,23 @@ void createAccessToWaterTimeSeriesData_allFieldsProvided_success() {
4749 .withIntervalOffsetMinutes (0L )
4850 .withZoneId (ZoneId .of ("UTC" ))
4951 .build ();
50- AccessToWaterTimeSeriesIdentifier item = new AccessToWaterTimeSeriesIdentifier .Builder ()
52+ TimeSeriesIdentifierDescriptor tsDescriptor2 = new TimeSeriesIdentifierDescriptor .Builder ()
53+ .withTimeSeriesId ("VANL.Flow.Inst.15Minutes.0.Ccp-Rev" )
54+ .withOfficeId ("SWT" )
55+ .withActive (true )
56+ .withIntervalOffsetMinutes (0L )
57+ .withZoneId (ZoneId .of ("UTC" ))
58+ .build ();
59+ TypedTimeSeriesIdentifiers items = new TypedTimeSeriesIdentifiers .Builder ()
5160 .withLocationId (CwmsId .buildCwmsId ("SWT" , "VANL" ))
52- .withTimeSeriesIdDescriptor ( tsDescriptor )
53- .withTsType ( "STAGE" )
61+ .withTypeToTsId ( "STAGE" , tsDescriptor )
62+ .withTypeToTsId ( "OUTFLOW" , tsDescriptor2 )
5463 .build ();
5564
5665 assertAll (
57- () -> DTOMatch .assertMatch (CwmsId .buildCwmsId ("SWT" , "VANL" ), item .getLocationId (), "The location ID does not match the provided value " ),
58- () -> DTOMatch .assertMatch (tsDescriptor , item . getTimeSeriesIdDescriptor ( )),
59- () -> assertEquals ( "STAGE" , item . getTsType (), "The time series type does not match the provided value" )
66+ () -> DTOMatch .assertMatch (CwmsId .buildCwmsId ("SWT" , "VANL" ), items .getLocationId (), "Location ID " ),
67+ () -> DTOMatch .assertMatch (tsDescriptor , items . getTypeToTsIdMap (). get ( "STAGE" )),
68+ () -> DTOMatch . assertMatch ( tsDescriptor2 , items . getTypeToTsIdMap (). get ( "OUTFLOW" ) )
6069 );
6170 }
6271
@@ -69,30 +78,15 @@ void createAccessToWaterTimeSeriesData_missingField_throwsFieldException() {
6978 .withIntervalOffsetMinutes (0L )
7079 .withZoneId (ZoneId .of ("UTC" ))
7180 .build ();
81+ Map <String , TimeSeriesIdentifierDescriptor > typeToTsIdMap = new HashMap <>();
82+ typeToTsIdMap .put ("STAGE" , tsDescriptor );
7283 assertAll (
7384 () -> assertThrows (FieldException .class , () -> {
74- AccessToWaterTimeSeriesIdentifier item = new AccessToWaterTimeSeriesIdentifier .Builder ()
75- .withTimeSeriesIdDescriptor (tsDescriptor )
76- .withTsType ("STAGE" )
77- .build ();
78- item .validate ();
79- }, "The validate method should have thrown a FieldException because the location ID is missing" ),
80-
81- () -> assertThrows (FieldException .class , () -> {
82- AccessToWaterTimeSeriesIdentifier item = new AccessToWaterTimeSeriesIdentifier .Builder ()
83- .withLocationId (CwmsId .buildCwmsId ("SWT" , "VANL" ))
84- .withTsType ("STAGE" )
85- .build ();
86- item .validate ();
87- }, "The validate method should have thrown a FieldException because the TimeSeries ID is missing" ),
88-
89- () -> assertThrows (FieldException .class , () -> {
90- AccessToWaterTimeSeriesIdentifier item = new AccessToWaterTimeSeriesIdentifier .Builder ()
91- .withLocationId (CwmsId .buildCwmsId ("SWT" , "VANL" ))
92- .withTimeSeriesIdDescriptor (tsDescriptor )
85+ TypedTimeSeriesIdentifiers item = new TypedTimeSeriesIdentifiers .Builder ()
86+ .withTypeToTsIdMap (typeToTsIdMap )
9387 .build ();
9488 item .validate ();
95- }, "The validate method should have thrown a FieldException because the time series type is missing" )
89+ }, "The validate method should have thrown a FieldException because the location ID is missing" )
9690 );
9791 }
9892
@@ -105,15 +99,14 @@ void createAccessToWaterTimeSeriesData_serialize_roundtrip() {
10599 .withIntervalOffsetMinutes (0L )
106100 .withZoneId (ZoneId .of ("UTC" ))
107101 .build ();
108- AccessToWaterTimeSeriesIdentifier data = new AccessToWaterTimeSeriesIdentifier .Builder ()
102+ TypedTimeSeriesIdentifiers data = new TypedTimeSeriesIdentifiers .Builder ()
109103 .withLocationId (CwmsId .buildCwmsId ("SWT" , "VANL" ))
110- .withTimeSeriesIdDescriptor (tsDescriptor )
111- .withTsType ("STAGE" )
104+ .withTypeToTsId ("STAGE" , tsDescriptor )
112105 .build ();
113106
114107 ContentType contentType = new ContentType (Formats .JSON );
115108 String json = Formats .format (contentType , data );
116- AccessToWaterTimeSeriesIdentifier deserialized = Formats .parseContent (contentType , json , AccessToWaterTimeSeriesIdentifier .class );
109+ TypedTimeSeriesIdentifiers deserialized = Formats .parseContent (contentType , json , TypedTimeSeriesIdentifiers .class );
117110 DTOMatch .assertMatch (data , deserialized );
118111 }
119112
@@ -126,17 +119,16 @@ void createAccessToWaterTimeSeriesData_deserialize() throws Exception {
126119 .withIntervalOffsetMinutes (0L )
127120 .withZoneId (ZoneId .of ("UTC" ))
128121 .build ();
129- AccessToWaterTimeSeriesIdentifier expected = new AccessToWaterTimeSeriesIdentifier .Builder ()
122+ TypedTimeSeriesIdentifiers expected = new TypedTimeSeriesIdentifiers .Builder ()
130123 .withLocationId (CwmsId .buildCwmsId ("SWT" , "VANL" ))
131- .withTimeSeriesIdDescriptor (tsDescriptor )
132- .withTsType ("STAGE" )
124+ .withTypeToTsId ("STAGE" , tsDescriptor )
133125 .build ();
134126
135- InputStream resource = this .getClass ().getResourceAsStream ("/cwms/cda/data/dto/access_to_water_time_series_data .json" );
127+ InputStream resource = this .getClass ().getResourceAsStream ("/cwms/cda/data/dto/typed_time_series_identifiers .json" );
136128 assertNotNull (resource );
137129 String json = IOUtils .toString (resource , StandardCharsets .UTF_8 );
138130 ContentType contentType = new ContentType (Formats .JSON );
139- AccessToWaterTimeSeriesIdentifier deserialized = Formats .parseContent (contentType , json , AccessToWaterTimeSeriesIdentifier .class );
131+ TypedTimeSeriesIdentifiers deserialized = Formats .parseContent (contentType , json , TypedTimeSeriesIdentifiers .class );
140132 DTOMatch .assertMatch (expected , deserialized );
141133 }
142134}
0 commit comments