deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ch...@apache.org
Subject [03/10] git commit: Refactored the servlet tests into new package structure
Date Thu, 13 Jun 2013 05:02:52 GMT
Refactored the servlet tests into new package structure


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

Branch: refs/heads/master
Commit: 28e5c71e22c3d9831db1b1bd608ed9bf08f3454f
Parents: c161b11
Author: Christian Kaltepoth <christian@kaltepoth.de>
Authored: Wed May 22 17:25:43 2013 +0200
Committer: Christian Kaltepoth <christian@kaltepoth.de>
Committed: Thu Jun 13 06:53:29 2013 +0200

----------------------------------------------------------------------
 .../impl/event/RequestResponseEventsTest.java   | 110 ------------------
 .../impl/event/ServletEventObserver.java        |  73 ------------
 .../request/RequestResponseEventsObserver.java  |  76 +++++++++++++
 .../request/RequestResponseEventsTest.java      | 112 +++++++++++++++++++
 4 files changed, 188 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/28e5c71e/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/RequestResponseEventsTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/RequestResponseEventsTest.java
b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/RequestResponseEventsTest.java
deleted file mode 100644
index 2f6e347..0000000
--- a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/RequestResponseEventsTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.deltaspike.test.servlet.impl.event;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.net.URL;
-
-import javax.inject.Inject;
-
-import org.apache.deltaspike.test.category.WebProfileCategory;
-import org.apache.deltaspike.test.servlet.impl.Deployments;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.RunAsClient;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.StringAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-
-/**
- * @author Christian Kaltepoth
- */
-@RunWith(Arquillian.class)
-@Category(WebProfileCategory.class)
-public class RequestResponseEventsTest
-{
-
-    @Deployment
-    public static WebArchive getDeployment()
-    {
-        return ShrinkWrap.create(WebArchive.class, "test.war")
-                .addAsLibraries(Deployments.getDeltaSpikeCoreArchives())
-                .addAsLibraries(Deployments.getDeltaSpikeServletArchives())
-                .addAsLibraries(Deployments.getTestSupportArchives())
-                .addClass(ServletEventObserver.class)
-                .addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml")
-                .addAsWebResource(new StringAsset("foobar"), "foobar.txt");
-    }
-
-    @Inject
-    private ServletEventObserver observer;
-
-    @Test
-    @RunAsClient
-    @InSequence(2)
-    public void sendRequest(@ArquillianResource URL contextPath) throws Exception
-    {
-        String url = new URL(contextPath, "foobar.txt").toString();
-        HttpResponse response = new DefaultHttpClient().execute(new HttpGet(url));
-        assertEquals(200, response.getStatusLine().getStatusCode());
-    }
-
-    @Test
-    @InSequence(3)
-    public void shouldReceiveRequestInitializedEvent()
-    {
-        assertTrue("Didn't receive expected event",
-                observer.getEventLog().contains("Initialized HttpServletRequest: /test/foobar.txt"));
-    }
-
-    @Test
-    @InSequence(3)
-    public void shouldReceiveResponseInitializedEvent()
-    {
-        assertTrue("Didn't receive expected event",
-                observer.getEventLog().contains("Initialized HttpServletResponse"));
-    }
-
-    @Test
-    @InSequence(3)
-    public void shouldReceiveRequestDestroyedEvent()
-    {
-        assertTrue("Didn't receive expected event",
-                observer.getEventLog().contains("Destroyed HttpServletRequest: /test/foobar.txt"));
-    }
-
-    @Test
-    @InSequence(3)
-    public void shouldReceiveResponseDestroyedEvent()
-    {
-        assertTrue("Didn't receive expected event",
-                observer.getEventLog().contains("Destroyed HttpServletResponse"));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/28e5c71e/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/ServletEventObserver.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/ServletEventObserver.java
b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/ServletEventObserver.java
deleted file mode 100644
index 3f8b502..0000000
--- a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/ServletEventObserver.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.deltaspike.test.servlet.impl.event;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.deltaspike.servlet.api.Destroyed;
-import org.apache.deltaspike.servlet.api.Initialized;
-import org.apache.deltaspike.servlet.api.Web;
-
-/**
- * @author Christian Kaltepoth
- */
-@ApplicationScoped
-public class ServletEventObserver
-{
-
-    private final List<String> eventLog = new ArrayList<String>();
-
-    public void requestInitialized(@Observes @Web @Initialized HttpServletRequest request)
-    {
-        eventLog.add("Initialized HttpServletRequest: " + request.getRequestURI());
-    }
-
-    public void responseInitialized(@Observes @Web @Initialized HttpServletResponse response)
-    {
-        eventLog.add("Initialized HttpServletResponse");
-    }
-
-    public void requestDestroyed(@Observes @Web @Destroyed HttpServletRequest request)
-    {
-        eventLog.add("Destroyed HttpServletRequest: " + request.getRequestURI());
-    }
-
-    public void responseDestroyed(@Observes @Web @Destroyed HttpServletResponse response)
-    {
-        eventLog.add("Destroyed HttpServletResponse");
-    }
-
-    public int getEventCount()
-    {
-        return eventLog.size();
-    }
-
-    public List<String> getEventLog()
-    {
-        return Collections.unmodifiableList(eventLog);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/28e5c71e/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/request/RequestResponseEventsObserver.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/request/RequestResponseEventsObserver.java
b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/request/RequestResponseEventsObserver.java
new file mode 100644
index 0000000..50dd6f1
--- /dev/null
+++ b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/request/RequestResponseEventsObserver.java
@@ -0,0 +1,76 @@
+/*
+ * 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.deltaspike.test.servlet.impl.event.request;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.deltaspike.servlet.api.Destroyed;
+import org.apache.deltaspike.servlet.api.Initialized;
+import org.apache.deltaspike.servlet.api.Web;
+
+/**
+ * Application scoped observer which listens for {@link HttpServletRequest} and {@link HttpServletResponse}
events on
+ * the CDI event bus.
+ * 
+ * @author Christian Kaltepoth
+ */
+@ApplicationScoped
+public class RequestResponseEventsObserver
+{
+
+    private final List<String> eventLog = new ArrayList<String>();
+
+    public void requestInitialized(@Observes @Web @Initialized HttpServletRequest request)
+    {
+        eventLog.add("Initialized HttpServletRequest: " + request.getRequestURI());
+    }
+
+    public void responseInitialized(@Observes @Web @Initialized HttpServletResponse response)
+    {
+        eventLog.add("Initialized HttpServletResponse");
+    }
+
+    public void requestDestroyed(@Observes @Web @Destroyed HttpServletRequest request)
+    {
+        eventLog.add("Destroyed HttpServletRequest: " + request.getRequestURI());
+    }
+
+    public void responseDestroyed(@Observes @Web @Destroyed HttpServletResponse response)
+    {
+        eventLog.add("Destroyed HttpServletResponse");
+    }
+
+    public int getEventCount()
+    {
+        return eventLog.size();
+    }
+
+    public List<String> getEventLog()
+    {
+        return Collections.unmodifiableList(eventLog);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/28e5c71e/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/request/RequestResponseEventsTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/request/RequestResponseEventsTest.java
b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/request/RequestResponseEventsTest.java
new file mode 100644
index 0000000..e9a33dd
--- /dev/null
+++ b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/request/RequestResponseEventsTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.deltaspike.test.servlet.impl.event.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import javax.inject.Inject;
+
+import org.apache.deltaspike.test.category.WebProfileCategory;
+import org.apache.deltaspike.test.servlet.impl.Deployments;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.junit.InSequence;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+/**
+ * Test which validates that CDI events are fired when requests and responses are created
or destroyed
+ * 
+ * @author Christian Kaltepoth
+ */
+@RunWith(Arquillian.class)
+@Category(WebProfileCategory.class)
+public class RequestResponseEventsTest
+{
+
+    @Deployment
+    public static WebArchive getDeployment()
+    {
+        return ShrinkWrap.create(WebArchive.class, "test.war")
+                .addAsLibraries(Deployments.getDeltaSpikeCoreArchives())
+                .addAsLibraries(Deployments.getDeltaSpikeServletArchives())
+                .addAsLibraries(Deployments.getTestSupportArchives())
+                .addClass(RequestResponseEventsObserver.class)
+                .addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml")
+                .addAsWebResource(new StringAsset("foobar"), "foobar.txt");
+    }
+
+    @Inject
+    private RequestResponseEventsObserver observer;
+
+    @Test
+    @RunAsClient
+    @InSequence(2)
+    public void sendRequest(@ArquillianResource URL contextPath) throws Exception
+    {
+        String url = new URL(contextPath, "foobar.txt").toString();
+        HttpResponse response = new DefaultHttpClient().execute(new HttpGet(url));
+        assertEquals(200, response.getStatusLine().getStatusCode());
+    }
+
+    @Test
+    @InSequence(3)
+    public void shouldReceiveRequestInitializedEvent()
+    {
+        assertTrue("Didn't receive expected event",
+                observer.getEventLog().contains("Initialized HttpServletRequest: /test/foobar.txt"));
+    }
+
+    @Test
+    @InSequence(3)
+    public void shouldReceiveResponseInitializedEvent()
+    {
+        assertTrue("Didn't receive expected event",
+                observer.getEventLog().contains("Initialized HttpServletResponse"));
+    }
+
+    @Test
+    @InSequence(3)
+    public void shouldReceiveRequestDestroyedEvent()
+    {
+        assertTrue("Didn't receive expected event",
+                observer.getEventLog().contains("Destroyed HttpServletRequest: /test/foobar.txt"));
+    }
+
+    @Test
+    @InSequence(3)
+    public void shouldReceiveResponseDestroyedEvent()
+    {
+        assertTrue("Didn't receive expected event",
+                observer.getEventLog().contains("Destroyed HttpServletResponse"));
+    }
+
+}


Mime
View raw message