tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmar...@apache.org
Subject svn commit: r439728 [2/2] - in /incubator/tuscany/java/sca: containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/ containers/container.spring/src/main/java/org/springframework/sca/ containers/container.spring/src/main/java...
Date Sun, 03 Sep 2006 06:02:46 GMT
Added: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
(added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
Sat Sep  2 23:02:44 2006
@@ -0,0 +1,118 @@
+/*
+ * 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.tuscany.runtime.webapp;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.osoa.sca.SCA;
+
+import junit.framework.TestCase;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyFilterTestCase extends TestCase {
+
+    public void testStartStopFilter() throws Exception {
+        SCA sca = EasyMock.createNiceMock(SCA.class);
+        sca.start();
+        sca.stop();
+        EasyMock.replay(sca);
+        TuscanyWebappRuntime runtime = createMock(TuscanyWebappRuntime.class);
+        expect(runtime.getContext()).andReturn(sca);
+        runtime.startRequest();
+        runtime.stopRequest();
+        replay(runtime);
+        ServletContext context = createNiceMock(ServletContext.class);
+        EasyMock.expect(context.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(runtime);
+        replay(context);
+        TuscanyFilter filter = new TuscanyFilter();
+        FilterConfig config = createMock(FilterConfig.class);
+        expect(config.getServletContext()).andReturn(context);
+        replay(config);
+        filter.init(config);
+        ServletRequest req = createNiceMock(ServletRequest.class);
+        ServletResponse resp = createNiceMock(ServletResponse.class);
+        FilterChain chain = createNiceMock(FilterChain.class);
+        filter.doFilter(req, resp, chain);
+        verify(runtime);
+        EasyMock.verify(sca);
+    }
+
+    public void testExceptionCleanupFilter() throws Exception {
+        SCA sca = EasyMock.createNiceMock(SCA.class);
+        sca.start();
+        sca.stop();
+        EasyMock.replay(sca);
+        TuscanyWebappRuntime runtime = createMock(TuscanyWebappRuntime.class);
+        runtime.startRequest();
+        runtime.stopRequest();
+        expect(runtime.getContext()).andReturn(sca);
+        replay(runtime);
+        ServletContext context = createNiceMock(ServletContext.class);
+        EasyMock.expect(context.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(runtime);
+        replay(context);
+        TuscanyFilter filter = new TuscanyFilter();
+        FilterConfig config = createMock(FilterConfig.class);
+        expect(config.getServletContext()).andReturn(context);
+        replay(config);
+        filter.init(config);
+        ServletRequest req = createNiceMock(ServletRequest.class);
+        ServletResponse resp = createNiceMock(ServletResponse.class);
+        FilterChain chain = createNiceMock(FilterChain.class);
+        chain.doFilter(isA(ServletRequest.class), isA(ServletResponse.class));
+        EasyMock.expectLastCall().andThrow(new TestException());
+        filter.doFilter(req, resp, chain);
+        verify(runtime);
+        EasyMock.verify(sca);
+    }
+
+    public void testRuntimeNotConfigured() throws Exception {
+        ServletContext context = createNiceMock(ServletContext.class);
+        TuscanyFilter filter = new TuscanyFilter();
+        FilterConfig config = createMock(FilterConfig.class);
+        expect(config.getServletContext()).andReturn(context);
+        replay(config);
+        try {
+            filter.init(config);
+            fail();
+        } catch (ServletException e) {
+            //expected
+        }
+    }
+
+    private class TestException extends RuntimeException {
+
+    }
+
+
+}

Propchange: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
(original)
+++ incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
Sat Sep  2 23:02:44 2006
@@ -20,14 +20,20 @@
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
 import junit.framework.TestCase;
 import org.apache.tuscany.host.servlet.ServletRequestInjector;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
 import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
 
 /**
  * Verifies {@link TuscanyServlet} properly services a request
@@ -36,23 +42,39 @@
  */
 public class TuscanyServletTestCase extends TestCase {
 
-    public void testService() throws Exception {
-        ServletRequestInjector requestInjector = EasyMock.createMock(ServletRequestInjector.class);
-        requestInjector.service(isA(ServletRequest.class), isA(ServletResponse.class));
-        EasyMock.expectLastCall();
-        EasyMock.replay(requestInjector);
-        ServletContext context = org.easymock.classextension.EasyMock.createMock(ServletContext.class);
-        expect(context.getAttribute(TuscanyServlet.TUSCANY_SERVLET_REQUEST_INJECTOR)).andReturn(requestInjector);
-        org.easymock.classextension.EasyMock.replay(context);
-        ServletConfig config = EasyMock.createMock(ServletConfig.class);
-        EasyMock.expect(config.getServletContext()).andReturn(context);
-        EasyMock.replay(config);
+    public void testRequestInjection() throws Exception {
+        ServletRequest req = createNiceMock(ServletRequest.class);
+        ServletResponse resp = createNiceMock(ServletResponse.class);
+        ServletRequestInjector injector = createMock(ServletRequestInjector.class);
+        injector.service(eq(req), eq(resp));
+        EasyMock.replay(injector);
+        TuscanyWebappRuntime runtime = createMock(TuscanyWebappRuntime.class);
+        expect(runtime.getRequestInjector()).andReturn(injector);
+        replay(runtime);
+        ServletContext context = createNiceMock(ServletContext.class);
+        EasyMock.expect(context.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(runtime);
+        EasyMock.replay(context);
         TuscanyServlet servlet = new TuscanyServlet();
+        ServletConfig config = createMock(ServletConfig.class);
+        expect(config.getServletContext()).andReturn(context);
+        replay(config);
         servlet.init(config);
-        ServletRequest req = EasyMock.createNiceMock(ServletRequest.class);
-        ServletResponse res = EasyMock.createNiceMock(ServletResponse.class);
-        servlet.service(req, res);
-        EasyMock.verify(requestInjector);
+        servlet.service(req, resp);
+        verify(context);
+        verify(injector);
     }
 
+    public void testRuntimeNotConfigured() throws Exception {
+        ServletContext context = createNiceMock(ServletContext.class);
+        TuscanyServlet servlet = new TuscanyServlet();
+        ServletConfig config = createMock(ServletConfig.class);
+        expect(config.getServletContext()).andReturn(context);
+        replay(config);
+        try {
+            servlet.init(config);
+            fail();
+        } catch (ServletException e) {
+            //expected
+        }
+    }
 }

Added: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
(added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
Sat Sep  2 23:02:44 2006
@@ -0,0 +1,55 @@
+package org.apache.tuscany.runtime.webapp;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+
+import junit.framework.TestCase;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies {@link org.apache.tuscany.runtime.webapp.TuscanySessionListener} notifies the
runtime of session events
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanySessionListenerTestCase extends TestCase {
+
+    public void testSessionPropagated() throws Exception {
+        TuscanyWebappRuntime runtime = EasyMock.createNiceMock(TuscanyWebappRuntime.class);
+        runtime.sessionCreated(EasyMock.isA(HttpSessionEvent.class));
+        runtime.sessionDestroyed(EasyMock.isA(HttpSessionEvent.class));
+        EasyMock.replay(runtime);
+        ServletContext context = EasyMock.createNiceMock(ServletContext.class);
+        EasyMock.expect(context.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(runtime);
+        EasyMock.replay(context);
+        HttpSession session = EasyMock.createNiceMock(HttpSession.class);
+        EasyMock.expect(session.getServletContext()).andReturn(context);
+        EasyMock.replay(session);
+        HttpSessionEvent event = new HttpSessionEvent(session);
+        TuscanySessionListener listener = new TuscanySessionListener();
+        listener.sessionCreated(event);
+        listener.sessionDestroyed(event);
+        EasyMock.verify(context);
+        EasyMock.verify(runtime);
+    }
+
+    /**
+     * Verifies an error is logged when no runtime is configured
+     *
+     * @throws Exception
+     */
+    public void testRuntimeNotConfigured() throws Exception {
+        ServletContext context = EasyMock.createNiceMock(ServletContext.class);
+        context.log(EasyMock.isA(String.class), EasyMock.isA(ServletException.class));
+        EasyMock.replay(context);
+        TuscanySessionListener listener = new TuscanySessionListener();
+        HttpSession session = EasyMock.createNiceMock(HttpSession.class);
+        EasyMock.expect(session.getServletContext()).andReturn(context);
+        EasyMock.replay(session);
+        HttpSessionEvent event = new HttpSessionEvent(session);
+        listener.sessionCreated(event);
+        EasyMock.verify(context);
+    }
+}

Propchange: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message