cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject cxf git commit: Wait for logging message to be logged in RESTLoggingTest
Date Wed, 26 Apr 2017 13:14:18 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5f6cb0745 -> f4d0b2152


Wait for logging message to be logged in RESTLoggingTest


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f4d0b215
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f4d0b215
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f4d0b215

Branch: refs/heads/master
Commit: f4d0b2152036c6e57f82d762464f6c96907e0a37
Parents: 5f6cb07
Author: Christian Schneider <chris@die-schneider.net>
Authored: Wed Apr 26 15:13:40 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Wed Apr 26 15:14:12 2017 +0200

----------------------------------------------------------------------
 parent/pom.xml                                  |   6 +
 rt/rs/client/pom.xml                            |   7 +-
 .../jaxrs/client/logging/RESTLoggingTest.java   | 110 +++++++++----------
 3 files changed, 61 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f4d0b215/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 2560100..32ad67d 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -748,6 +748,12 @@
                 <scope>test</scope>
             </dependency>
             <dependency>
+                <groupId>org.awaitility</groupId>
+                <artifactId>awaitility</artifactId>
+                <version>3.0.0-rc3</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
                 <groupId>nekohtml</groupId>
                 <artifactId>nekohtml</artifactId>
                 <version>1.9.6.2</version>

http://git-wip-us.apache.org/repos/asf/cxf/blob/f4d0b215/rt/rs/client/pom.xml
----------------------------------------------------------------------
diff --git a/rt/rs/client/pom.xml b/rt/rs/client/pom.xml
index 9123d65..d05d13e 100644
--- a/rt/rs/client/pom.xml
+++ b/rt/rs/client/pom.xml
@@ -95,7 +95,7 @@
           <version>1.0-alpha-1</version>
           <scope>provided</scope>
           <optional>true</optional>
-    </dependency>
+        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
@@ -147,6 +147,11 @@
           <version>2.1</version>
           <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <profiles>
         <profile>

http://git-wip-us.apache.org/repos/asf/cxf/blob/f4d0b215/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java
b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java
index a742caf..1ec1f9e 100644
--- a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java
+++ b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.client.logging;
 
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -33,10 +34,12 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.transport.local.LocalTransportFactory;
-
 import org.junit.Assert;
 import org.junit.Test;
 
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.core.Is.is;
+
 public class RESTLoggingTest {
 
     private static final String SERVICE_URI = "local://testrest";
@@ -45,104 +48,89 @@ public class RESTLoggingTest {
     @Test
     public void testSlf4j() throws IOException {
         LoggingFeature loggingFeature = new LoggingFeature();
-        Server server = createService(loggingFeature);
+        Server server = createService(SERVICE_URI, new TestServiceRest(), loggingFeature);
         server.start();
-        WebClient client = createClient(loggingFeature);
+        WebClient client = createClient(SERVICE_URI, loggingFeature);
         String result = client.get(String.class);
         server.destroy();
         Assert.assertEquals("test1", result);
     }
 
     @Test
-    public void testBinary() throws IOException {
+    public void testBinary() throws IOException, InterruptedException {
         LoggingFeature loggingFeature = new LoggingFeature();
         TestEventSender sender = new TestEventSender();
         loggingFeature.setSender(sender);
-        Server server = createServiceBinary(loggingFeature);
+        Server server = createService(SERVICE_URI_BINARY, new TestServiceRestBinary(), loggingFeature);
         server.start();
-        WebClient client = createClientBinary(loggingFeature);
+        WebClient client = createClient(SERVICE_URI_BINARY, loggingFeature);
         client.get(InputStream.class).close();
         loggingFeature.setLogBinary(true);
         client.get(InputStream.class).close();
         client.close();
+        List<LogEvent> events = sender.getEvents();
+        await().until(() -> events.size(), is(8));
         server.stop();
         server.destroy();
+        
+        // First call with binary logging false
+        assertContentLogged(events.get(0));
+        assertContentLogged(events.get(1));
+        assertContentNotLogged(events.get(2));
+        assertContentNotLogged(events.get(3));
+        
+        // Second call with binary logging true
+        assertContentLogged(events.get(4));
+        assertContentLogged(events.get(5));
+        assertContentLogged(events.get(6));
+        assertContentLogged(events.get(7));
+    }
 
+    @Test
+    public void testEvents() throws MalformedURLException {
+        LoggingFeature loggingFeature = new LoggingFeature();
+        loggingFeature.setLogBinary(true);
+        TestEventSender sender = new TestEventSender();
+        loggingFeature.setSender(sender);
+        Server server = createService(SERVICE_URI, new TestServiceRest(), loggingFeature);
+        server.start();
+        WebClient client = createClient(SERVICE_URI, loggingFeature);
+        String result = client.get(String.class);
+        Assert.assertEquals("test1", result);
+        server.destroy();
         List<LogEvent> events = sender.getEvents();
-        assertLogged(events.get(0));
-        assertLogged(events.get(1));
-        assertNotLogged(events.get(2));
-        assertNotLogged(events.get(3));
-
-        assertLogged(events.get(4));
-        assertLogged(events.get(5));
-        assertLogged(events.get(6));
-
-        Assert.assertEquals(8, events.size());
-        assertLogged(events.get(7));
+        Assert.assertEquals(4, events.size());
+        checkRequestOut(events.get(0));
+        checkRequestIn(events.get(1));
+        checkResponseOut(events.get(2));
+        checkResponseIn(events.get(3));
     }
-
-    private void assertLogged(LogEvent event) {
+    
+    private void assertContentLogged(LogEvent event) {
         Assert.assertNotEquals(AbstractLoggingInterceptor.CONTENT_SUPPRESSED, event.getPayload());
     }
 
-    private void assertNotLogged(LogEvent event) {
+    private void assertContentNotLogged(LogEvent event) {
         Assert.assertEquals(AbstractLoggingInterceptor.CONTENT_SUPPRESSED, event.getPayload());
     }
 
-    private WebClient createClient(LoggingFeature loggingFeature) {
-        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
-        bean.setAddress(SERVICE_URI);
-        bean.setFeatures(Collections.singletonList(loggingFeature));
-        bean.setTransportId(LocalTransportFactory.TRANSPORT_ID);
-        return bean.createWebClient().path("test1");
-    }
-
-    private Server createService(LoggingFeature loggingFeature) {
-        JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
-        factory.setAddress(SERVICE_URI);
-        factory.setFeatures(Collections.singletonList(loggingFeature));
-        factory.setServiceBean(new TestServiceRest());
-        factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
-        return factory.create();
-    }
-
-    private WebClient createClientBinary(LoggingFeature loggingFeature) {
+    private WebClient createClient(String serviceURI, LoggingFeature loggingFeature) {
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
-        bean.setAddress(SERVICE_URI_BINARY);
+        bean.setAddress(serviceURI);
         bean.setFeatures(Collections.singletonList(loggingFeature));
         bean.setTransportId(LocalTransportFactory.TRANSPORT_ID);
         return bean.createWebClient().path("test1");
     }
 
-    private Server createServiceBinary(LoggingFeature loggingFeature) {
+    private Server createService(String serviceURI, Object serviceImpl, LoggingFeature loggingFeature)
{
         JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
-        factory.setAddress(SERVICE_URI_BINARY);
+        factory.setAddress(serviceURI);
         factory.setFeatures(Collections.singletonList(loggingFeature));
-        factory.setServiceBean(new TestServiceRestBinary());
+        factory.setServiceBean(serviceImpl);
         factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
         return factory.create();
     }
 
-    @Test
-    public void testEvents() throws MalformedURLException {
-        LoggingFeature loggingFeature = new LoggingFeature();
-        loggingFeature.setLogBinary(true);
-        TestEventSender sender = new TestEventSender();
-        loggingFeature.setSender(sender);
-        Server server = createService(loggingFeature);
-        server.start();
-        WebClient client = createClient(loggingFeature);
-        String result = client.get(String.class);
-        Assert.assertEquals("test1", result);
-        server.destroy();
-        List<LogEvent> events = sender.getEvents();
-        Assert.assertEquals(4, events.size());
-        checkRequestOut(events.get(0));
-        checkRequestIn(events.get(1));
-        checkResponseOut(events.get(2));
-        checkResponseIn(events.get(3));
-    }
 
     private void checkRequestOut(LogEvent requestOut) {
         Assert.assertEquals(SERVICE_URI + "/test1", requestOut.getAddress());


Mime
View raw message