diff --git a/rest-assured-tutorial/pom.xml b/rest-assured-tutorial/pom.xml index 90875a19ac..43072d3094 100644 --- a/rest-assured-tutorial/pom.xml +++ b/rest-assured-tutorial/pom.xml @@ -5,7 +5,6 @@ rest-assured-tutorial 1.0 rest-assured -<<<<<<< HEAD @@ -214,108 +213,38 @@ wiremock 2.1.7 -======= - - - - 3.5.1 - 2.19.1 - - 1.10.19 - 4.12 - 2.1.7 - 1.3 - 1.2.5 - 2.2.6 - 3.0.0 - - - 1.7.13 - 1.1.3 - - - - - - - org.slf4j - slf4j-api - ${org.slf4j.version} - - - ch.qos.logback - logback-classic - ${logback.version} - - - - org.slf4j - jcl-over-slf4j - ${org.slf4j.version} - runtime - - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - - ->>>>>>> upstream/master io.rest-assured rest-assured - ${rest-assured.version} + 3.0.0 test - io.rest-assured json-schema-validator - ${rest-assured.version} + 3.0.0 - com.github.fge json-schema-validator - ${json-schema-validator.version} + 2.2.6 - com.github.fge json-schema-core - ${json-schema-core.version} + 1.2.5 -<<<<<<< HEAD junit junit 4.3 test -======= - - - - - junit - junit - ${junit.version} - test - - - - com.github.tomakehurst - wiremock - ${wiremock.version} - test - ->>>>>>> upstream/master org.hamcrest hamcrest-all - ${hamcrest-all.version} - test + 1.3 @@ -324,12 +253,5 @@ 3.2.2 - - org.mockito - mockito-core - ${mockito.version} - test - - diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java index 0fe7df7138..a88ef2efc0 100644 --- a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java @@ -1,29 +1,14 @@ package com.baeldung.restassured; -<<<<<<< HEAD import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -======= -import com.github.fge.jsonschema.SchemaVersion; -import com.github.fge.jsonschema.cfg.ValidationConfiguration; -import com.github.fge.jsonschema.main.JsonSchemaFactory; -import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.client.WireMock; -import io.restassured.module.jsv.JsonSchemaValidator; -import org.junit.Ignore; -import org.junit.Test; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; ->>>>>>> upstream/master import static io.restassured.RestAssured.get; import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath; import static io.restassured.module.jsv.JsonSchemaValidatorSettings.settings; -import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.equalTo; -<<<<<<< HEAD import static org.hamcrest.Matchers.hasItems; import org.junit.After; @@ -34,10 +19,6 @@ import com.github.fge.jsonschema.SchemaVersion; import com.github.fge.jsonschema.cfg.ValidationConfiguration; import com.github.fge.jsonschema.main.JsonSchemaFactory; import com.github.tomakehurst.wiremock.WireMockServer; -======= -import static org.hamcrest.xml.HasXPath.hasXPath; - ->>>>>>> upstream/master public class RestAssuredTest { @@ -63,91 +44,28 @@ public class RestAssuredTest { .body("odd.ck", equalTo(12.2f)); } - private WireMockServer wireMockServer = new WireMockServer(); - private static final String EVENTS_PATH = "/events?id=390"; - private static final String APPLICATION_JSON = "application/json"; - - private static final String GAME_ODDS = "" + - "{" + - " \"id\": 390," + - " \"data\": {" + - " \"countryId\": 35," + - " \"countryName\": \"Norway\"," + - " \"leagueName\": \"Norway 3\"," + - " \"status\": 0," + - " \"sportName\": \"Soccer\"," + - " \"time\": \"2016-06-12T12:00:00Z\"" + - " }," + - " \"odds\": [" + - " {" + - " \"price\": \"1.30\"," + - " \"status\": 0," + - " \"ck\": \"1\"," + - " \"name\": \"1\"" + - " }," + - " {" + - " \"price\": \"5.25\"," + - " \"status\": 0," + - " \"ck\": \"X\"," + - " \"name\": \"X\"" + - " }" + - " ]" + - "}"; - - @Test - public void givenUrl_whenSuccessOnGetsResponse_andJsonHasRequiredKV_thenCorrect() { - - wireMockServer.start(); - configureFor("localhost", 8080); - - stubFor(WireMock.get(urlEqualTo(EVENTS_PATH)).willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", APPLICATION_JSON) - .withBody(GAME_ODDS))); + public void givenUrl_whenSuccessOnGetsResponse_andJsonHasRequiredKV_thenCorrect() { get("/events?id=390").then().statusCode(200).assertThat() -<<<<<<< HEAD .body("id", equalTo("390")); -======= - .body("id", equalTo(390)); ->>>>>>> upstream/master - wireMockServer.stop(); } - @Test public void givenUrl_whenJsonResponseHasArrayWithGivenValuesUnderKey_thenCorrect() { -<<<<<<< HEAD get("/events?id=390").then().assertThat() .body("odds.price", hasItems(1.30f, 5.25f, 2.70f, 1.20f)); -======= - - wireMockServer.start(); - configureFor("localhost", 8080); - - stubFor(WireMock.get(urlEqualTo(EVENTS_PATH)).willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", APPLICATION_JSON) - .withBody(GAME_ODDS))); - - get("/events?id=390").then().assertThat() - .body("odds.price", hasItems("1.30", "5.25")); - - wireMockServer.stop(); ->>>>>>> upstream/master } - - @Test @Ignore + @Test public void givenUrl_whenJsonResponseConformsToSchema_thenCorrect() { get("/events?id=390").then().assertThat() .body(matchesJsonSchemaInClasspath("event_0.json")); } - @Test @Ignore + @Test public void givenUrl_whenValidatesResponseWithInstanceSettings_thenCorrect() { JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory .newBuilder() @@ -164,11 +82,10 @@ public class RestAssuredTest { } - @Test @Ignore + @Test public void givenUrl_whenValidatesResponseWithStaticSettings_thenCorrect() { get("/events?id=390") -<<<<<<< HEAD .then() .assertThat() .body(matchesJsonSchemaInClasspath("event_0.json").using( @@ -184,75 +101,6 @@ public class RestAssuredTest { private static String getEventJson() { return Util.inputStreamToString(new RestAssuredTest().getClass() .getResourceAsStream("/event_0.json")); -======= - .then() - .assertThat() - .body(matchesJsonSchemaInClasspath("event_0.json").using( - settings().with().checkedValidation(false))); - - } - - @Test @Ignore - public void givenUrl_whenCheckingFloatValuePasses_thenCorrect() { - get("/odd").then().assertThat().body("odd.ck", equalTo(12.2f)); - } - - @Test @Ignore - public void givenUrl_whenXmlResponseValueTestsEqual_thenCorrect() { - post("/employees").then().assertThat() - .body("employees.employee.first-name", equalTo("Jane")); - } - - @Test @Ignore - public void givenUrl_whenMultipleXmlValuesTestEqual_thenCorrect() { - post("/employees").then().assertThat() - .body("employees.employee.first-name", equalTo("Jane")) - .body("employees.employee.last-name", equalTo("Daisy")) - .body("employees.employee.sex", equalTo("f")); - } - - @Test @Ignore - public void givenUrl_whenMultipleXmlValuesTestEqualInShortHand_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body("employees.employee.first-name", equalTo("Jane"), - "employees.employee.last-name", equalTo("Daisy"), - "employees.employee.sex", equalTo("f")); - } - - @Test @Ignore - public void givenUrl_whenValidatesXmlUsingXpath_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body(hasXPath("/employees/employee/first-name", - containsString("Ja"))); - - } - - @Test @Ignore - public void givenUrl_whenValidatesXmlUsingXpath2_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body(hasXPath("/employees/employee/first-name[text()='Jane']")); - - } - - @Test @Ignore - public void givenUrl_whenVerifiesScienceTeacherFromXml_thenCorrect() { - get("/teachers") - .then() - .body("teachers.teacher.find { it.@department == 'science' }.subject", - hasItems("math", "physics")); - } - - @Test @Ignore - public void givenUrl_whenVerifiesOddPricesAccuratelyByStatus_thenCorrect() { - get("/odds").then().body("odds.findAll { it.status > 0 }.price", - hasItems(1.30f, 1.20f)); ->>>>>>> upstream/master } }