Merge pull request #8295 from kwoyke/BAEL-19798

BAEL-19798: Change port number for KarateIntegrationTest
This commit is contained in:
Loredana Crusoveanu 2019-12-04 21:09:04 +02:00 committed by GitHub
commit 592d3e27d7
2 changed files with 12 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package com.baeldung.rest.karate; package com.baeldung.rest.karate;
import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.intuit.karate.junit4.Karate; import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions; import cucumber.api.CucumberOptions;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -14,13 +15,15 @@ import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
@CucumberOptions(features = "classpath:karate") @CucumberOptions(features = "classpath:karate")
public class KarateIntegrationTest { public class KarateIntegrationTest {
private static final WireMockServer wireMockServer = new WireMockServer(); public static final int PORT_NUMBER = 8097;
private static final WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options().port(PORT_NUMBER));
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
wireMockServer.start(); wireMockServer.start();
configureFor("localhost", 8080); configureFor("localhost", PORT_NUMBER);
stubFor(get(urlEqualTo("/user/get")) stubFor(get(urlEqualTo("/user/get"))
.willReturn(aResponse() .willReturn(aResponse()
.withStatus(200) .withStatus(200)

View File

@ -1,41 +1,41 @@
Feature: Testing a REST API with Karate Feature: Testing a REST API with Karate
Scenario: Testing valid GET endpoint Scenario: Testing valid GET endpoint
Given url 'http://localhost:8080/user/get' Given url 'http://localhost:8097/user/get'
When method GET When method GET
Then status 200 Then status 200
Scenario: Testing an invalid GET endpoint - 404 Scenario: Testing an invalid GET endpoint - 404
Given url 'http://localhost:8080/user/wrong' Given url 'http://localhost:8097/user/wrong'
When method GET When method GET
Then status 404 Then status 404
Scenario: Testing the exact response of a GET endpoint Scenario: Testing the exact response of a GET endpoint
Given url 'http://localhost:8080/user/get' Given url 'http://localhost:8097/user/get'
When method GET When method GET
Then status 200 Then status 200
And match $ == {id:"1234",name:"John Smith"} And match $ == {id:"1234",name:"John Smith"}
Scenario: Testing the exact response field value of a GET endpoint Scenario: Testing the exact response field value of a GET endpoint
Given url 'http://localhost:8080/user/get' Given url 'http://localhost:8097/user/get'
When method GET When method GET
Then status 200 Then status 200
And match $.id == "1234" And match $.id == "1234"
Scenario: Testing that GET response contains specific field Scenario: Testing that GET response contains specific field
Given url 'http://localhost:8080/user/get' Given url 'http://localhost:8097/user/get'
When method GET When method GET
Then status 200 Then status 200
And match $ contains {id:"1234"} And match $ contains {id:"1234"}
Scenario: Test GET response using markers Scenario: Test GET response using markers
Given url 'http://localhost:8080/user/get' Given url 'http://localhost:8097/user/get'
When method GET When method GET
Then status 200 Then status 200
And match $ == {id:"#notnull",name:"John Smith"} And match $ == {id:"#notnull",name:"John Smith"}
Scenario: Testing a POST endpoint with request body Scenario: Testing a POST endpoint with request body
Given url 'http://localhost:8080/user/create' Given url 'http://localhost:8097/user/create'
And request { id: '1234' , name: 'John Smith'} And request { id: '1234' , name: 'John Smith'}
When method POST When method POST
Then status 200 Then status 200