55import org .junit .AfterClass ;
66import org .junit .BeforeClass ;
77import org .junit .Test ;
8-
98import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
109import static com .github .tomakehurst .wiremock .client .WireMock .configureFor ;
10+ import static com .github .tomakehurst .wiremock .client .WireMock .containing ;
1111import static com .github .tomakehurst .wiremock .client .WireMock .get ;
12+ import static com .github .tomakehurst .wiremock .client .WireMock .post ;
1213import static com .github .tomakehurst .wiremock .client .WireMock .stubFor ;
1314import static com .github .tomakehurst .wiremock .client .WireMock .urlEqualTo ;
1415import static io .restassured .RestAssured .get ;
16+ import static io .restassured .RestAssured .with ;
1517import static org .hamcrest .Matchers .hasItems ;
1618
1719public class RestAssured2IntegrationTest {
@@ -29,20 +31,32 @@ public static void before() throws Exception {
2931 configureFor ("localhost" , PORT );
3032 RestAssured .port = PORT ;
3133 stubFor (get (urlEqualTo (EVENTS_PATH )).willReturn (
32- aResponse ().withStatus (200 )
34+ aResponse ().withStatus (200 )
3335 .withHeader ("Content-Type" , APPLICATION_JSON )
3436 .withBody (ODDS )));
37+ stubFor (post (urlEqualTo ("/odds/new" ))
38+ .withRequestBody (containing ("{\" price\" :5.25,\" status\" :1,\" ck\" :13.1,\" name\" :\" X\" }" ))
39+ .willReturn (aResponse ().withStatus (201 )));
3540 }
3641
3742 @ Test
3843 public void givenUrl_whenVerifiesOddPricesAccuratelyByStatus_thenCorrect () {
39- get ("/odds" ).then ().body ("odds.findAll { it.status > 0 }.price" ,
40- hasItems (5.25f , 1.2f ));
44+ get ("/odds" ).then ().body ("odds.findAll { it.status > 0 }.price" ,
45+ hasItems (5.25f , 1.2f ));
46+ }
47+
48+ @ Test
49+ public void whenRequestedPost_thenCreated () {
50+ with ().body (new Odd (5.25f , 1 , 13.1f , "X" ))
51+ .when ()
52+ .request ("POST" , "/odds/new" )
53+ .then ()
54+ .statusCode (201 );
4155 }
4256
4357 private static String getJson () {
4458 return Util .inputStreamToString (RestAssured2IntegrationTest .class
45- .getResourceAsStream ("/odds.json" ));
59+ .getResourceAsStream ("/odds.json" ));
4660 }
4761
4862 @ AfterClass
0 commit comments