diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /sandbox/old/contrib/runtime-webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/old/contrib/runtime-webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java')
-rw-r--r-- | sandbox/old/contrib/runtime-webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/sandbox/old/contrib/runtime-webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java b/sandbox/old/contrib/runtime-webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java new file mode 100644 index 0000000000..aa237da01c --- /dev/null +++ b/sandbox/old/contrib/runtime-webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java @@ -0,0 +1,113 @@ +/* + * 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 java.lang.reflect.Method; +import java.net.URL; +import java.net.URI; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import junit.framework.TestCase; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.eq; +import static org.easymock.classextension.EasyMock.expect; +import static org.easymock.classextension.EasyMock.isA; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM; +import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT; + +/** + * @version $Rev$ $Date$ + */ +public class TuscanyContextListenerTestCase extends TestCase { + private String contextName; + private ServletContext context; + private TuscanyContextListener listener; + private ClassLoader cl; + private ClassLoader bootClassLoader; + private URL systemUrl; + private URL scdl; + private WebappUtil utils; + private String compositeId; + + public void testInitializationUsingDefaults() throws Exception { + ServletContextEvent event = createMock(ServletContextEvent.class); + expect(event.getServletContext()).andReturn(context); + replay(event); + + WebappRuntime runtime = createMock(WebappRuntime.class); + expect(utils.getBootClassLoader(cl)).andReturn(bootClassLoader); + expect(utils.getInitParameter("tuscany.composite", compositeId)).andReturn(compositeId); + expect(utils.getInitParameter("tuscany.component", contextName)).andReturn(contextName); + expect(utils.getInitParameter("tuscany.online", "true")).andReturn("true"); + expect(utils.getInitParameter(APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT)) + .andReturn(APPLICATION_SCDL_PATH_DEFAULT); + expect(utils.getRuntime(bootClassLoader)).andReturn(runtime); + expect(utils.getSystemScdl(bootClassLoader)).andReturn(systemUrl); + replay(utils); + + expect(context.getResource("/WEB-INF/tuscany/")).andReturn(null); + expect(context.getResource(APPLICATION_SCDL_PATH_DEFAULT)).andReturn(scdl); + context.setAttribute(eq(Constants.RUNTIME_ATTRIBUTE), isA(WebappRuntime.class)); + replay(context); + replay(cl); + replay(bootClassLoader); + expect(listener.getUtils(context)).andReturn(utils); + replay(listener); + runtime.setServletContext(context); + runtime.setRuntimeInfo(isA(WebappRuntimeInfo.class)); + runtime.setHostClassLoader(cl); + runtime.setSystemScdl(systemUrl); + runtime.initialize(); + runtime.deploy(URI.create(compositeId), scdl, URI.create(contextName)); + replay(runtime); + + ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(cl); + listener.contextInitialized(event); + } finally { + Thread.currentThread().setContextClassLoader(oldCl); + } + verify(event); + verify(utils); + verify(context); + verify(listener); + verify(cl); + verify(bootClassLoader); + verify(runtime); + } + + protected void setUp() throws Exception { + super.setUp(); + Method getUtilsMethod = TuscanyContextListener.class.getDeclaredMethod("getUtils", ServletContext.class); + utils = createMock(WebappUtil.class); + listener = createMock(TuscanyContextListener.class, new Method[]{getUtilsMethod}); + context = createMock(ServletContext.class); + cl = createMock(ClassLoader.class); + bootClassLoader = createMock(ClassLoader.class); + systemUrl = new URL("file:/system.scdl"); + scdl = new URL("file:/app.scdl"); + contextName = "webapp"; + compositeId = "http://locahost/sca"; + } +} |