25
25
package cwms .cda .data .dto ;
26
26
27
27
import java .time .ZoneId ;
28
+ import java .util .HashMap ;
29
+ import java .util .Map ;
28
30
import static org .junit .jupiter .api .Assertions .*;
29
31
30
32
import cwms .cda .api .errors .FieldException ;
36
38
import org .apache .commons .io .IOUtils ;
37
39
import org .junit .jupiter .api .Test ;
38
40
39
- final class AccessToWaterTimeSeriesIdentifierTest {
41
+ final class TypedTimeSeriesIdentifierTest {
40
42
41
43
@ Test
42
44
void createAccessToWaterTimeSeriesData_allFieldsProvided_success () {
@@ -47,16 +49,23 @@ void createAccessToWaterTimeSeriesData_allFieldsProvided_success() {
47
49
.withIntervalOffsetMinutes (0L )
48
50
.withZoneId (ZoneId .of ("UTC" ))
49
51
.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 ()
51
60
.withLocationId (CwmsId .buildCwmsId ("SWT" , "VANL" ))
52
- .withTimeSeriesIdDescriptor ( tsDescriptor )
53
- .withTsType ( "STAGE" )
61
+ .withTypeToTsId ( "STAGE" , tsDescriptor )
62
+ .withTypeToTsId ( "OUTFLOW" , tsDescriptor2 )
54
63
.build ();
55
64
56
65
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" ) )
60
69
);
61
70
}
62
71
@@ -69,30 +78,15 @@ void createAccessToWaterTimeSeriesData_missingField_throwsFieldException() {
69
78
.withIntervalOffsetMinutes (0L )
70
79
.withZoneId (ZoneId .of ("UTC" ))
71
80
.build ();
81
+ Map <String , TimeSeriesIdentifierDescriptor > typeToTsIdMap = new HashMap <>();
82
+ typeToTsIdMap .put ("STAGE" , tsDescriptor );
72
83
assertAll (
73
84
() -> 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 )
93
87
.build ();
94
88
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" )
96
90
);
97
91
}
98
92
@@ -105,15 +99,14 @@ void createAccessToWaterTimeSeriesData_serialize_roundtrip() {
105
99
.withIntervalOffsetMinutes (0L )
106
100
.withZoneId (ZoneId .of ("UTC" ))
107
101
.build ();
108
- AccessToWaterTimeSeriesIdentifier data = new AccessToWaterTimeSeriesIdentifier .Builder ()
102
+ TypedTimeSeriesIdentifiers data = new TypedTimeSeriesIdentifiers .Builder ()
109
103
.withLocationId (CwmsId .buildCwmsId ("SWT" , "VANL" ))
110
- .withTimeSeriesIdDescriptor (tsDescriptor )
111
- .withTsType ("STAGE" )
104
+ .withTypeToTsId ("STAGE" , tsDescriptor )
112
105
.build ();
113
106
114
107
ContentType contentType = new ContentType (Formats .JSON );
115
108
String json = Formats .format (contentType , data );
116
- AccessToWaterTimeSeriesIdentifier deserialized = Formats .parseContent (contentType , json , AccessToWaterTimeSeriesIdentifier .class );
109
+ TypedTimeSeriesIdentifiers deserialized = Formats .parseContent (contentType , json , TypedTimeSeriesIdentifiers .class );
117
110
DTOMatch .assertMatch (data , deserialized );
118
111
}
119
112
@@ -126,17 +119,16 @@ void createAccessToWaterTimeSeriesData_deserialize() throws Exception {
126
119
.withIntervalOffsetMinutes (0L )
127
120
.withZoneId (ZoneId .of ("UTC" ))
128
121
.build ();
129
- AccessToWaterTimeSeriesIdentifier expected = new AccessToWaterTimeSeriesIdentifier .Builder ()
122
+ TypedTimeSeriesIdentifiers expected = new TypedTimeSeriesIdentifiers .Builder ()
130
123
.withLocationId (CwmsId .buildCwmsId ("SWT" , "VANL" ))
131
- .withTimeSeriesIdDescriptor (tsDescriptor )
132
- .withTsType ("STAGE" )
124
+ .withTypeToTsId ("STAGE" , tsDescriptor )
133
125
.build ();
134
126
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" );
136
128
assertNotNull (resource );
137
129
String json = IOUtils .toString (resource , StandardCharsets .UTF_8 );
138
130
ContentType contentType = new ContentType (Formats .JSON );
139
- AccessToWaterTimeSeriesIdentifier deserialized = Formats .parseContent (contentType , json , AccessToWaterTimeSeriesIdentifier .class );
131
+ TypedTimeSeriesIdentifiers deserialized = Formats .parseContent (contentType , json , TypedTimeSeriesIdentifiers .class );
140
132
DTOMatch .assertMatch (expected , deserialized );
141
133
}
142
134
}
0 commit comments