@@ -183,6 +183,41 @@ public void testFindByRank() {
183
183
184
184
}
185
185
186
+ /**
187
+ * Test findByShipSizeAndRank, currently expects ordering to remain the same, which the spec doesn't require.
188
+ */
189
+ @ Test
190
+ public void testFindByShipSizeAndRank () {
191
+ response = client .target (baseURL + "db/crew/it1" ).request ().post (Entity .json ("{\" name\" :\" Mark\" ,\" rank\" :\" Engineer\" ,\" crewID\" :75,\" ship\" :\" Liberty Saucer\" }" ));
192
+ assertEquals (200 , response .getStatus (), "output: " + response .readEntity (String .class ));
193
+ response = client .target (baseURL + "db/crew/it2" ).request ().post (Entity .json ("{\" name\" :\" Jim\" ,\" rank\" :\" Captain\" ,\" crewID\" :64,\" ship\" :\" Liberty Saucer\" }" ));
194
+ assertEquals (200 , response .getStatus (), "output: " + response .readEntity (String .class ));
195
+ response = client .target (baseURL + "db/crew/it3" ).request ().post (Entity .json ("{\" name\" :\" Alex\" ,\" rank\" :\" Engineer\" ,\" crewID\" :15,\" ship\" :\" WebSphere Battleship\" }" ));
196
+ assertEquals (200 , response .getStatus (), "output: " + response .readEntity (String .class ));
197
+ response = client .target (baseURL + "db/crew/it4" ).request ().post (Entity .json ("{\" name\" :\" Nathan\" ,\" rank\" :\" Captain\" ,\" crewID\" :30,\" ship\" :\" Jakarta Sailboat\" }" ));
198
+ assertEquals (200 , response .getStatus (), "output: " + response .readEntity (String .class ));
199
+
200
+ //Check findByShipSizeAndRank
201
+ response = client .target (baseURL + "db/crew/shipSize/small/rank/Engineer" ).request ().get ();
202
+ JsonReader reader = Json .createReader (new StringReader (response .readEntity (String .class )));
203
+ JsonArray array = reader .readArray ();
204
+ JsonArray expectedArray = Json .createArrayBuilder ().add (Json .createObjectBuilder ().add ("Name" , "Mark" ).add ("CrewID" , 75 ).add ("Ship" , "Liberty Saucer" ).build ()).build ();
205
+ assertEquals (expectedArray , array );
206
+
207
+ response = client .target (baseURL + "db/crew/shipSize/large/rank/Engineer" ).request ().get ();
208
+ reader = Json .createReader (new StringReader (response .readEntity (String .class )));
209
+ array = reader .readArray ();
210
+ expectedArray = Json .createArrayBuilder ().add (Json .createObjectBuilder ().add ("Name" , "Alex" ).add ("CrewID" , 15 ).add ("Ship" , "WebSphere Battleship" ).build ()).build ();
211
+ assertEquals (expectedArray , array );
212
+
213
+ response = client .target (baseURL + "db/crew/shipSize/small/rank/Captain" ).request ().get ();
214
+ reader = Json .createReader (new StringReader (response .readEntity (String .class )));
215
+ array = reader .readArray ();
216
+ expectedArray = Json .createArrayBuilder ().add (Json .createObjectBuilder ().add ("Name" , "Jim" ).add ("CrewID" , 64 ).add ("Ship" , "Liberty Saucer" ).build ())
217
+ .add (Json .createObjectBuilder ().add ("Name" , "Nathan" ).add ("CrewID" , 30 ).add ("Ship" , "Jakarta Sailboat" ).build ()).build ();
218
+ assertEquals (expectedArray , array );
219
+ }
220
+
186
221
187
222
private static boolean isPostgresAvailable () {
188
223
return checkHostAndPort ("localhost" , 5432 );
0 commit comments