This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 332a02450fe1620daeaa2b65c0716e337d49095a
Author: Alexey Markevich <[email protected]>
AuthorDate: Thu Mar 18 17:55:52 2021 +0300

    cxf-systests-spring-boot: switch to JUnit 5
---
 systests/spring-boot/pom.xml                       | 44 +----------------
 .../spring/boot/SpringJaxrsApplicationTest.java    | 44 +++++++----------
 .../boot/SpringJaxrsClassesScanningTest.java       | 10 ++--
 .../boot/SpringJaxrsComponentScanningTest.java     | 10 ++--
 .../systest/jaxrs/spring/boot/SpringJaxrsTest.java | 44 +++++++----------
 .../jaxrs/spring/boot/SpringSseEmitterTest.java    | 57 ++++++++++------------
 .../systest/jaxws/spring/boot/SpringJaxwsTest.java | 53 ++++++++++----------
 7 files changed, 96 insertions(+), 166 deletions(-)

diff --git a/systests/spring-boot/pom.xml b/systests/spring-boot/pom.xml
index 11b8d95..1df0b4e 100644
--- a/systests/spring-boot/pom.xml
+++ b/systests/spring-boot/pom.xml
@@ -36,21 +36,6 @@
     </properties>
 
     <build>
-        <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
-        <testResources>
-            <testResource>
-                <directory>src/test/java</directory>
-                <excludes>
-                    <exclude>**/*.java</exclude>
-                </excludes>
-            </testResource>
-            <testResource>
-                <directory>src/test/resources</directory>
-                <includes>
-                    <include>**/*</include>
-                </includes>
-            </testResource>
-        </testResources>
         <plugins>
             <plugin>
                 <artifactId>maven-jar-plugin</artifactId>
@@ -74,11 +59,6 @@
     </build>
     <dependencies>
         <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>jcl-over-slf4j</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
         </dependency>
@@ -88,18 +68,6 @@
         </dependency>
         <dependency>
             <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-rt-frontend-jaxws</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-rt-rs-client</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-features-metrics</artifactId>
         </dependency>
         <dependency>
@@ -123,11 +91,7 @@
             <artifactId>cxf-testutils</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
@@ -145,11 +109,5 @@
             <artifactId>spring-boot-starter-actuator</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.junit.vintage</groupId>
-            <artifactId>junit-vintage-engine</artifactId>
-            <version>${cxf.junit5.version}</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 </project>
diff --git 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsApplicationTest.java
 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsApplicationTest.java
index fa4d5ec..f5efe25 100644
--- 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsApplicationTest.java
+++ 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsApplicationTest.java
@@ -32,7 +32,7 @@ import javax.ws.rs.core.Response;
 
 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 
-import org.apache.cxf.bus.spring.SpringBus;
+import org.apache.cxf.Bus;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.metrics.MetricsFeature;
@@ -44,34 +44,29 @@ import 
org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.system.OutputCaptureRule;
 import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
 import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.util.SocketUtils;
 
 import io.micrometer.core.instrument.MeterRegistry;
 import io.micrometer.core.instrument.Tag;
 import io.micrometer.core.instrument.search.RequiredSearch;
 
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 
 import static java.util.stream.Collectors.toMap;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.entry;
 
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = 
SpringJaxrsApplicationTest.TestConfig.class)
 @ActiveProfiles("jaxrs")
 public class SpringJaxrsApplicationTest {
-    @Rule
-    public OutputCaptureRule output = new OutputCaptureRule();
 
     @Autowired
     private MeterRegistry registry;
@@ -82,18 +77,9 @@ public class SpringJaxrsApplicationTest {
     @LocalServerPort
     private int port;
 
-    @Configuration
     @EnableAutoConfiguration
     static class TestConfig {
         @Bean
-        public SpringBus cxf() {
-            final SpringBus bus = new SpringBus();
-            // By default, the exception are propagated and out fault 
interceptors are not called 
-            bus.setProperty("org.apache.cxf.propagate.exception", 
Boolean.FALSE);
-            return bus;
-        }
-        
-        @Bean
         public Application application() {
             return new LibraryApplication();
         }
@@ -103,10 +89,16 @@ public class SpringJaxrsApplicationTest {
             return new MetricsFeature(metricsProvider);
         }
     }
-    
-    @Before
-    public void setUp() {
-        this.registry.getMeters().forEach(meter -> registry.remove(meter));
+
+    @Autowired
+    public void setBus(Bus bus) {
+        // By default, the exception are propagated and out fault interceptors 
are not called 
+        bus.setProperty("org.apache.cxf.propagate.exception", Boolean.FALSE);
+    }
+
+    @AfterEach
+    public void clear() {
+        registry.clear();
     }
 
     @Test
@@ -272,7 +264,7 @@ public class SpringJaxrsApplicationTest {
 
         // no server meters
         assertThat(registry.getMeters())
-            .noneMatch(m -> m.getId().getName().equals("cxf.server.requests"));
+            .noneMatch(m -> "cxf.server.requests".equals(m.getId().getName()));
         
         RequiredSearch clientRequestMetrics = 
registry.get("cxf.client.requests");
 
@@ -411,7 +403,7 @@ public class SpringJaxrsApplicationTest {
 
         // no server meters
         assertThat(registry.getMeters())
-            .noneMatch(m -> m.getId().getName().equals("cxf.server.requests"));
+            .noneMatch(m -> "cxf.server.requests".equals(m.getId().getName()));
         
         RequiredSearch clientRequestMetrics = 
registry.get("cxf.client.requests");
 
diff --git 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsClassesScanningTest.java
 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsClassesScanningTest.java
index 624c02c..6063fe5 100644
--- 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsClassesScanningTest.java
+++ 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsClassesScanningTest.java
@@ -24,16 +24,15 @@ import 
org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.context.annotation.Configuration;
 import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
         classes = SpringJaxrsClassesScanningTest.TestConfig.class)
 @ActiveProfiles("jaxrs-classes-scan")
@@ -41,7 +40,6 @@ public class SpringJaxrsClassesScanningTest {
     @Autowired
     private AbstractJaxrsClassesScanServer scanner;
 
-    @Configuration
     @EnableAutoConfiguration
     static class TestConfig {
     }
diff --git 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsComponentScanningTest.java
 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsComponentScanningTest.java
index 3fea6dc..afc7927 100644
--- 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsComponentScanningTest.java
+++ 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsComponentScanningTest.java
@@ -28,16 +28,15 @@ import 
org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
 import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
 import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
         classes = SpringJaxrsComponentScanningTest.TestConfig.class)
 @ActiveProfiles("jaxrs-component-scan")
@@ -45,7 +44,6 @@ public class SpringJaxrsComponentScanningTest {
     @Autowired
     private AbstractSpringComponentScanServer scanner;
 
-    @Configuration
     @EnableAutoConfiguration
     @ComponentScan(basePackageClasses = Library.class)
     static class TestConfig {
diff --git 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsTest.java
 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsTest.java
index df9eb92..fd72e47 100644
--- 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsTest.java
+++ 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsTest.java
@@ -31,7 +31,7 @@ import javax.ws.rs.core.Response;
 
 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 
-import org.apache.cxf.bus.spring.SpringBus;
+import org.apache.cxf.Bus;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.metrics.MetricsFeature;
@@ -43,35 +43,30 @@ import 
org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.system.OutputCaptureRule;
 import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
 import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.util.SocketUtils;
 
 import io.micrometer.core.instrument.MeterRegistry;
 import io.micrometer.core.instrument.Tag;
 import io.micrometer.core.instrument.search.RequiredSearch;
 
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 
 import static java.util.stream.Collectors.toMap;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.entry;
 
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = 
SpringJaxrsTest.TestConfig.class)
 @ActiveProfiles("jaxrs")
 public class SpringJaxrsTest {
-    @Rule
-    public OutputCaptureRule output = new OutputCaptureRule();
 
     @Autowired
     private MeterRegistry registry;
@@ -82,19 +77,10 @@ public class SpringJaxrsTest {
     @LocalServerPort
     private int port;
 
-    @Configuration
     @EnableAutoConfiguration
     @ComponentScan(basePackageClasses = Library.class)
     static class TestConfig {
         @Bean
-        public SpringBus cxf() {
-            final SpringBus bus = new SpringBus();
-            // By default, the exception are propagated and out fault 
interceptors are not called 
-            bus.setProperty("org.apache.cxf.propagate.exception", 
Boolean.FALSE);
-            return bus;
-        }
-        
-        @Bean
         public Feature metricsFeature(MetricsProvider metricsProvider) {
             return new MetricsFeature(metricsProvider);
         }
@@ -104,10 +90,16 @@ public class SpringJaxrsTest {
             return new JacksonJsonProvider();
         }
     }
-    
-    @Before
-    public void setUp() {
-        this.registry.getMeters().forEach(meter -> registry.remove(meter));
+
+    @Autowired
+    public void setBus(Bus bus) {
+        // By default, the exception are propagated and out fault interceptors 
are not called 
+        bus.setProperty("org.apache.cxf.propagate.exception", Boolean.FALSE);
+    }
+
+    @AfterEach
+    public void clear() {
+        registry.clear();
     }
 
     @Test
@@ -236,7 +228,7 @@ public class SpringJaxrsTest {
 
         // no server meters
         assertThat(registry.getMeters())
-            .noneMatch(m -> m.getId().getName().equals("cxf.server.requests"));
+            .noneMatch(m -> "cxf.server.requests".equals(m.getId().getName()));
         
         RequiredSearch clientRequestMetrics = 
registry.get("cxf.client.requests");
 
@@ -375,7 +367,7 @@ public class SpringJaxrsTest {
 
         // no server meters
         assertThat(registry.getMeters())
-            .noneMatch(m -> m.getId().getName().equals("cxf.server.requests"));
+            .noneMatch(m -> "cxf.server.requests".equals(m.getId().getName()));
         
         RequiredSearch clientRequestMetrics = 
registry.get("cxf.client.requests");
 
diff --git 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringSseEmitterTest.java
 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringSseEmitterTest.java
index c993122..ef1d354 100644
--- 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringSseEmitterTest.java
+++ 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringSseEmitterTest.java
@@ -21,13 +21,11 @@ package org.apache.cxf.systest.jaxrs.spring.boot;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.function.Consumer;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
 
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.sse.InboundSseEvent;
 import javax.ws.rs.sse.SseEventSource;
 
 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
@@ -38,21 +36,23 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
 import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.http.MediaType;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 import 
org.springframework.web.servlet.mvc.method.annotation.SseEmitter.SseEventBuilder;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 
 import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = 
SpringSseEmitterTest.LibraryController.class)
 public class SpringSseEmitterTest {
+    private static final int CNT = 5;
     @LocalServerPort
     private int port;
     
@@ -62,24 +62,21 @@ public class SpringSseEmitterTest {
         @GetMapping("/sse")
         public SseEmitter streamSseMvc() {
             final SseEmitter emitter = new SseEmitter();
-            final ExecutorService sseMvcExecutor = 
Executors.newSingleThreadExecutor();
-            
-            sseMvcExecutor.execute(() -> {
+            CompletableFuture.runAsync(() -> {
                 try {
-                    for (int eventId = 1; eventId <= 5; ++eventId) {
+                    for (int eventId = 1; eventId <= CNT; ++eventId) {
                         SseEventBuilder event = SseEmitter.event()
                             .id(Integer.toString(eventId))
                             .data(new Book("New Book #" + eventId, "Author #" 
+ eventId), MediaType.APPLICATION_JSON)
                             .name("book");
                         emitter.send(event);
-                        Thread.sleep(100);
+                        Thread.sleep(100L);
                     }
                     emitter.complete();
                 } catch (Exception ex) {
                     emitter.completeWithError(ex);
                 }
             });
-            
             return emitter;
         }
     }
@@ -87,15 +84,26 @@ public class SpringSseEmitterTest {
     @Test
     public void testSseEvents() throws InterruptedException {
         final WebTarget target = createWebTarget();
-        final Collection<Book> books = new ArrayList<>();
+        final Collection<Book> books = new ArrayList<>(CNT);
+        final AtomicReference<Throwable> throwable = new AtomicReference<>();
 
         try (SseEventSource eventSource = 
SseEventSource.target(target).build()) {
-            eventSource.register(collect(books), System.out::println);
+            eventSource.register(event -> {
+                books.add(event.readData(Book.class, 
javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE));
+                if (books.size() == CNT) {
+                    synchronized (books) {
+                        books.notify();
+                    }
+                }
+            }, e -> throwable.set(e));
             eventSource.open();
             // Give the SSE stream some time to collect all events
-            awaitEvents(5000, books, 5);
+            synchronized (books) {
+                books.wait(5000L);
+            }
         }
 
+        assertThat(throwable.get(), nullValue());
         assertThat(books,
             hasItems(
                 new Book("New Book #1", "Author #1"),
@@ -115,19 +123,4 @@ public class SpringSseEmitterTest {
             .target("http://localhost:"; + port + "/sse");
     }
 
-    private static Consumer<InboundSseEvent> collect(final Collection< Book > 
books) {
-        return event -> books.add(event.readData(Book.class, 
javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE));
-    }
-    
-    private void awaitEvents(int timeout, final Collection<?> events, int 
size) throws InterruptedException {
-        final int sleep = timeout / 10;
-        
-        for (int i = 0; i < timeout; i += sleep) {
-            if (events.size() == size) {
-                break;
-            } else {
-                Thread.sleep(sleep);
-            }
-        }
-    }
 }
diff --git 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsTest.java
 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsTest.java
index 3f6f480..25baf74 100644
--- 
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsTest.java
+++ 
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsTest.java
@@ -47,23 +47,22 @@ import 
org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.system.OutputCaptureRule;
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.boot.test.system.OutputCaptureExtension;
 import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
 import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.util.SocketUtils;
 
 import io.micrometer.core.instrument.MeterRegistry;
 import io.micrometer.core.instrument.Tag;
 import io.micrometer.core.instrument.search.RequiredSearch;
 
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
 
 import static java.util.stream.Collectors.toMap;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -71,11 +70,14 @@ import static 
org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.catchThrowable;
 import static org.assertj.core.api.Assertions.entry;
 
-@RunWith(SpringRunner.class)
-@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
-        classes = SpringJaxwsTest.TestConfig.class)
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(
+        webEnvironment = WebEnvironment.RANDOM_PORT,
+        classes = SpringJaxwsTest.TestConfig.class,
+        properties = {
+            "cxf.metrics.server.max-uri-tags=2"
+        })
 @ActiveProfiles("jaxws")
-@TestPropertySource(properties = {"cxf.metrics.server.max-uri-tags=2"})
 public class SpringJaxwsTest {
 
     private static final String DUMMY_REQUEST_BODY = "<q0:sayHello 
xmlns:q0=\"http://service.ws.sample/\";>"
@@ -85,9 +87,6 @@ public class SpringJaxwsTest {
     private static final String HELLO_SERVICE_NAME_V2 = "HelloV2";
     private static final String HELLO_SERVICE_NAME_V3 = "HelloV3";
 
-    @Rule
-    public OutputCaptureRule output = new OutputCaptureRule();
-
     @Autowired
     private MeterRegistry registry;
     
@@ -97,7 +96,6 @@ public class SpringJaxwsTest {
     @LocalServerPort
     private int port;
 
-    @Configuration
     @EnableAutoConfiguration
     static class TestConfig {
         @Autowired
@@ -134,9 +132,9 @@ public class SpringJaxwsTest {
         }
     }
 
-    @Before
-    public void setUp() {
-        this.registry.getMeters().forEach(meter -> registry.remove(meter));
+    @AfterEach
+    public void clear() {
+        registry.clear();
     }
 
     @Test
@@ -229,7 +227,8 @@ public class SpringJaxwsTest {
     }
 
     @Test
-    public void testAfterMaxUrisReachedFurtherUrisAreDenied() throws 
MalformedURLException {
+    @ExtendWith(OutputCaptureExtension.class)
+    public void testAfterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput 
output) throws MalformedURLException {
         // given in setUp
 
         // when
@@ -239,11 +238,12 @@ public class SpringJaxwsTest {
 
         // then
         assertThat(registry.get("cxf.server.requests").meters()).hasSize(2);
-        assertThat(this.output).contains("Reached the maximum number of URI 
tags " + "for 'cxf.server.requests'");
+        assertThat(output).contains("Reached the maximum number of URI tags 
for 'cxf.server.requests'");
     }
 
     @Test
-    public void testDoesNotDenyNorLogIfMaxUrisIsNotReached() throws 
MalformedURLException {
+    @ExtendWith(OutputCaptureExtension.class)
+    public void testDoesNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput 
output) throws MalformedURLException {
         // given in setUp
 
         // when
@@ -251,10 +251,9 @@ public class SpringJaxwsTest {
 
         // then
         assertThat(registry.get("cxf.server.requests").meters()).hasSize(1);
-        assertThat(this.output).doesNotContain("Reached the maximum number of 
URI tags " + "for 'cxf.server.requests'");
-
+        assertThat(output).doesNotContain("Reached the maximum number of URI 
tags for 'cxf.server.requests'");
     }
-    
+
     @Test
     public void testJaxwsProxySuccessMetric() throws MalformedURLException {
         final HelloService api = createApi(port, HELLO_SERVICE_NAME_V1); 
@@ -342,7 +341,7 @@ public class SpringJaxwsTest {
 
         // no server meters
         assertThat(registry.getMeters())
-            .noneMatch(m -> m.getId().getName().equals("cxf.server.requests"));
+            .noneMatch(m -> "cxf.server.requests".equals(m.getId().getName()));
         
         RequiredSearch clientRequestMetrics = 
registry.get("cxf.client.requests");
 
@@ -375,7 +374,7 @@ public class SpringJaxwsTest {
         Service service = Service.create(new URL(address + "?wsdl"),
                 new QName("http://service.ws.sample/";, "HelloService"), new 
MetricsFeature(metricsProvider));
         Dispatch<Source> dispatch = service.createDispatch(new 
QName("http://service.ws.sample/";, "HelloPort"),
-                Source.class, Mode.PAYLOAD);
+            Source.class, Mode.PAYLOAD);
 
         Source result = dispatch.invoke(source);
         return StaxUtils.toString(result);
-

Reply via email to