From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/runtime/webapp/Foo.java | 25 ++++++ .../org/apache/tuscany/runtime/webapp/FooImpl.java | 25 ++++++ .../runtime/webapp/LazyHTTPSessionIdTestCase.java | 44 ++++++++++ .../runtime/webapp/ServletHostTestCase.java | 86 +++++++++++++++++++ .../runtime/webapp/WebappRuntimeImplTestCase.java | 98 ++++++++++++++++++++++ .../webapp-host/src/test/resources/testapp.scdl | 26 ++++++ 6 files changed, 304 insertions(+) create mode 100644 sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/Foo.java create mode 100644 sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/FooImpl.java create mode 100644 sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java create mode 100644 sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletHostTestCase.java create mode 100644 sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java create mode 100644 sandbox/old/contrib/runtime-webapp/webapp-host/src/test/resources/testapp.scdl (limited to 'sandbox/old/contrib/runtime-webapp/webapp-host/src/test') diff --git a/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/Foo.java b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/Foo.java new file mode 100644 index 0000000000..75b49de188 --- /dev/null +++ b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/Foo.java @@ -0,0 +1,25 @@ +/* + * 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; + +/** + * @version $Rev$ $Date$ + */ +public interface Foo { +} diff --git a/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/FooImpl.java b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/FooImpl.java new file mode 100644 index 0000000000..dd938f2a58 --- /dev/null +++ b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/FooImpl.java @@ -0,0 +1,25 @@ +/* + * 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; + +/** + * @version $Rev$ $Date$ + */ +public class FooImpl implements Foo { +} diff --git a/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java new file mode 100644 index 0000000000..f41fa2361b --- /dev/null +++ b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java @@ -0,0 +1,44 @@ +/* + * 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 static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import junit.framework.TestCase; + +public class LazyHTTPSessionIdTestCase extends TestCase { + + public void testGetIdentifier() { + HttpSession id = createMock(HttpSession.class); + + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getSession(true)).andReturn(id); + replay(request); + + LazyHTTPSessionId lazyHTTPSessionId = new LazyHTTPSessionId(request); + assertEquals(id, lazyHTTPSessionId.getIdentifier()); + } + +} diff --git a/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletHostTestCase.java b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletHostTestCase.java new file mode 100644 index 0000000000..3d979e8f46 --- /dev/null +++ b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletHostTestCase.java @@ -0,0 +1,86 @@ +/* + * 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 static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.verify; + +import javax.servlet.Servlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class ServletHostTestCase extends TestCase { + + public void testDispatch() throws Exception { + HttpServletRequest req = createMock(HttpServletRequest.class); + expect(req.getPathInfo()).andReturn("foo"); + replay(req); + HttpServletResponse res = createMock(HttpServletResponse.class); + Servlet servlet = createMock(Servlet.class); + servlet.service(req, res); + EasyMock.expectLastCall(); + replay(servlet); + ServletHostImpl host = new ServletHostImpl(); + host.registerMapping("foo", servlet); + host.service(req, res); + verify(servlet); + } + + public void testDuplicateRegistration() throws Exception { + Servlet servlet = createMock(Servlet.class); + ServletHostImpl host = new ServletHostImpl(); + host.registerMapping("foo", servlet); + assertEquals(true, host.isMappingRegistered("foo")); + assertEquals(false, host.isMappingRegistered("bar")); + try { + host.registerMapping("foo", servlet); + fail(); + } catch (IllegalStateException e) { + // expected + } + } + + public void testUnregister() throws Exception { + HttpServletRequest req = createMock(HttpServletRequest.class); + expect(req.getPathInfo()).andReturn("foo"); + replay(req); + HttpServletResponse res = createMock(HttpServletResponse.class); + Servlet servlet = createMock(Servlet.class); + replay(servlet); + ServletHostImpl host = new ServletHostImpl(); + host.registerMapping("foo", servlet); + Servlet unregedServlet = host.unregisterMapping("foo"); + assertEquals(unregedServlet, servlet); + try { + host.service(req, res); + } catch (IllegalStateException e) { + // expected + } + verify(servlet); + } + +} diff --git a/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java new file mode 100644 index 0000000000..c076fb73cf --- /dev/null +++ b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java @@ -0,0 +1,98 @@ +/* + * 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 static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + +import java.net.URL; + +import javax.servlet.ServletContext; + +import junit.framework.TestCase; + +import org.apache.tuscany.core.monitor.NullMonitorFactory; + +/** + * @version $Rev$ $Date$ + */ +public class WebappRuntimeImplTestCase extends TestCase { + private URL applicationScdl; + private URL systemScdl; + private WebappRuntimeImpl runtime; + private ServletContext context; + + /** + * Verifies the web app host is configured properly to perform a basic boot + */ + public void testBootWithDefaults() throws Exception { + expect(context.getResourcePaths("/WEB-INF/tuscany/extensions/")).andReturn(null); + replay(context); + runtime.initialize(); + verify(context); + } + +/* + public void testLazyHttpSessionId() throws Exception { + expect(context.getResourcePaths("/WEB-INF/tuscany/extensions/")).andReturn(null); + replay(context); + runtime.initialize(); + verify(context); + + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getSession(true)).andReturn(null); + expect(request.getSession(false)).andReturn(null); + replay(request); + + runtime.httpRequestStarted(request); + + ServletRequestInjector injector = runtime.getRequestInjector(); + class WorkContextAccessor extends ServletHostImpl { + ServletHostImpl servletHostImpl; + WorkContextAccessor(ServletHostImpl servletHostImpl){ + this.servletHostImpl = servletHostImpl; + } + WorkContext getWorkContext() { + return servletHostImpl.workContext; + } + } + WorkContext workContext = new WorkContextAccessor((ServletHostImpl)injector).getWorkContext(); + workContext.getIdentifier(Scope.SESSION); + verify(request); + } +*/ + + protected void setUp() throws Exception { + super.setUp(); + systemScdl = getClass().getResource("/META-INF/tuscany/webapp.scdl"); + applicationScdl = getClass().getResource("/testapp.scdl"); + context = createMock(ServletContext.class); + + runtime = new WebappRuntimeImpl(); + runtime.setRuntimeInfo(new WebappRuntimeInfoImpl(context, null, false)); + runtime.setMonitorFactory(new NullMonitorFactory()); + runtime.setHostClassLoader(getClass().getClassLoader()); + runtime.setServletContext(context); + runtime.setSystemScdl(systemScdl); + runtime.setApplicationName("foo"); + runtime.setApplicationScdl(applicationScdl); + } +} diff --git a/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/resources/testapp.scdl b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/resources/testapp.scdl new file mode 100644 index 0000000000..9b5bda7fb6 --- /dev/null +++ b/sandbox/old/contrib/runtime-webapp/webapp-host/src/test/resources/testapp.scdl @@ -0,0 +1,26 @@ + + + + + + + + + -- cgit v1.2.3