11package com .baeldung .restassured ;
22
3- <<<<<<< HEAD
43import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
54import static com .github .tomakehurst .wiremock .client .WireMock .configureFor ;
65import static com .github .tomakehurst .wiremock .client .WireMock .get ;
76import static com .github .tomakehurst .wiremock .client .WireMock .stubFor ;
87import static com .github .tomakehurst .wiremock .client .WireMock .urlEqualTo ;
9- =======
10- import com .github .fge .jsonschema .SchemaVersion ;
11- import com .github .fge .jsonschema .cfg .ValidationConfiguration ;
12- import com .github .fge .jsonschema .main .JsonSchemaFactory ;
13- import com .github .tomakehurst .wiremock .WireMockServer ;
14- import com .github .tomakehurst .wiremock .client .WireMock ;
15- import io .restassured .module .jsv .JsonSchemaValidator ;
16- import org .junit .Ignore ;
17- import org .junit .Test ;
18-
19- import static com .github .tomakehurst .wiremock .client .WireMock .*;
20- >>>>>>> upstream /master
218import static io .restassured .RestAssured .get ;
229import static io .restassured .module .jsv .JsonSchemaValidator .matchesJsonSchemaInClasspath ;
2310import static io .restassured .module .jsv .JsonSchemaValidatorSettings .settings ;
24- import static org .hamcrest .Matchers .*;
2511import static org .hamcrest .Matchers .equalTo ;
26- <<<<<<< HEAD
2712import static org .hamcrest .Matchers .hasItems ;
2813
2914import org .junit .After ;
3419import com .github .fge .jsonschema .cfg .ValidationConfiguration ;
3520import com .github .fge .jsonschema .main .JsonSchemaFactory ;
3621import com .github .tomakehurst .wiremock .WireMockServer ;
37- =======
38- import static org .hamcrest .xml .HasXPath .hasXPath ;
39-
40- >>>>>>> upstream /master
4122
4223public class RestAssuredTest {
4324
@@ -63,91 +44,28 @@ public void givenUrl_whenCheckingFloatValuePasses_thenCorrect() {
6344 .body ("odd.ck" , equalTo (12.2f ));
6445 }
6546
66- private WireMockServer wireMockServer = new WireMockServer ();
67- private static final String EVENTS_PATH = "/events?id=390" ;
68- private static final String APPLICATION_JSON = "application/json" ;
69-
70- private static final String GAME_ODDS = "" +
71- "{" +
72- " \" id\" : 390," +
73- " \" data\" : {" +
74- " \" countryId\" : 35," +
75- " \" countryName\" : \" Norway\" ," +
76- " \" leagueName\" : \" Norway 3\" ," +
77- " \" status\" : 0," +
78- " \" sportName\" : \" Soccer\" ," +
79- " \" time\" : \" 2016-06-12T12:00:00Z\" " +
80- " }," +
81- " \" odds\" : [" +
82- " {" +
83- " \" price\" : \" 1.30\" ," +
84- " \" status\" : 0," +
85- " \" ck\" : \" 1\" ," +
86- " \" name\" : \" 1\" " +
87- " }," +
88- " {" +
89- " \" price\" : \" 5.25\" ," +
90- " \" status\" : 0," +
91- " \" ck\" : \" X\" ," +
92- " \" name\" : \" X\" " +
93- " }" +
94- " ]" +
95- "}" ;
96-
97-
9847 @ Test
99- public void givenUrl_whenSuccessOnGetsResponse_andJsonHasRequiredKV_thenCorrect () {
100-
101- wireMockServer .start ();
102- configureFor ("localhost" , 8080 );
103-
104- stubFor (WireMock .get (urlEqualTo (EVENTS_PATH )).willReturn (aResponse ()
105- .withStatus (200 )
106- .withHeader ("Content-Type" , APPLICATION_JSON )
107- .withBody (GAME_ODDS )));
48+ public void givenUrl_whenSuccessOnGetsResponse_andJsonHasRequiredKV_thenCorrect () {
10849
10950 get ("/events?id=390" ).then ().statusCode (200 ).assertThat ()
110- <<<<<<< HEAD
11151 .body ("id" , equalTo ("390" ));
112- =======
113- .body ("id" , equalTo (390 ));
114- >>>>>>> upstream /master
11552
116- wireMockServer .stop ();
11753 }
11854
119-
12055 @ Test
12156 public void givenUrl_whenJsonResponseHasArrayWithGivenValuesUnderKey_thenCorrect () {
122- <<<<<<< HEAD
12357 get ("/events?id=390" ).then ().assertThat ()
12458 .body ("odds.price" , hasItems (1.30f , 5.25f , 2.70f , 1.20f ));
125- =======
126-
127- wireMockServer .start ();
128- configureFor ("localhost" , 8080 );
129-
130- stubFor (WireMock .get (urlEqualTo (EVENTS_PATH )).willReturn (aResponse ()
131- .withStatus (200 )
132- .withHeader ("Content-Type" , APPLICATION_JSON )
133- .withBody (GAME_ODDS )));
134-
135- get ("/events?id=390" ).then ().assertThat ()
136- .body ("odds.price" , hasItems ("1.30" , "5.25" ));
137-
138- wireMockServer .stop ();
139- >>>>>>> upstream /master
14059 }
14160
142-
143- @ Test @ Ignore
61+ @ Test
14462 public void givenUrl_whenJsonResponseConformsToSchema_thenCorrect () {
14563
14664 get ("/events?id=390" ).then ().assertThat ()
14765 .body (matchesJsonSchemaInClasspath ("event_0.json" ));
14866 }
14967
150- @ Test @ Ignore
68+ @ Test
15169 public void givenUrl_whenValidatesResponseWithInstanceSettings_thenCorrect () {
15270 JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory
15371 .newBuilder ()
@@ -164,11 +82,10 @@ public void givenUrl_whenValidatesResponseWithInstanceSettings_thenCorrect() {
16482
16583 }
16684
167- @ Test @ Ignore
85+ @ Test
16886 public void givenUrl_whenValidatesResponseWithStaticSettings_thenCorrect () {
16987
17088 get ("/events?id=390" )
171- <<<<<<< HEAD
17289 .then ()
17390 .assertThat ()
17491 .body (matchesJsonSchemaInClasspath ("event_0.json" ).using (
@@ -184,75 +101,6 @@ public void after() throws Exception {
184101 private static String getEventJson () {
185102 return Util .inputStreamToString (new RestAssuredTest ().getClass ()
186103 .getResourceAsStream ("/event_0.json" ));
187- =======
188- .then ()
189- .assertThat ()
190- .body (matchesJsonSchemaInClasspath ("event_0.json" ).using (
191- settings ().with ().checkedValidation (false )));
192-
193- }
194-
195- @ Test @ Ignore
196- public void givenUrl_whenCheckingFloatValuePasses_thenCorrect () {
197- get ("/odd" ).then ().assertThat ().body ("odd.ck" , equalTo (12.2f ));
198- }
199-
200- @ Test @ Ignore
201- public void givenUrl_whenXmlResponseValueTestsEqual_thenCorrect () {
202- post ("/employees" ).then ().assertThat ()
203- .body ("employees.employee.first-name" , equalTo ("Jane" ));
204- }
205-
206- @ Test @ Ignore
207- public void givenUrl_whenMultipleXmlValuesTestEqual_thenCorrect () {
208- post ("/employees" ).then ().assertThat ()
209- .body ("employees.employee.first-name" , equalTo ("Jane" ))
210- .body ("employees.employee.last-name" , equalTo ("Daisy" ))
211- .body ("employees.employee.sex" , equalTo ("f" ));
212- }
213-
214- @ Test @ Ignore
215- public void givenUrl_whenMultipleXmlValuesTestEqualInShortHand_thenCorrect () {
216- post ("/employees" )
217- .then ()
218- .assertThat ()
219- .body ("employees.employee.first-name" , equalTo ("Jane" ),
220- "employees.employee.last-name" , equalTo ("Daisy" ),
221- "employees.employee.sex" , equalTo ("f" ));
222- }
223-
224- @ Test @ Ignore
225- public void givenUrl_whenValidatesXmlUsingXpath_thenCorrect () {
226- post ("/employees" )
227- .then ()
228- .assertThat ()
229- .body (hasXPath ("/employees/employee/first-name" ,
230- containsString ("Ja" )));
231-
232- }
233-
234- @ Test @ Ignore
235- public void givenUrl_whenValidatesXmlUsingXpath2_thenCorrect () {
236- post ("/employees" )
237- .then ()
238- .assertThat ()
239- .body (hasXPath ("/employees/employee/first-name[text()='Jane']" ));
240-
241- }
242-
243- @ Test @ Ignore
244- public void givenUrl_whenVerifiesScienceTeacherFromXml_thenCorrect () {
245- get ("/teachers" )
246- .then ()
247- .body ("teachers.teacher.find { it.@department == 'science' }.subject" ,
248- hasItems ("math" , "physics" ));
249- }
250-
251- @ Test @ Ignore
252- public void givenUrl_whenVerifiesOddPricesAccuratelyByStatus_thenCorrect () {
253- get ("/odds" ).then ().body ("odds.findAll { it.status > 0 }.price" ,
254- hasItems (1.30f , 1.20f ));
255- >>>>>>> upstream /master
256104 }
257105
258106}
0 commit comments