diff --git a/integration-dsl/pom.xml b/integration-dsl/pom.xml index 8e1925916..f41c35d55 100644 --- a/integration-dsl/pom.xml +++ b/integration-dsl/pom.xml @@ -14,14 +14,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.6.RELEASE + 2.5.6 UTF-8 UTF-8 - 1.8 + 17 @@ -75,10 +75,10 @@ ch.qos.logback logback-classic - + - junit - junit + org.junit.jupiter + junit-jupiter test @@ -101,11 +101,6 @@ reactor-test test - - org.springframework.security - spring-security-test - test - org.springframework.integration spring-integration-test @@ -115,6 +110,11 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + org.apache.maven.plugins diff --git a/integration-dsl/src/test/java/com/example/demo/ApplicationTests.java b/integration-dsl/src/test/java/com/example/demo/ApplicationTests.java index 0dc11d6db..1a8dbf8f6 100644 --- a/integration-dsl/src/test/java/com/example/demo/ApplicationTests.java +++ b/integration-dsl/src/test/java/com/example/demo/ApplicationTests.java @@ -5,23 +5,19 @@ */ package com.example.demo; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.web.reactive.server.WebTestClient; /** * * @author hantsy */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = Application.class) +@SpringJUnitConfig(classes = Application.class) @ActiveProfiles("test") public class ApplicationTests { @@ -30,7 +26,7 @@ public class ApplicationTests { WebTestClient rest; - @Before + @BeforeEach public void setup() { this.rest = WebTestClient .bindToApplicationContext(this.context) diff --git a/integration-dsl/src/test/java/com/example/demo/IntegrationTests.java b/integration-dsl/src/test/java/com/example/demo/IntegrationTests.java index 2bd5a2d28..0b1f0138a 100644 --- a/integration-dsl/src/test/java/com/example/demo/IntegrationTests.java +++ b/integration-dsl/src/test/java/com/example/demo/IntegrationTests.java @@ -1,48 +1,64 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.example.demo; -import java.time.Duration; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.web.reactive.server.WebTestClient; +import reactor.netty.DisposableServer; +import reactor.netty.http.server.HttpServer; + +import java.time.Duration; /** - * * @author hantsy */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = Application.class) +@SpringJUnitConfig(classes = Application.class) public class IntegrationTests { - @Value("#{@nettyContext.address().getPort()}") + @Value("${server.port:8080}") int port; - WebTestClient rest; + private WebTestClient rest; + + @Autowired + HttpServer httpServer; + + private DisposableServer disposableServer; - @Before + @BeforeEach public void setup() { + this.disposableServer = this.httpServer.bindNow(Duration.ofMillis(1000)); this.rest = WebTestClient - .bindToServer() - .responseTimeout(Duration.ofDays(1)) - .baseUrl("http://localhost:" + this.port) - .build(); + .bindToServer() + .responseTimeout(Duration.ofMillis(5000)) + .baseUrl("http://localhost:" + this.port) + .build(); + } + + @AfterEach + public void tearDown() { + this.disposableServer.dispose(); } @Test public void getAllPostsWillBeOk() throws Exception { this.rest - .get() - .uri("/posts") - .exchange() - .expectStatus().isOk(); + .get() + .uri("/posts") + .exchange() + .expectStatus().isOk(); + } + + @Test + public void getAllPostsWillBeOk_viaIntegration() throws Exception { + this.rest + .get() + .uri("/all") + .exchange() + .expectStatus().isOk(); } } diff --git a/integration-dsl/src/test/java/com/example/demo/PostControllerTest.java b/integration-dsl/src/test/java/com/example/demo/PostControllerTest.java index 5f75b7a94..7bfa53247 100644 --- a/integration-dsl/src/test/java/com/example/demo/PostControllerTest.java +++ b/integration-dsl/src/test/java/com/example/demo/PostControllerTest.java @@ -5,22 +5,20 @@ */ package com.example.demo; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import static org.springframework.http.MediaType.APPLICATION_JSON; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.web.reactive.server.WebTestClient; +import static org.springframework.http.MediaType.APPLICATION_JSON; + /** * * @author hantsy */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = Application.class) +@SpringJUnitConfig(classes = Application.class) @ActiveProfiles("test") public class PostControllerTest { @@ -29,7 +27,7 @@ public class PostControllerTest { WebTestClient rest; - @Before + @BeforeEach public void setup() { this.rest = WebTestClient .bindToController(this.ctrl) diff --git a/integration-dsl/src/test/java/com/example/demo/PostRepositoryTest.java b/integration-dsl/src/test/java/com/example/demo/PostRepositoryTest.java index 66f475feb..4e4553917 100644 --- a/integration-dsl/src/test/java/com/example/demo/PostRepositoryTest.java +++ b/integration-dsl/src/test/java/com/example/demo/PostRepositoryTest.java @@ -5,11 +5,13 @@ */ package com.example.demo; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import reactor.test.StepVerifier; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * * @author hantsy @@ -18,7 +20,7 @@ public class PostRepositoryTest { PostRepository posts; - @Before + @BeforeEach public void setup() { posts = new PostRepository(); } diff --git a/integration/pom.xml b/integration/pom.xml index 913682430..93e09cbe5 100644 --- a/integration/pom.xml +++ b/integration/pom.xml @@ -14,14 +14,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.6.RELEASE + 2.5.6 UTF-8 UTF-8 - 1.8 + 17 @@ -75,10 +75,10 @@ ch.qos.logback logback-classic - + - junit - junit + org.junit.jupiter + junit-jupiter test @@ -101,11 +101,6 @@ reactor-test test - - org.springframework.security - spring-security-test - test - org.springframework.integration spring-integration-test @@ -115,6 +110,11 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + org.apache.maven.plugins diff --git a/integration/src/test/java/com/example/demo/ApplicationTests.java b/integration/src/test/java/com/example/demo/ApplicationTests.java index 0dc11d6db..2ced9f3b8 100644 --- a/integration/src/test/java/com/example/demo/ApplicationTests.java +++ b/integration/src/test/java/com/example/demo/ApplicationTests.java @@ -5,14 +5,13 @@ */ package com.example.demo; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; @@ -20,8 +19,7 @@ * * @author hantsy */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = Application.class) +@SpringJUnitConfig(classes = Application.class) @ActiveProfiles("test") public class ApplicationTests { @@ -30,7 +28,7 @@ public class ApplicationTests { WebTestClient rest; - @Before + @BeforeEach public void setup() { this.rest = WebTestClient .bindToApplicationContext(this.context) diff --git a/integration/src/test/java/com/example/demo/IntegrationTests.java b/integration/src/test/java/com/example/demo/IntegrationTests.java index 2bd5a2d28..0b1f0138a 100644 --- a/integration/src/test/java/com/example/demo/IntegrationTests.java +++ b/integration/src/test/java/com/example/demo/IntegrationTests.java @@ -1,48 +1,64 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.example.demo; -import java.time.Duration; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.web.reactive.server.WebTestClient; +import reactor.netty.DisposableServer; +import reactor.netty.http.server.HttpServer; + +import java.time.Duration; /** - * * @author hantsy */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = Application.class) +@SpringJUnitConfig(classes = Application.class) public class IntegrationTests { - @Value("#{@nettyContext.address().getPort()}") + @Value("${server.port:8080}") int port; - WebTestClient rest; + private WebTestClient rest; + + @Autowired + HttpServer httpServer; + + private DisposableServer disposableServer; - @Before + @BeforeEach public void setup() { + this.disposableServer = this.httpServer.bindNow(Duration.ofMillis(1000)); this.rest = WebTestClient - .bindToServer() - .responseTimeout(Duration.ofDays(1)) - .baseUrl("http://localhost:" + this.port) - .build(); + .bindToServer() + .responseTimeout(Duration.ofMillis(5000)) + .baseUrl("http://localhost:" + this.port) + .build(); + } + + @AfterEach + public void tearDown() { + this.disposableServer.dispose(); } @Test public void getAllPostsWillBeOk() throws Exception { this.rest - .get() - .uri("/posts") - .exchange() - .expectStatus().isOk(); + .get() + .uri("/posts") + .exchange() + .expectStatus().isOk(); + } + + @Test + public void getAllPostsWillBeOk_viaIntegration() throws Exception { + this.rest + .get() + .uri("/all") + .exchange() + .expectStatus().isOk(); } } diff --git a/integration/src/test/java/com/example/demo/PostControllerTest.java b/integration/src/test/java/com/example/demo/PostControllerTest.java index 5f75b7a94..2da49d9f3 100644 --- a/integration/src/test/java/com/example/demo/PostControllerTest.java +++ b/integration/src/test/java/com/example/demo/PostControllerTest.java @@ -5,13 +5,13 @@ */ package com.example.demo; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import static org.springframework.http.MediaType.APPLICATION_JSON; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; @@ -19,8 +19,7 @@ * * @author hantsy */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = Application.class) +@SpringJUnitConfig(classes = Application.class) @ActiveProfiles("test") public class PostControllerTest { @@ -29,7 +28,7 @@ public class PostControllerTest { WebTestClient rest; - @Before + @BeforeEach public void setup() { this.rest = WebTestClient .bindToController(this.ctrl) diff --git a/integration/src/test/java/com/example/demo/PostRepositoryTest.java b/integration/src/test/java/com/example/demo/PostRepositoryTest.java index 66f475feb..4e4553917 100644 --- a/integration/src/test/java/com/example/demo/PostRepositoryTest.java +++ b/integration/src/test/java/com/example/demo/PostRepositoryTest.java @@ -5,11 +5,13 @@ */ package com.example.demo; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import reactor.test.StepVerifier; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * * @author hantsy @@ -18,7 +20,7 @@ public class PostRepositoryTest { PostRepository posts; - @Before + @BeforeEach public void setup() { posts = new PostRepository(); }