Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2161E200B9A for ; Fri, 23 Sep 2016 03:31:58 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1FD8A160AE0; Fri, 23 Sep 2016 01:31:58 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D6B10160AAD for ; Fri, 23 Sep 2016 03:31:56 +0200 (CEST) Received: (qmail 16385 invoked by uid 500); 23 Sep 2016 01:31:56 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 16375 invoked by uid 99); 23 Sep 2016 01:31:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Sep 2016 01:31:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DB6A4E03CE; Fri, 23 Sep 2016 01:31:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: reta@apache.org To: commits@cxf.apache.org Message-Id: <26265c7c318b4cceb133819a416de442@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: CXF-5855: restructured SSE test cases to stabilize them Date: Fri, 23 Sep 2016 01:31:55 +0000 (UTC) archived-at: Fri, 23 Sep 2016 01:31:58 -0000 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 Authored: Thu Sep 22 21:31:41 2016 -0400 Committer: reta 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> 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 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> 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 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; + } + +}