You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2016/09/23 01:31:55 UTC

cxf git commit: CXF-5855: restructured SSE test cases to stabilize them

Repository: cxf
Updated Branches:
  refs/heads/master a4e4b8f9b -> 7a5e2690c


CXF-5855: restructured SSE test cases to stabilize them


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

Branch: refs/heads/master
Commit: 7a5e2690c36914ba481570c811f23d6e6b80bc07
Parents: a4e4b8f
Author: reta <dr...@gmail.com>
Authored: Thu Sep 22 21:31:41 2016 -0400
Committer: reta <dr...@gmail.com>
Committed: Thu Sep 22 21:31:41 2016 -0400

----------------------------------------------------------------------
 .../jaxrs/sse/AbstractBroadcasterSseTest.java   | 64 +++++++++++++++++++
 .../systest/jaxrs/sse/AbstractSseBaseTest.java  | 56 +++++++++++++++++
 .../cxf/systest/jaxrs/sse/AbstractSseTest.java  | 65 +-------------------
 .../jaxrs/sse/jetty/JettyBroadcasterTest.java   | 49 +++++++++++++++
 .../jaxrs/sse/tomcat/TomcatBroadcasterTest.java | 49 +++++++++++++++
 5 files changed, 219 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/7a5e2690/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractBroadcasterSseTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractBroadcasterSseTest.java b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractBroadcasterSseTest.java
new file mode 100644
index 0000000..4a84acc
--- /dev/null
+++ b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractBroadcasterSseTest.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs.sse;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+
+public abstract class AbstractBroadcasterSseTest extends AbstractSseBaseTest {
+    @Test
+    public void testBooksStreamIsBroadcasted() throws Exception {
+        final Collection<Future<Response>> results = new ArrayList<>();
+        
+        for (int i = 0; i < 2; ++i) {
+            results.add(
+                createWebClient("/rest/api/bookstore/broadcast/sse").async().get()
+            );
+        }
+
+        createWebClient("/rest/api/bookstore/broadcast/close")
+            .async()
+            .post(null)
+            .get(4, TimeUnit.SECONDS)
+            .close();
+
+        for (final Future<Response> result: results) {
+            final Response r = result.get(1, TimeUnit.SECONDS);
+            assertEquals(Status.OK.getStatusCode(), r.getStatus());
+    
+            final String response = r.readEntity(String.class);
+            assertThat(response, containsString("id: 1000"));
+            assertThat(response, containsString("data: " + toJson("New Book #1000", 1000)));
+            
+            assertThat(response, containsString("id: 2000"));
+            assertThat(response, containsString("data: " + toJson("New Book #2000", 2000)));
+            
+            r.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/7a5e2690/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseBaseTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseBaseTest.java b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseBaseTest.java
new file mode 100644
index 0000000..07b53b7
--- /dev/null
+++ b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseBaseTest.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs.sse;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+public abstract class AbstractSseBaseTest extends AbstractBusClientServerTestBase {
+    private final ObjectMapper mapper = new ObjectMapper();
+
+    protected String toJson(final String name, final Integer id) throws JsonProcessingException {
+        return mapper.writeValueAsString(new Book(name, id));
+    }
+    
+    protected WebClient createWebClient(final String url, final String media) {
+        final List< ? > providers = Arrays.asList(new JacksonJsonProvider());
+        
+        final WebClient wc = WebClient
+            .create("http://localhost:" + getPort() + url, providers)
+            .accept(media);
+        
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(5000L);
+        return wc;
+    }
+    
+    protected WebClient createWebClient(final String url) {
+        return createWebClient(url, MediaType.SERVER_SENT_EVENTS);
+    }
+    
+    protected abstract int getPort();
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/7a5e2690/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java
index 80d5cde..4c6bbf3 100644
--- a/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java
+++ b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java
@@ -18,12 +18,7 @@
  */
 package org.apache.cxf.systest.jaxrs.sse;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
 
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -31,19 +26,13 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 
-import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.hasItems;
 
-public abstract class AbstractSseTest extends AbstractBusClientServerTestBase {
-    private final ObjectMapper mapper = new ObjectMapper();
-    
+public abstract class AbstractSseTest extends AbstractSseBaseTest {
     @Test
     public void testBooksStreamIsReturnedFromLastEventId() throws JsonProcessingException {
         Response r = createWebClient("/rest/api/bookstore/sse/100")
@@ -77,56 +66,4 @@ public abstract class AbstractSseTest extends AbstractBusClientServerTestBase {
         
         r.close();
     }
-    
-    @Test
-    public void testBooksStreamIsBroadcasted() throws Exception {
-        final Collection<Future<Response>> results = new ArrayList<>();
-        
-        for (int i = 0; i < 2; ++i) {
-            results.add(
-                createWebClient("/rest/api/bookstore/broadcast/sse").async().get()
-            );
-        }
-
-        createWebClient("/rest/api/bookstore/broadcast/close")
-            .async()
-            .post(null)
-            .get(4, TimeUnit.SECONDS)
-            .close();
-
-        for (final Future<Response> result: results) {
-            final Response r = result.get(1, TimeUnit.SECONDS);
-            assertEquals(Status.OK.getStatusCode(), r.getStatus());
-    
-            final String response = r.readEntity(String.class);
-            assertThat(response, containsString("id: 1000"));
-            assertThat(response, containsString("data: " + toJson("New Book #1000", 1000)));
-            
-            assertThat(response, containsString("id: 2000"));
-            assertThat(response, containsString("data: " + toJson("New Book #2000", 2000)));
-            
-            r.close();
-        }
-    }
-
-    private String toJson(final String name, final Integer id) throws JsonProcessingException {
-        return mapper.writeValueAsString(new Book(name, id));
-    }
-    
-    protected WebClient createWebClient(final String url, final String media) {
-        final List< ? > providers = Arrays.asList(new JacksonJsonProvider());
-        
-        final WebClient wc = WebClient
-            .create("http://localhost:" + getPort() + url, providers)
-            .accept(media);
-        
-        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(5000L);
-        return wc;
-    }
-    
-    protected WebClient createWebClient(final String url) {
-        return createWebClient(url, MediaType.SERVER_SENT_EVENTS);
-    }
-    
-    protected abstract int getPort();
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/7a5e2690/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/jetty/JettyBroadcasterTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/jetty/JettyBroadcasterTest.java b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/jetty/JettyBroadcasterTest.java
new file mode 100644
index 0000000..6fc58e1
--- /dev/null
+++ b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/jetty/JettyBroadcasterTest.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs.sse.jetty;
+
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.systest.jaxrs.sse.AbstractBroadcasterSseTest;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+
+public class JettyBroadcasterTest extends AbstractBroadcasterSseTest {
+    @Ignore
+    public static class EmbeddedJettyServer extends AbstractJettyServer {
+        public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+        public EmbeddedJettyServer() {
+            super("/", PORT);
+        }
+    }
+    
+    @BeforeClass
+    public static void startServers() throws Exception {
+        AbstractResourceInfo.clearAllMaps();
+        //keep out of process due to stack traces testing failures
+        assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+        createStaticBus();
+    }
+    
+    @Override
+    protected int getPort() {
+        return EmbeddedJettyServer.PORT;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/7a5e2690/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/tomcat/TomcatBroadcasterTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/tomcat/TomcatBroadcasterTest.java b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/tomcat/TomcatBroadcasterTest.java
new file mode 100644
index 0000000..a22b4bf
--- /dev/null
+++ b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/tomcat/TomcatBroadcasterTest.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs.sse.tomcat;
+
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.systest.jaxrs.sse.AbstractBroadcasterSseTest;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+
+public class TomcatBroadcasterTest extends AbstractBroadcasterSseTest {  
+    @Ignore
+    public static class EmbeddedTomcatServer extends AbstractTomcatServer {
+        public static final int PORT = allocatePortAsInt(EmbeddedTomcatServer.class);
+
+        public EmbeddedTomcatServer() {
+            super("/", PORT);
+        }
+    }
+    
+    @BeforeClass
+    public static void startServers() throws Exception {
+        AbstractResourceInfo.clearAllMaps();
+        assertTrue("server did not launch correctly", launchServer(EmbeddedTomcatServer.class, true));
+        createStaticBus();
+    }
+    
+    @Override
+    protected int getPort() {
+        return EmbeddedTomcatServer.PORT;
+    }
+
+}