5050import static io .restassured .RestAssured .given ;
5151import static org .hamcrest .Matchers .is ;
5252import static org .junit .jupiter .api .Assertions .assertEquals ;
53- import static org .junit .jupiter .api .Assertions .assertNotNull ;
5453
5554@ Tag ("integration" )
5655class RatingsControllerTestVerticalDatumIT extends DataApiTestIT {
@@ -142,8 +141,9 @@ static void cleanUp() {
142141
143142 @ MethodSource (value = "provideDatumCombinations" )
144143 @ ParameterizedTest
145- void test_store_vertical_datum_null_vd_null_create (TestLocationIds locId ,
146- TestLocationVerticalDatumData testData ) throws Exception {
144+ void test_vertical_datum_get_all (TestLocationIds locId , TestLocationVerticalDatumData testData ) throws Exception {
145+ //This tests getting a rating with various combinations of native location datum and requested datum
146+ //Storing a rating without any vertical datum info, then requesting it back with various datum requests
147147 String xml = readVerticalDatumRatingXml (locId ._locationId );
148148 RatingSet originalRatingSet = RatingXmlFactory .ratingSet (xml );
149149
@@ -155,6 +155,65 @@ void test_store_vertical_datum_null_vd_null_create(TestLocationIds locId,
155155
156156 storeRatingFromXml (xml , user , storedVerticalDatum );
157157
158+ //Request the one rating id we stored, using the getAll endpoint with a query param filter
159+ String requestedVerticalDatum = testData ._requestedVerticalDatum == null ? "" : testData ._requestedVerticalDatum .toString ();
160+ ExtractableResponse <Response > response = given ()
161+ .log ().ifValidationFails (LogDetail .ALL , true )
162+ .contentType (Formats .XMLV2 )
163+ .queryParam (OFFICE , SPK )
164+ .queryParam (DATUM , requestedVerticalDatum )
165+ .queryParam (NAME , ratingId )
166+ .when ()
167+ .redirects ()
168+ .follow (true )
169+ .redirects ()
170+ .max (3 )
171+ .get ("/ratings" )
172+ .then ()
173+ .assertThat ()
174+ .log ().ifValidationFails (LogDetail .ALL , true )
175+ .statusCode (is (HttpServletResponse .SC_OK ))
176+ .contentType (is (Formats .XMLV2 ))
177+ .extract ();
178+
179+ deleteRatingEffectiveDates (user , ratingId );
180+
181+ RatingSet receivedRatingSet = RatingXmlFactory .ratingSet (response .body ().asString ());
182+ VerticalDatumContainer receivedDatumContainer = receivedRatingSet .getVerticalDatumContainer ();
183+ assertEquals (locId ._nativeDatum == null , receivedDatumContainer == null , "Received VerticalDatumContainer presence mismatch. Expected " + (locId ._nativeDatum == null ? "null" : "not null" ));
184+
185+
186+ VerticalDatum expectedDatum = testData ._requestedVerticalDatum ;
187+
188+ if (testData ._requestedVerticalDatum == VerticalDatum .NATIVE || testData ._requestedVerticalDatum == null || locId ._nativeDatum == null ) {
189+ expectedDatum = locId ._nativeDatum ;
190+ }
191+
192+ VerticalDatum receivedDatum = null ;
193+ if (receivedDatumContainer != null ) {
194+ receivedDatum = VerticalDatum .getVerticalDatum (receivedDatumContainer .getCurrentVerticalDatum ());
195+ }
196+
197+ assertEquals (expectedDatum , receivedDatum , "Unexpected Current Vertical Datum received" );
198+ }
199+
200+ @ MethodSource (value = "provideDatumCombinations" )
201+ @ ParameterizedTest
202+ void test_vertical_datum_get_one (TestLocationIds locId , TestLocationVerticalDatumData testData ) throws Exception {
203+ //This tests getting a rating with various combinations of native location datum and requested datum
204+ //Storing a rating without any vertical datum info, then requesting it back with various datum requests
205+ String xml = readVerticalDatumRatingXml (locId ._locationId );
206+ RatingSet originalRatingSet = RatingXmlFactory .ratingSet (xml );
207+
208+ TestAccounts .KeyUser user = TestAccounts .KeyUser .SPK_NORMAL ;
209+ String ratingId = originalRatingSet .getRatingSpec ().getRatingSpecId ();
210+ AbstractRating originalRating = originalRatingSet .getRatings ()[0 ];
211+ originalRating .setVerticalDatumContainer (null );
212+ VerticalDatum storedVerticalDatum = null ;
213+
214+ storeRatingFromXml (xml , user , storedVerticalDatum );
215+
216+ //Use getOne endpoint to get the rating we just stored
158217 String requestedVerticalDatum = testData ._requestedVerticalDatum == null ? "" : testData ._requestedVerticalDatum .toString ();
159218 ExtractableResponse <Response > response = given ()
160219 .log ().ifValidationFails (LogDetail .ALL , true )
@@ -177,21 +236,22 @@ void test_store_vertical_datum_null_vd_null_create(TestLocationIds locId,
177236 deleteRatingEffectiveDates (user , ratingId );
178237
179238 RatingSet receivedRatingSet = RatingXmlFactory .ratingSet (response .body ().asString ());
180- AbstractRating receivedRating = receivedRatingSet .getRatings ()[0 ];
239+ VerticalDatumContainer receivedDatumContainer = receivedRatingSet .getVerticalDatumContainer ();
240+ assertEquals (locId ._nativeDatum == null , receivedDatumContainer == null , "Received VerticalDatumContainer presence mismatch. Expected " + (locId ._nativeDatum == null ? "null" : "not null" ));
181241
182- VerticalDatumContainer receivedVerticalDatumContainer = receivedRating .getVerticalDatumContainer ();
183- assertNotNull (receivedVerticalDatumContainer );
184242
185243 VerticalDatum expectedDatum = testData ._requestedVerticalDatum ;
186244
187- if (testData ._requestedVerticalDatum == VerticalDatum .NATIVE ) {
245+ if (testData ._requestedVerticalDatum == VerticalDatum .NATIVE || testData . _requestedVerticalDatum == null || locId . _nativeDatum == null ) {
188246 expectedDatum = locId ._nativeDatum ;
189247 }
190248
191- VerticalDatum receivedDatum = VerticalDatum .getVerticalDatum (
192- receivedVerticalDatumContainer .getCurrentVerticalDatum ());
249+ VerticalDatum receivedDatum = null ;
250+ if (receivedDatumContainer != null ) {
251+ receivedDatum = VerticalDatum .getVerticalDatum (receivedDatumContainer .getCurrentVerticalDatum ());
252+ }
193253
194- assertEquals (expectedDatum , receivedDatum );
254+ assertEquals (expectedDatum , receivedDatum , "Unexpected Current Vertical Datum received" );
195255 }
196256
197257 private static void storeRatingFromXml (String xml , TestAccounts .KeyUser user , VerticalDatum storedVerticalDatum ) {
@@ -235,6 +295,17 @@ private static void deleteRatingEffectiveDates(TestAccounts.KeyUser user, String
235295 }
236296
237297 private static Stream <Arguments > provideDatumCombinations () {
298+ //This provides information for 3 locations:
299+ // - BASE_LOCATION: no vertical datum
300+ // - LOC_WITH_NAVD88: native datum NAVD88
301+ // - LOC_WITH_NGVD29: native datum NGVD29
302+ //And for each location, we test requesting:
303+ // - null
304+ // - NATIVE
305+ // - NAVD88
306+ // - NGVD29
307+ //
308+ //This creates a 3 x 4 matrix of test cases to cover all combinations of these parameters
238309 return Stream .of (TestLocationIds .values ())
239310 .flatMap (locId -> Stream .of (TestLocationVerticalDatumData .values ())
240311 .map (datum -> Arguments .of (locId , datum )));
0 commit comments