tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r451319 - in /incubator/tuscany/java/sca/runtime/webapp/src: main/java/org/apache/tuscany/runtime/webapp/ test/java/org/apache/tuscany/runtime/webapp/
Date Fri, 29 Sep 2006 15:02:16 GMT
Author: jboynes
Date: Fri Sep 29 08:02:15 2006
New Revision: 451319

URL: http://svn.apache.org/viewvc?view=rev&rev=451319
Log:
refactor webapp property support into a utility class

Added:
    incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.java
  (with props)
    incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.java
  (with props)
    incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java
  (with props)
Modified:
    incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
    incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java

Modified: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java?view=diff&rev=451319&r1=451318&r2=451319
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
(original)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
Fri Sep 29 08:02:15 2006
@@ -20,22 +20,12 @@
 
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Set;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 
 import org.apache.tuscany.api.TuscanyRuntimeException;
-import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT;
-import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
-import static org.apache.tuscany.runtime.webapp.Constants.BOOTDIR_DEFAULT;
-import static org.apache.tuscany.runtime.webapp.Constants.BOOTDIR_PARAM;
 import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
-import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_DEFAULT;
-import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_PARAM;
-import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_DEFAULT;
-import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_PARAM;
 
 /**
  * Launches a Tuscany runtime in a web application, loading information from servlet context
parameters. This listener
@@ -60,15 +50,16 @@
 
     public void contextInitialized(ServletContextEvent event) {
         ServletContext servletContext = event.getServletContext();
+        WebappUtil utils = getUtils(servletContext);
         try {
             ClassLoader webappClassLoader = Thread.currentThread().getContextClassLoader();
-            ClassLoader bootClassLoader = getBootClassLoader(servletContext, webappClassLoader);
-            WebappRuntime runtime = getRuntime(servletContext, bootClassLoader);
+            ClassLoader bootClassLoader = utils.getBootClassLoader(webappClassLoader);
+            WebappRuntime runtime = utils.getRuntime(bootClassLoader);
             WebappRuntimeInfo info = new WebappRuntimeInfoImpl(servletContext,
                                                                servletContext.getResource("/WEB-INF/tuscany/"));
-            URL systemScdl = getSystemScdl(servletContext, bootClassLoader);
-            URL applicationScdl = getApplicationScdl(servletContext, webappClassLoader);
-            String name = getApplicationName(servletContext);
+            URL systemScdl = utils.getSystemScdl(bootClassLoader);
+            URL applicationScdl = utils.getApplicationScdl(webappClassLoader);
+            String name = utils.getApplicationName();
 
             runtime.setServletContext(servletContext);
             runtime.setMonitorFactory(runtime.createDefaultMonitorFactory());
@@ -89,6 +80,10 @@
         }
     }
 
+    protected WebappUtil getUtils(ServletContext servletContext) {
+        return new WebappUtilImpl(servletContext);
+    }
+
     public void contextDestroyed(ServletContextEvent event) {
         ServletContext servletContext = event.getServletContext();
         WebappRuntime runtime = (WebappRuntime) servletContext.getAttribute(RUNTIME_ATTRIBUTE);
@@ -100,98 +95,4 @@
         runtime.destroy();
     }
 
-    /**
-     * Return the classloader that should be used to boot the Tuscany runtime.
-     * This will be a child of the web application's ClassLoader.
-     *
-     * @param servletContext    the servlet context for the webapp containing the bootstrap
classes
-     * @param webappClassLoader the web application's classloader
-     * @return a classloader that can be used to load the Tuscany runtime classes
-     */
-    protected ClassLoader getBootClassLoader(ServletContext servletContext, ClassLoader webappClassLoader)
{
-        String bootDirName = getInitParameter(servletContext, BOOTDIR_PARAM, BOOTDIR_DEFAULT);
-        Set paths = servletContext.getResourcePaths(bootDirName);
-        if (paths == null) {
-            // nothing in boot directory, assume everything is in the webapp classloader
-            return webappClassLoader;
-        }
-        URL[] urls = new URL[paths.size()];
-        int i = 0;
-        for (Object path : paths) {
-            try {
-                urls[i++] = servletContext.getResource((String) path);
-            } catch (MalformedURLException e) {
-                throw new AssertionError("getResourcePaths returned an invalid path: " +
path);
-            }
-        }
-        return new URLClassLoader(urls, webappClassLoader);
-    }
-
-    protected WebappRuntime getRuntime(ServletContext servletContext, ClassLoader bootClassLoader)
{
-        try {
-            String className = getInitParameter(servletContext, RUNTIME_PARAM, RUNTIME_DEFAULT);
-            Class<?> runtimeClass = bootClassLoader.loadClass(className);
-            return (WebappRuntime) runtimeClass.newInstance();
-        } catch (InstantiationException e) {
-            throw new TuscanyInitException("Invalid runtime class", e);
-        } catch (IllegalAccessException e) {
-            throw new TuscanyInitException("Invalid runtime class", e);
-        } catch (ClassNotFoundException e) {
-            throw new TuscanyInitException("Runtime Implementation not found", e);
-        }
-    }
-
-    protected URL getSystemScdl(ServletContext servletContext, ClassLoader bootClassLoader)
{
-        String path = getInitParameter(servletContext, SYSTEM_SCDL_PATH_PARAM, SYSTEM_SCDL_PATH_DEFAULT);
-        try {
-            return getScdlURL(path, servletContext, bootClassLoader);
-        } catch (MalformedURLException e) {
-            throw new TuscanyInitException("Invalid resource path for " + SYSTEM_SCDL_PATH_PARAM
+ " : " + path, e);
-        }
-    }
-
-    protected String getApplicationName(ServletContext servletContext) {
-        String name = servletContext.getServletContextName();
-        if (name == null) {
-            name = "application";
-        }
-        return name;
-    }
-
-    protected URL getApplicationScdl(ServletContext servletContext, ClassLoader bootClassLoader)
{
-        String path = getInitParameter(servletContext, APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT);
-        try {
-            return getScdlURL(path, servletContext, bootClassLoader);
-        } catch (MalformedURLException e) {
-            throw new TuscanyInitException("Invalid resource path for " + APPLICATION_SCDL_PATH_PARAM
+ " : " + path,
-                                           e);
-        }
-    }
-
-    protected URL getScdlURL(String path, ServletContext servletContext, ClassLoader classLoader)
-        throws MalformedURLException {
-        if (path.charAt(0) == '/') {
-            // user supplied an absolute path - look up as a webapp resource
-            return servletContext.getResource(path);
-        } else {
-            // user supplied a relative path - look up as a boot classpath resource
-            return classLoader.getResource(path);
-        }
-    }
-
-    /**
-     * Return a init parameter from the servlet context or provide a default.
-     *
-     * @param servletContext the servlet context for the application
-     * @param name           the name of the parameter
-     * @param value          the default value
-     * @return the value of the specified parameter, or the default if not defined
-     */
-    protected String getInitParameter(ServletContext servletContext, String name, String
value) {
-        String result = servletContext.getInitParameter(name);
-        if (result != null && result.length() != 0) {
-            return result;
-        }
-        return value;
-    }
 }

Added: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.java?view=auto&rev=451319
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.java
(added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.java
Fri Sep 29 08:02:15 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface WebappUtil {
+    /**
+     * Return the classloader that should be used to boot the Tuscany runtime.
+     * This will be a child of the web application's ClassLoader.
+     *
+     * @param servletContext    the servlet context for the webapp containing the bootstrap
classes
+     * @param webappClassLoader the web application's classloader
+     * @return a classloader that can be used to load the Tuscany runtime classes
+     */
+    ClassLoader getBootClassLoader(ClassLoader webappClassLoader);
+
+    WebappRuntime getRuntime(ClassLoader bootClassLoader);
+
+    URL getSystemScdl(ClassLoader bootClassLoader);
+
+    String getApplicationName();
+
+    URL getApplicationScdl(ClassLoader bootClassLoader);
+
+    URL getScdlURL(String path, ClassLoader classLoader)
+        throws MalformedURLException;
+
+    /**
+     * Return a init parameter from the servlet context or provide a default.
+     *
+     * @param name  the name of the parameter
+     * @param value the default value
+     * @return the value of the specified parameter, or the default if not defined
+     */
+    String getInitParameter(String name, String value);
+}

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

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

Added: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.java?view=auto&rev=451319
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.java
(added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.java
Fri Sep 29 08:02:15 2006
@@ -0,0 +1,124 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Set;
+import javax.servlet.ServletContext;
+
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.BOOTDIR_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.BOOTDIR_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_PARAM;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappUtilImpl implements WebappUtil {
+    private final ServletContext servletContext;
+
+    public WebappUtilImpl(ServletContext servletContext) {
+        this.servletContext = servletContext;
+    }
+
+    public ClassLoader getBootClassLoader(ClassLoader webappClassLoader) {
+        String bootDirName = getInitParameter(BOOTDIR_PARAM, BOOTDIR_DEFAULT);
+        Set paths = servletContext.getResourcePaths(bootDirName);
+        if (paths == null) {
+            // nothing in boot directory, assume everything is in the webapp classloader
+            return webappClassLoader;
+        }
+        URL[] urls = new URL[paths.size()];
+        int i = 0;
+        for (Object path : paths) {
+            try {
+                urls[i++] = servletContext.getResource((String) path);
+            } catch (MalformedURLException e) {
+                throw new AssertionError("getResourcePaths returned an invalid path: " +
path);
+            }
+        }
+        return new URLClassLoader(urls, webappClassLoader);
+    }
+
+    public WebappRuntime getRuntime(ClassLoader bootClassLoader) {
+        try {
+            String className = getInitParameter(RUNTIME_PARAM, RUNTIME_DEFAULT);
+            Class<?> runtimeClass = bootClassLoader.loadClass(className);
+            return (WebappRuntime) runtimeClass.newInstance();
+        } catch (InstantiationException e) {
+            throw new TuscanyInitException("Invalid runtime class", e);
+        } catch (IllegalAccessException e) {
+            throw new TuscanyInitException("Invalid runtime class", e);
+        } catch (ClassNotFoundException e) {
+            throw new TuscanyInitException("Runtime Implementation not found", e);
+        }
+    }
+
+    public URL getSystemScdl(ClassLoader bootClassLoader) {
+        String path = getInitParameter(SYSTEM_SCDL_PATH_PARAM, SYSTEM_SCDL_PATH_DEFAULT);
+        try {
+            return getScdlURL(path, bootClassLoader);
+        } catch (MalformedURLException e) {
+            throw new TuscanyInitException("Invalid resource path for " + SYSTEM_SCDL_PATH_PARAM
+ " : " + path, e);
+        }
+    }
+
+    public String getApplicationName() {
+        String name = servletContext.getServletContextName();
+        if (name == null) {
+            name = "application";
+        }
+        return name;
+    }
+
+    public URL getApplicationScdl(ClassLoader bootClassLoader) {
+        String path = getInitParameter(APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT);
+        try {
+            return getScdlURL(path, bootClassLoader);
+        } catch (MalformedURLException e) {
+            throw new TuscanyInitException("Invalid resource path for " + APPLICATION_SCDL_PATH_PARAM
+ " : " + path,
+                                           e);
+        }
+    }
+
+    public URL getScdlURL(String path, ClassLoader classLoader)
+        throws MalformedURLException {
+        if (path.charAt(0) == '/') {
+            // user supplied an absolute path - look up as a webapp resource
+            return servletContext.getResource(path);
+        } else {
+            // user supplied a relative path - look up as a boot classpath resource
+            return classLoader.getResource(path);
+        }
+    }
+
+    public String getInitParameter(String name, String value) {
+        String result = servletContext.getInitParameter(name);
+        if (result != null && result.length() != 0) {
+            return result;
+        }
+        return value;
+    }
+}

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

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

Modified: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java?view=diff&rev=451319&r1=451318&r2=451319
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
(original)
+++ incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
Fri Sep 29 08:02:15 2006
@@ -19,7 +19,6 @@
 package org.apache.tuscany.runtime.webapp;
 
 import java.net.URL;
-import java.net.MalformedURLException;
 import java.lang.reflect.Method;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
@@ -36,147 +35,67 @@
     private ServletContext context;
     private TuscanyContextListener listener;
     private ClassLoader cl;
+    private ClassLoader bootClassLoader;
     private URL systemUrl;
     private URL applicationUrl;
-    private Method getRuntimeMethod;
+    private Method getUtilsMethod;
     private MonitorFactory monitorFactory;
+    private WebappUtil utils;
 
     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.getRuntime(bootClassLoader)).andReturn(runtime);
+        expect(utils.getSystemScdl(bootClassLoader)).andReturn(systemUrl);
+        expect(utils.getApplicationScdl(cl)).andReturn(applicationUrl);
+        expect(utils.getApplicationName()).andReturn("application");
+        replay(utils);
+
+        expect(context.getResource("/WEB-INF/tuscany/")).andReturn(null);
+        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);
+        expect(runtime.createDefaultMonitorFactory()).andReturn(monitorFactory);
+        runtime.setMonitorFactory(monitorFactory);
+        runtime.setRuntimeInfo(isA(WebappRuntimeInfo.class));
+        runtime.setHostClassLoader(cl);
+        runtime.setSystemScdl(systemUrl);
+        runtime.setApplicationName("application");
+        runtime.setApplicationScdl(applicationUrl);
+        runtime.initialize();
+        replay(runtime);
+
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
-        listener = createMock(TuscanyContextListener.class, new Method[]{getRuntimeMethod});
         try {
             Thread.currentThread().setContextClassLoader(cl);
-            ServletContextEvent event = createMock(ServletContextEvent.class);
-            WebappRuntime runtime = createMock(WebappRuntime.class);
-            expect(event.getServletContext()).andReturn(context);
-            replay(event);
-            expect(context.getInitParameter("tuscany.bootDir")).andReturn(null);
-            expect(context.getResourcePaths("/WEB-INF/tuscany/boot")).andReturn(null);
-            expect(context.getResource("/WEB-INF/tuscany/")).andReturn(null);
-            expect(context.getInitParameter("tuscany.systemScdlPath")).andReturn(null);
-            expect(context.getServletContextName()).andReturn(null);
-            expect(context.getInitParameter("tuscany.applicationScdlPath")).andReturn(null);
-            expect(context.getResource("/WEB-INF/default.scdl")).andReturn(applicationUrl);
-            context.setAttribute(eq(Constants.RUNTIME_ATTRIBUTE), isA(WebappRuntime.class));
-            replay(context);
-            expect(cl.getResource("META-INF/tuscany/webapp.scdl")).andReturn(systemUrl);
-            replay(cl);
-            expect(listener.getRuntime(context, cl)).andReturn(runtime);
-            replay(listener);
-            runtime.setServletContext(context);
-            expect(runtime.createDefaultMonitorFactory()).andReturn(monitorFactory);
-            runtime.setMonitorFactory(monitorFactory);
-            runtime.setRuntimeInfo(isA(WebappRuntimeInfo.class));
-            runtime.setHostClassLoader(cl);
-            runtime.setSystemScdl(systemUrl);
-            runtime.setApplicationName("application");
-            runtime.setApplicationScdl(applicationUrl);
-            runtime.initialize();
-            replay(runtime);
             listener.contextInitialized(event);
-            verify(event);
-            verify(context);
-            verify(listener);
-            verify(cl);
-            verify(runtime);
         } finally {
             Thread.currentThread().setContextClassLoader(oldCl);
         }
-    }
-
-    public void testGetInitParameterWhenSpecified() {
-        String name = "name";
-        String value = "default";
-        expect(context.getInitParameter(name)).andReturn(value);
-        replay(context);
-
-        assertEquals(value, listener.getInitParameter(context, name, "default"));
-        verify(context);
-    }
-
-    public void testGetInitParameterUsingDefault() {
-        String name = "name";
-        String value = "default";
-        expect(context.getInitParameter(name)).andReturn(null);
-        replay(context);
-
-        assertEquals(value, listener.getInitParameter(context, name, value));
-        verify(context);
-    }
-
-    public void testGetInitParameterWithZeroLength() {
-        String name = "name";
-        String value = "default";
-        expect(context.getInitParameter(name)).andReturn("");
-        replay(context);
-
-        assertEquals(value, listener.getInitParameter(context, name, value));
-        verify(context);
-    }
-
-    public void testGetScdlFromWebapp() throws MalformedURLException {
-        String path = "/WEB-INF/test";
-        expect(context.getResource(path)).andReturn(systemUrl);
-        replay(context);
-        replay(cl);
-        assertSame(systemUrl, listener.getScdlURL(path, context, cl));
-        verify(context);
-        verify(cl);
-    }
-
-    public void testGetScdlFromWebappMissing() throws MalformedURLException {
-        String path = "/WEB-INF/test";
-        expect(context.getResource(path)).andReturn(null);
-        replay(context);
-        replay(cl);
-        assertNull(listener.getScdlURL(path, context, cl));
-        verify(context);
-        verify(cl);
-    }
-
-    public void testGetScdlFromWebappMalformed() throws MalformedURLException {
-        String path = "/WEB-INF/test";
-        expect(context.getResource(path)).andThrow(new MalformedURLException());
-        replay(context);
-        replay(cl);
-        try {
-            listener.getScdlURL(path, context, cl);
-            fail();
-        } catch (MalformedURLException e) {
-            // OK
-        }
-        verify(context);
-        verify(cl);
-    }
-
-    public void testGetScdlFromClasspath() throws MalformedURLException {
-        String path = "META-INF/test";
-        replay(context);
-        expect(cl.getResource(path)).andReturn(systemUrl);
-        replay(cl);
-        assertSame(systemUrl, listener.getScdlURL(path, context, cl));
-        verify(context);
-        verify(cl);
-    }
-
-    public void testGetScdlFromClasspathMissing() throws MalformedURLException {
-        String path = "META-INF/test";
-        replay(context);
-        expect(cl.getResource(path)).andReturn(null);
-        replay(cl);
-        assertNull(listener.getScdlURL(path, context, cl));
+        verify(event);
         verify(context);
+        verify(listener);
         verify(cl);
+        verify(bootClassLoader);
+        verify(runtime);
     }
 
     protected void setUp() throws Exception {
         super.setUp();
-        getRuntimeMethod = TuscanyContextListener.class.getDeclaredMethod("getRuntime",
-                                                                          ServletContext.class,
-                                                                          ClassLoader.class);
-        listener = new TuscanyContextListener();
+        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");
         applicationUrl = new URL("file:/application.scdl");
         monitorFactory = createMock(MonitorFactory.class);

Added: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java?view=auto&rev=451319
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java
(added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java
Fri Sep 29 08:02:15 2006
@@ -0,0 +1,130 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URL;
+import javax.servlet.ServletContext;
+
+import junit.framework.TestCase;
+import static org.easymock.classextension.EasyMock.*;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappUtilTestCase extends TestCase {
+    private ServletContext context;
+    private WebappUtilImpl listener;
+    private ClassLoader cl;
+    private URL systemUrl;
+
+
+    public void testGetInitParameterWhenSpecified() {
+        String name = "name";
+        String value = "default";
+        expect(context.getInitParameter(name)).andReturn(value);
+        replay(context);
+
+        assertEquals(value, listener.getInitParameter(name, "default"));
+        verify(context);
+    }
+
+    public void testGetInitParameterUsingDefault() {
+        String name = "name";
+        String value = "default";
+        expect(context.getInitParameter(name)).andReturn(null);
+        replay(context);
+
+        assertEquals(value, listener.getInitParameter(name, value));
+        verify(context);
+    }
+
+    public void testGetInitParameterWithZeroLength() {
+        String name = "name";
+        String value = "default";
+        expect(context.getInitParameter(name)).andReturn("");
+        replay(context);
+
+        assertEquals(value, listener.getInitParameter(name, value));
+        verify(context);
+    }
+
+    public void testGetScdlFromWebapp() throws MalformedURLException {
+        String path = "/WEB-INF/test";
+        expect(context.getResource(path)).andReturn(systemUrl);
+        replay(context);
+        replay(cl);
+        assertSame(systemUrl, listener.getScdlURL(path, cl));
+        verify(context);
+        verify(cl);
+    }
+
+    public void testGetScdlFromWebappMissing() throws MalformedURLException {
+        String path = "/WEB-INF/test";
+        expect(context.getResource(path)).andReturn(null);
+        replay(context);
+        replay(cl);
+        assertNull(listener.getScdlURL(path, cl));
+        verify(context);
+        verify(cl);
+    }
+
+    public void testGetScdlFromWebappMalformed() throws MalformedURLException {
+        String path = "/WEB-INF/test";
+        expect(context.getResource(path)).andThrow(new MalformedURLException());
+        replay(context);
+        replay(cl);
+        try {
+            listener.getScdlURL(path, cl);
+            fail();
+        } catch (MalformedURLException e) {
+            // OK
+        }
+        verify(context);
+        verify(cl);
+    }
+
+    public void testGetScdlFromClasspath() throws MalformedURLException {
+        String path = "META-INF/test";
+        replay(context);
+        expect(cl.getResource(path)).andReturn(systemUrl);
+        replay(cl);
+        assertSame(systemUrl, listener.getScdlURL(path, cl));
+        verify(context);
+        verify(cl);
+    }
+
+    public void testGetScdlFromClasspathMissing() throws MalformedURLException {
+        String path = "META-INF/test";
+        replay(context);
+        expect(cl.getResource(path)).andReturn(null);
+        replay(cl);
+        assertNull(listener.getScdlURL(path, cl));
+        verify(context);
+        verify(cl);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        context = createMock(ServletContext.class);
+        listener = new WebappUtilImpl(context);
+        cl = createMock(ClassLoader.class);
+        systemUrl = new URL("file:/system.scdl");
+    }
+}

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

Propchange: incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.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