@@ -57,6 +57,11 @@ public static void makeGetRequest(String endpoint) {
5757 response = RequestHelpers .sendGetRequestTo (endpoints .get (endpoint ));
5858 responses .add (response );
5959 }
60+ @ When ("^I make a GET request to the (Posts|Comments|Albums|Photos|ToDos|Users) endpoint with a path parameter of (\\ d+)$" )
61+ public static void makeGetRequestWithPathParameter (String endpoint , int pathParam ) {
62+ response = RequestHelpers .sendGetRequestTo (endpoints .get (endpoint ) + "/" + pathParam );
63+ responses .add (response );
64+ }
6065 @ Then ("the response has a status code of {int}" )
6166 public static void verifyResponseStatusCode (int code ) {
6267 assertEquals (code , response .statusCode ());
@@ -82,11 +87,20 @@ public static void verifyNumberOfResultsArrayElements(int numElements) {
8287 }
8388
8489 @ Then ("the response body matches the {string} expected response" )
85- public static void verifyResponseBodyAgainstExpectedResponse (String type ) throws IOException {
86- String filename = EXPECTED_RESPONSES_DIR + type .replaceAll (" " , "" ) + "Response.json" ;
90+ public static void verifyResponseBodyAgainstExpectedResponse (String expectedResponse ) throws IOException {
91+ String filename = EXPECTED_RESPONSES_DIR + expectedResponse .replaceAll (" " , "" ) + "Response.json" ;
8792 String json = Files .readString (new File (filename ).toPath ());
8893 assertEquals (json .replace ("\r " , "" ), response .body ());
8994 }
9095
96+ @ Then ("^the response body matches the (\\ d+).{2} post in the \" (.*)\" expected response$" )
97+ public static void verifyResponseBodyAgainstPartOfExpectedResponse (int index , String expectedResponse ) throws IOException {
98+ String filename = EXPECTED_RESPONSES_DIR + expectedResponse .replaceAll (" " , "" ) + "Response.json" ;
99+ String json = Files .readString (new File (filename ).toPath ());
100+ JSONObject expected = new JSONArray (json ).getJSONObject (index - 1 );
101+ JSONObject actual = new JSONObject (response .body ());
102+ assertEquals (expected .toString (), actual .toString ());
103+ }
104+
91105
92106}
0 commit comments