group testing modules (#2914)
* move security content from spring-security-rest-full * swagger update * move query language to new module * rename spring-security-rest-full to spring-rest-full * group persistence modules * group testing modules * try fix conflict * cleanup
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
38efd3454f
commit
7d41efdab1
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.junit5;
|
||||
|
||||
public class Greetings {
|
||||
|
||||
public static String sayHello() {
|
||||
return "Hello";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.baeldung.junit5.Greetings;
|
||||
|
||||
@RunWith(JUnitPlatform.class)
|
||||
public class GreetingsTest {
|
||||
|
||||
@Test
|
||||
void whenCallingSayHello_thenReturnHello() {
|
||||
assertTrue("Hello".equals(Greetings.sayHello()));
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.junit5.spring;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.baeldung.junit5.Greetings;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { SpringTestConfiguration.class })
|
||||
public class GreetingsSpringTest {
|
||||
|
||||
@Test
|
||||
void whenCallingSayHello_thenReturnHello() {
|
||||
assertTrue("Hello".equals(Greetings.sayHello()));
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.junit5.spring;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SpringTestConfiguration {
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.rest.karate;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.intuit.karate.junit4.Karate;
|
||||
import cucumber.api.CucumberOptions;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
|
||||
@RunWith(Karate.class)
|
||||
@CucumberOptions(features = "classpath:karate")
|
||||
public class KarateUnitTest {
|
||||
|
||||
private static final WireMockServer wireMockServer = new WireMockServer();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
wireMockServer.start();
|
||||
|
||||
configureFor("localhost", 8080);
|
||||
stubFor(get(urlEqualTo("/user/get"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withBody("{ \"id\": \"1234\", name: \"John Smith\" }")));
|
||||
stubFor(post(urlEqualTo("/user/create"))
|
||||
.withHeader("content-type", equalTo("application/json"))
|
||||
.withRequestBody(containing("id"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withBody("{ \"id\": \"1234\", name: \"John Smith\" }")));
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception {
|
||||
wireMockServer.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
Feature: Testing a REST API with Karate
|
||||
|
||||
Scenario: Testing valid GET endpoint
|
||||
Given url 'http://localhost:8080/user/get'
|
||||
When method GET
|
||||
Then status 200
|
||||
|
||||
Scenario: Testing an invalid GET endpoint - 404
|
||||
Given url 'http://localhost:8080/user/wrong'
|
||||
When method GET
|
||||
Then status 404
|
||||
|
||||
Scenario: Testing the exact response of a GET endpoint
|
||||
Given url 'http://localhost:8080/user/get'
|
||||
When method GET
|
||||
Then status 200
|
||||
And match $ == {id:"1234",name:"John Smith"}
|
||||
|
||||
Scenario: Testing the exact response field value of a GET endpoint
|
||||
Given url 'http://localhost:8080/user/get'
|
||||
When method GET
|
||||
Then status 200
|
||||
And match $.id == "1234"
|
||||
|
||||
Scenario: Testing that GET response contains specific field
|
||||
Given url 'http://localhost:8080/user/get'
|
||||
When method GET
|
||||
Then status 200
|
||||
And match $ contains {id:"1234"}
|
||||
|
||||
Scenario: Test GET response using markers
|
||||
Given url 'http://localhost:8080/user/get'
|
||||
When method GET
|
||||
Then status 200
|
||||
And match $ == {id:"#notnull",name:"John Smith"}
|
||||
|
||||
Scenario: Testing a POST endpoint with request body
|
||||
Given url 'http://localhost:8080/user/create'
|
||||
And request { id: '1234' , name: 'John Smith'}
|
||||
When method POST
|
||||
Then status 200
|
||||
And match $ contains {id:"#notnull"}
|
||||
Reference in New Issue
Block a user