Skip to content

Commit aed9c8b

Browse files
authored
Rest-assured fix (eugenp#2764)
1 parent 01406f1 commit aed9c8b

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎rest-assured/src/test/java/com/baeldung/restassured/RestAssured2IntegrationTest.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.baeldung.restassured;
22

33
import com.github.tomakehurst.wiremock.WireMockServer;
4+
import io.restassured.RestAssured;
45
import org.junit.AfterClass;
56
import org.junit.BeforeClass;
67
import org.junit.Test;
@@ -14,7 +15,8 @@
1415
import static org.hamcrest.Matchers.hasItems;
1516

1617
public class RestAssured2IntegrationTest {
17-
private static WireMockServer wireMockServer = new WireMockServer();
18+
private static final int PORT = 8084;
19+
private static WireMockServer wireMockServer = new WireMockServer(PORT);
1820

1921
private static final String EVENTS_PATH = "/odds";
2022
private static final String APPLICATION_JSON = "application/json";
@@ -24,7 +26,8 @@ public class RestAssured2IntegrationTest {
2426
public static void before() throws Exception {
2527
System.out.println("Setting up!");
2628
wireMockServer.start();
27-
configureFor("localhost", 8080);
29+
configureFor("localhost", PORT);
30+
RestAssured.port = PORT;
2831
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
2932
aResponse().withStatus(200)
3033
.withHeader("Content-Type", APPLICATION_JSON)
@@ -38,7 +41,6 @@ public void givenUrl_whenVerifiesOddPricesAccuratelyByStatus_thenCorrect() {
3841
}
3942

4043
private static String getJson() {
41-
4244
return Util.inputStreamToString(RestAssured2IntegrationTest.class
4345
.getResourceAsStream("/odds.json"));
4446
}

‎rest-assured/src/test/java/com/baeldung/restassured/RestAssuredIntegrationTest.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.fge.jsonschema.cfg.ValidationConfiguration;
55
import com.github.fge.jsonschema.main.JsonSchemaFactory;
66
import com.github.tomakehurst.wiremock.WireMockServer;
7+
import io.restassured.RestAssured;
78
import org.junit.AfterClass;
89
import org.junit.BeforeClass;
910
import org.junit.Test;
@@ -20,8 +21,9 @@
2021
import static org.hamcrest.Matchers.hasItems;
2122

2223
public class RestAssuredIntegrationTest {
24+
private static final int PORT = 8083;
25+
private static WireMockServer wireMockServer = new WireMockServer(PORT);
2326

24-
private static WireMockServer wireMockServer = new WireMockServer();
2527
private static final String EVENTS_PATH = "/events?id=390";
2628
private static final String APPLICATION_JSON = "application/json";
2729
private static final String GAME_ODDS = getEventJson();
@@ -30,7 +32,8 @@ public class RestAssuredIntegrationTest {
3032
public static void before() throws Exception {
3133
System.out.println("Setting up!");
3234
wireMockServer.start();
33-
configureFor("localhost", 8080);
35+
RestAssured.port = PORT;
36+
configureFor("localhost", PORT);
3437
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
3538
aResponse().withStatus(200)
3639
.withHeader("Content-Type", APPLICATION_JSON)

‎rest-assured/src/test/java/com/baeldung/restassured/RestAssuredXML2IntegrationTest.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.baeldung.restassured;
22

33
import com.github.tomakehurst.wiremock.WireMockServer;
4+
import io.restassured.RestAssured;
45
import org.junit.AfterClass;
56
import org.junit.BeforeClass;
67
import org.junit.Test;
@@ -14,7 +15,8 @@
1415
import static org.hamcrest.Matchers.hasItems;
1516

1617
public class RestAssuredXML2IntegrationTest {
17-
private static WireMockServer wireMockServer = new WireMockServer();
18+
private static final int PORT = 8082;
19+
private static WireMockServer wireMockServer = new WireMockServer(PORT);
1820

1921
private static final String EVENTS_PATH = "/teachers";
2022
private static final String APPLICATION_XML = "application/xml";
@@ -24,7 +26,8 @@ public class RestAssuredXML2IntegrationTest {
2426
public static void before() throws Exception {
2527
System.out.println("Setting up!");
2628
wireMockServer.start();
27-
configureFor("localhost", 8080);
29+
RestAssured.port = PORT;
30+
configureFor("localhost", PORT);
2831
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
2932
aResponse().withStatus(200)
3033
.withHeader("Content-Type", APPLICATION_XML)

‎rest-assured/src/test/java/com/baeldung/restassured/RestAssuredXMLIntegrationTest.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.baeldung.restassured;
22

33
import com.github.tomakehurst.wiremock.WireMockServer;
4+
import io.restassured.RestAssured;
45
import org.junit.AfterClass;
56
import org.junit.BeforeClass;
67
import org.junit.Test;
@@ -16,7 +17,9 @@
1617
import static org.hamcrest.xml.HasXPath.hasXPath;
1718

1819
public class RestAssuredXMLIntegrationTest {
19-
private static WireMockServer wireMockServer = new WireMockServer();
20+
private static final int PORT = 8081;
21+
private static WireMockServer wireMockServer = new WireMockServer(PORT);
22+
2023
private static final String EVENTS_PATH = "/employees";
2124
private static final String APPLICATION_XML = "application/xml";
2225
private static final String EMPLOYEES = getXml();
@@ -25,7 +28,8 @@ public class RestAssuredXMLIntegrationTest {
2528
public static void before() throws Exception {
2629
System.out.println("Setting up!");
2730
wireMockServer.start();
28-
configureFor("localhost", 8080);
31+
configureFor("localhost", PORT);
32+
RestAssured.port = PORT;
2933
stubFor(post(urlEqualTo(EVENTS_PATH)).willReturn(
3034
aResponse().withStatus(200)
3135
.withHeader("Content-Type", APPLICATION_XML)

0 commit comments

Comments
 (0)