notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r1401 - in trunk/main/planet/http/impl/src: main/net/dpml/http test/net/dpml/http
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r1401 - in trunk/main/planet/http/impl/src: main/net/dpml/http test/net/dpml/http
- Date: Mon, 24 Apr 2006 18:10:57 +0200
Author: mcconnell
Date: 2006-04-24 18:10:56 +0200 (Mon, 24 Apr 2006)
New Revision: 1401
Added:
trunk/main/planet/http/impl/src/test/net/dpml/http/AbstractContextHandlerTestCase.java
trunk/main/planet/http/impl/src/test/net/dpml/http/ResourceContextHandlerTestCase.java
trunk/main/planet/http/impl/src/test/net/dpml/http/ServletContextHandlerTestCase.java
trunk/main/planet/http/impl/src/test/net/dpml/http/StandardLogger.java
Modified:
trunk/main/planet/http/impl/src/main/net/dpml/http/ResourceContextHandler.java
Log:
additional testcases under the http impl package
Modified:
trunk/main/planet/http/impl/src/main/net/dpml/http/ResourceContextHandler.java
===================================================================
---
trunk/main/planet/http/impl/src/main/net/dpml/http/ResourceContextHandler.java
2006-04-24 11:38:02 UTC (rev 1400)
+++
trunk/main/planet/http/impl/src/main/net/dpml/http/ResourceContextHandler.java
2006-04-24 16:10:56 UTC (rev 1401)
@@ -25,7 +25,7 @@
public class ResourceContextHandler extends
org.mortbay.jetty.handler.ContextHandler
{
/**
- * HTTP static resource vontext handler parameters.
+ * HTTP static resource context handler parameters.
*/
public interface Context extends ContextHandlerContext
{
@@ -38,8 +38,6 @@
String getResourceBase();
}
- private int m_priority = 0;
-
/**
* Creation of a new resource context handler.
* @param logger the assigned logging channel
Added:
trunk/main/planet/http/impl/src/test/net/dpml/http/AbstractContextHandlerTestCase.java
===================================================================
---
trunk/main/planet/http/impl/src/test/net/dpml/http/AbstractContextHandlerTestCase.java
2006-04-24 11:38:02 UTC (rev 1400)
+++
trunk/main/planet/http/impl/src/test/net/dpml/http/AbstractContextHandlerTestCase.java
2006-04-24 16:10:56 UTC (rev 1401)
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed 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 net.dpml.http;
+
+import java.util.Map;
+import java.util.Hashtable;
+
+import net.dpml.http.ResourceContextHandler.Context;
+
+import net.dpml.util.ContextInvocationHandler;
+
+import net.dpml.logging.Logger;
+
+import org.mortbay.jetty.handler.ErrorHandler;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.MimeTypes;
+
+import junit.framework.TestCase;
+
+/**
+ * NCSARequestLog test case.
+ */
+public abstract class AbstractContextHandlerTestCase extends TestCase
+{
+ private static final String[] VIRTUAL_HOSTS = new
String[]{"virtual.acme.org", "virtual.secret.acme.org"};
+ private static final String[] HOSTS = new String[]{"www.acme.org",
"secret.acme.org"};
+ private static final String[] WELCOME_FILES = new
String[]{"about.html","index.html","index.htm"};
+ private static final ClassLoader CLASSLOADER =
AbstractContextHandlerTestCase.class.getClassLoader();
+ private static final Map MIME_TYPES = new Hashtable();
+ private static final String CONTEXT_PATH = "acme";
+ private static final String DISPLAY_NAME = "testing";
+ private static final ErrorHandler ERROR_HANDLER = new ErrorHandler();
+
+ /**
+ * Setup the context map.
+ * @throws Exception if an error occurs
+ */
+ protected Map createMap() throws Exception
+ {
+ Map map = new Hashtable();
+ map.put( "virtualHosts", VIRTUAL_HOSTS );
+ map.put( "hosts", HOSTS );
+ map.put( "welcomeFiles", WELCOME_FILES );
+ map.put( "classLoader", CLASSLOADER );
+ map.put( "contextPath", CONTEXT_PATH );
+ map.put( "displayName", DISPLAY_NAME );
+ map.put( "mimeTypes", MIME_TYPES );
+ map.put( "errorHandler", ERROR_HANDLER );
+ return map;
+ }
+
+ protected abstract ContextHandler getContextHandler();
+
+ /**
+ * Test virtual hosts assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testVirtualHosts() throws Exception
+ {
+ assertEquals( "virtualHosts", VIRTUAL_HOSTS,
getContextHandler().getVirtualHosts() );
+ }
+
+ /**
+ * Test hosts assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testHosts() throws Exception
+ {
+ assertEquals( "hosts", HOSTS, getContextHandler().getHosts() );
+ }
+
+ /**
+ * Test welcome files assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testWelcomeFiles() throws Exception
+ {
+ assertEquals( "welcomeFiles", WELCOME_FILES,
getContextHandler().getWelcomeFiles() );
+ }
+
+ /**
+ * Test classloader assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testClassLoader() throws Exception
+ {
+ assertEquals( "classloader", CLASSLOADER,
getContextHandler().getClassLoader() );
+ }
+
+ /**
+ * Test context path assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testContextPath() throws Exception
+ {
+ assertEquals( "contextPath", CONTEXT_PATH,
getContextHandler().getContextPath() );
+ }
+
+ /**
+ * Test display name assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testDisplayName() throws Exception
+ {
+ assertEquals( "displayName", DISPLAY_NAME,
getContextHandler().getDisplayName() );
+ }
+
+ /**
+ * Test error handler assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testErrorHandler() throws Exception
+ {
+
+ assertEquals( "errorHandler", ERROR_HANDLER,
getContextHandler().getErrorHandler() );
+ }
+}
+
Added:
trunk/main/planet/http/impl/src/test/net/dpml/http/ResourceContextHandlerTestCase.java
===================================================================
---
trunk/main/planet/http/impl/src/test/net/dpml/http/ResourceContextHandlerTestCase.java
2006-04-24 11:38:02 UTC (rev 1400)
+++
trunk/main/planet/http/impl/src/test/net/dpml/http/ResourceContextHandlerTestCase.java
2006-04-24 16:10:56 UTC (rev 1401)
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed 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 net.dpml.http;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Hashtable;
+
+import net.dpml.http.ResourceContextHandler.Context;
+
+import net.dpml.util.ContextInvocationHandler;
+
+import net.dpml.logging.Logger;
+
+import org.mortbay.jetty.handler.ContextHandler;
+
+/**
+ * NCSARequestLog test case.
+ */
+public class ResourceContextHandlerTestCase extends
AbstractContextHandlerTestCase
+{
+ private static final String RESOURCE_BASE = ".";
+
+ private ResourceContextHandler m_handler;
+
+ /**
+ * Setup the ResourceContextHandler.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void setUp() throws Exception
+ {
+ Map map = createMap();
+
+ map.put( "resourceBase", RESOURCE_BASE );
+
+ Class clazz = Context.class;
+ Context context = (Context)
ContextInvocationHandler.getProxiedInstance( clazz, map );
+ Logger logger = new StandardLogger( "test" );
+ m_handler = new ResourceContextHandler( logger, context );
+ }
+
+ protected ContextHandler getContextHandler()
+ {
+ return m_handler;
+ }
+
+ /**
+ * Test resource base assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testResourceBase() throws Exception
+ {
+ File file = new File( RESOURCE_BASE );
+ String base = file.getCanonicalFile().toURI().toString();
+ assertEquals( "resourceBase", base, m_handler.getResourceBase() );
+ }
+
+}
+
Added:
trunk/main/planet/http/impl/src/test/net/dpml/http/ServletContextHandlerTestCase.java
===================================================================
---
trunk/main/planet/http/impl/src/test/net/dpml/http/ServletContextHandlerTestCase.java
2006-04-24 11:38:02 UTC (rev 1400)
+++
trunk/main/planet/http/impl/src/test/net/dpml/http/ServletContextHandlerTestCase.java
2006-04-24 16:10:56 UTC (rev 1401)
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006 Stephen J. McConnell.
+ *
+ * Licensed 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 net.dpml.http;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Hashtable;
+
+import net.dpml.http.ServletContextHandler.Context;
+
+import net.dpml.util.ContextInvocationHandler;
+
+import net.dpml.logging.Logger;
+
+import org.mortbay.jetty.handler.ContextHandler;
+
+/**
+ * NCSARequestLog test case.
+ */
+public class ServletContextHandlerTestCase extends
AbstractContextHandlerTestCase
+{
+ private static final String RESOURCE_BASE = ".";
+
+ private ServletContextHandler m_handler;
+
+ /**
+ * Setup the ResourceContextHandler.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void setUp() throws Exception
+ {
+ Map map = createMap();
+
+ map.put( "resourceBase", RESOURCE_BASE );
+
+ Class clazz = Context.class;
+ Context context = (Context)
ContextInvocationHandler.getProxiedInstance( clazz, map );
+ Logger logger = new StandardLogger( "test" );
+ m_handler = new ServletContextHandler( logger, context );
+ }
+
+ protected ContextHandler getContextHandler()
+ {
+ return m_handler;
+ }
+
+ /**
+ * Test resource base assignment integrity.
+ * @throws Exception if an error occurs during test execution
+ */
+ public void testResourceBase() throws Exception
+ {
+ File file = new File( RESOURCE_BASE );
+ String base = file.getCanonicalFile().toURI().toString();
+ assertEquals( "resourceBase", base, m_handler.getResourceBase() );
+ }
+
+}
+
Added: trunk/main/planet/http/impl/src/test/net/dpml/http/StandardLogger.java
===================================================================
--- trunk/main/planet/http/impl/src/test/net/dpml/http/StandardLogger.java
2006-04-24 11:38:02 UTC (rev 1400)
+++ trunk/main/planet/http/impl/src/test/net/dpml/http/StandardLogger.java
2006-04-24 16:10:56 UTC (rev 1401)
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ *
+ * Licensed 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 net.dpml.http;
+
+import net.dpml.util.Logger;
+import net.dpml.util.DefaultLogger;
+
+/**
+ * Default logging adapter.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+final class StandardLogger implements net.dpml.logging.Logger
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private Logger m_logger;
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ /**
+ * Creation of a new console adapter that is used to redirect transit
events
+ * the system output stream.
+ */
+ public StandardLogger( Logger logger )
+ {
+ m_logger = logger;
+ }
+
+ /**
+ * Creation of a new console adapter that is used to redirect transit
events
+ * the system output stream.
+ */
+ public StandardLogger( String path )
+ {
+ m_logger = new DefaultLogger( path );
+ }
+
+ //
------------------------------------------------------------------------
+ // Adapter
+ //
------------------------------------------------------------------------
+
+ /**
+ * Return TRUE if debug level logging is enabled.
+ * @return the enabled state of debug logging
+ */
+ public boolean isDebugEnabled()
+ {
+ return m_logger.isDebugEnabled();
+ }
+
+ /**
+ * Return TRUE if trace level logging is enabled.
+ * @return the enabled state of trace logging
+ */
+ public boolean isTraceEnabled()
+ {
+ return m_logger.isTraceEnabled();
+ }
+
+ /**
+ * Return TRUE if info level logging is enabled.
+ * @return the enabled state of info logging
+ */
+ public boolean isInfoEnabled()
+ {
+ return m_logger.isInfoEnabled();
+ }
+
+ /**
+ * Return TRUE if error level logging is enabled.
+ * @return the enabled state of error logging
+ */
+ public boolean isWarnEnabled()
+ {
+ return m_logger.isWarnEnabled();
+ }
+
+ /**
+ * Return TRUE if error level logging is enabled.
+ * @return the enabled state of error logging
+ */
+ public boolean isErrorEnabled()
+ {
+ return m_logger.isErrorEnabled();
+ }
+
+ /**
+ * Log a trace message if trace mode is enabled.
+ * @param message the message to log
+ */
+ public void trace( String message )
+ {
+ m_logger.trace( message );
+ }
+
+ /**
+ * Log a trace message if trace mode is enabled.
+ * @param message the message to log
+ */
+ public void debug( String message )
+ {
+ m_logger.debug( message );
+ }
+
+ /**
+ * Log a info level message.
+ * @param message the message to log
+ */
+ public void info( String message )
+ {
+ m_logger.info( message );
+ }
+
+ /**
+ * Record a warning message.
+ * @param message the warning message to record
+ */
+ public void warn( String message )
+ {
+ m_logger.warn( message );
+ }
+
+ /**
+ * Record a warning message.
+ * @param message the warning message to record
+ */
+ public void warn( String message, Throwable cause )
+ {
+ m_logger.warn( message, cause );
+ }
+
+ /**
+ * Log a error message.
+ * @param message the message to log
+ */
+ public void error( String message )
+ {
+ m_logger.error( message );
+ }
+
+ /**
+ * Log a error message.
+ * @param message the message to log
+ * @param cause the causal exception
+ */
+ public void error( String message, Throwable cause )
+ {
+ m_logger.error( message, cause );
+ }
+
+ /**
+ * Return a child logger.
+ * @param category the subsidiary category path
+ * @return the subsidiary logging channel
+ */
+ public net.dpml.logging.Logger getChildLogger( String category )
+ {
+ if( ( null == category ) || ( "".equals( category ) ) )
+ {
+ return this;
+ }
+ else
+ {
+ Logger logger = m_logger.getChildLogger( category );
+ return new StandardLogger( logger );
+ }
+ }
+}
+
- r1401 - in trunk/main/planet/http/impl/src: main/net/dpml/http test/net/dpml/http, mcconnell at BerliOS, 04/24/2006
Archive powered by MHonArc 2.6.24.