Rest-assured fix (#2764)

This commit is contained in:
Grzegorz Piwowarek 2017-10-19 19:13:29 +02:00 committed by GitHub
parent 01406f1c8b
commit aed9c8bfa8
4 changed files with 21 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package com.baeldung.restassured;
import com.github.tomakehurst.wiremock.WireMockServer;
import io.restassured.RestAssured;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -14,7 +15,8 @@ import static io.restassured.RestAssured.get;
import static org.hamcrest.Matchers.hasItems;
public class RestAssured2IntegrationTest {
private static WireMockServer wireMockServer = new WireMockServer();
private static final int PORT = 8084;
private static WireMockServer wireMockServer = new WireMockServer(PORT);
private static final String EVENTS_PATH = "/odds";
private static final String APPLICATION_JSON = "application/json";
@ -24,7 +26,8 @@ public class RestAssured2IntegrationTest {
public static void before() throws Exception {
System.out.println("Setting up!");
wireMockServer.start();
configureFor("localhost", 8080);
configureFor("localhost", PORT);
RestAssured.port = PORT;
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
aResponse().withStatus(200)
.withHeader("Content-Type", APPLICATION_JSON)
@ -38,7 +41,6 @@ public class RestAssured2IntegrationTest {
}
private static String getJson() {
return Util.inputStreamToString(RestAssured2IntegrationTest.class
.getResourceAsStream("/odds.json"));
}

View File

@ -4,6 +4,7 @@ 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 io.restassured.RestAssured;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -20,8 +21,9 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
public class RestAssuredIntegrationTest {
private static final int PORT = 8083;
private static WireMockServer wireMockServer = new WireMockServer(PORT);
private static 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 = getEventJson();
@ -30,7 +32,8 @@ public class RestAssuredIntegrationTest {
public static void before() throws Exception {
System.out.println("Setting up!");
wireMockServer.start();
configureFor("localhost", 8080);
RestAssured.port = PORT;
configureFor("localhost", PORT);
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
aResponse().withStatus(200)
.withHeader("Content-Type", APPLICATION_JSON)

View File

@ -1,6 +1,7 @@
package com.baeldung.restassured;
import com.github.tomakehurst.wiremock.WireMockServer;
import io.restassured.RestAssured;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -14,7 +15,8 @@ import static io.restassured.RestAssured.get;
import static org.hamcrest.Matchers.hasItems;
public class RestAssuredXML2IntegrationTest {
private static WireMockServer wireMockServer = new WireMockServer();
private static final int PORT = 8082;
private static WireMockServer wireMockServer = new WireMockServer(PORT);
private static final String EVENTS_PATH = "/teachers";
private static final String APPLICATION_XML = "application/xml";
@ -24,7 +26,8 @@ public class RestAssuredXML2IntegrationTest {
public static void before() throws Exception {
System.out.println("Setting up!");
wireMockServer.start();
configureFor("localhost", 8080);
RestAssured.port = PORT;
configureFor("localhost", PORT);
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
aResponse().withStatus(200)
.withHeader("Content-Type", APPLICATION_XML)

View File

@ -1,6 +1,7 @@
package com.baeldung.restassured;
import com.github.tomakehurst.wiremock.WireMockServer;
import io.restassured.RestAssured;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -16,7 +17,9 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.xml.HasXPath.hasXPath;
public class RestAssuredXMLIntegrationTest {
private static WireMockServer wireMockServer = new WireMockServer();
private static final int PORT = 8081;
private static WireMockServer wireMockServer = new WireMockServer(PORT);
private static final String EVENTS_PATH = "/employees";
private static final String APPLICATION_XML = "application/xml";
private static final String EMPLOYEES = getXml();
@ -25,7 +28,8 @@ public class RestAssuredXMLIntegrationTest {
public static void before() throws Exception {
System.out.println("Setting up!");
wireMockServer.start();
configureFor("localhost", 8080);
configureFor("localhost", PORT);
RestAssured.port = PORT;
stubFor(post(urlEqualTo(EVENTS_PATH)).willReturn(
aResponse().withStatus(200)
.withHeader("Content-Type", APPLICATION_XML)