cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [75/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main/...
Date Thu, 03 Nov 2005 14:00:48 GMT
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/thread/DefaultThreadPoolTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/thread/DefaultThreadPoolTestCase.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/thread/DefaultThreadPoolTestCase.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/thread/DefaultThreadPoolTestCase.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,149 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * 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 org.apache.cocoon.components.thread;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.easymock.MockControl;
+
+/**
+ * The $classType$ class ...
+ *
+ * @author <a href="mailto:giacomo.at.apache.org">Giacomo Pati</a>
+ * @version $Id$
+ */
+public class DefaultThreadPoolTestCase extends AbstractTestCase
+{
+    //~ Methods ----------------------------------------------------------------
+
+    /**
+     * DOCUMENT ME!
+     */
+    public final void testDefaultThreadPool(  )
+    {
+        final DefaultThreadPool pool = new DefaultThreadPool(  );
+        pool.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ) );
+        pool.setName( "mypool" );
+
+        // We cannot mock the DefaultThreadFactory as the underlying
+        // PooledExecutor of the DefaultThreadPool will again wrapp it into a
+        // PooledExecutor.Worker instance that does some bookeeping.
+        // Using a easymocked DefaultThreadFactory will prevent the
+        // PooledExecutor from shutting down and thus hangs forever.
+        final ThreadFactory threadFactory = new DefaultThreadFactory();
+        threadFactory.setPriority( Thread.MAX_PRIORITY );
+        pool.setThreadFactory( threadFactory );
+        pool.setQueue( 230 );
+        pool.setMaximumPoolSize( 15 );
+        pool.setMinimumPoolSize( 9 );
+        pool.setKeepAliveTime( 11000 );
+        pool.setBlockPolicy( "ABORT" );
+        pool.setShutdownGraceful( false );
+        pool.setShutdownWaitTimeMs( 12345 );
+
+        assertEquals( "block-policy", "ABORT", pool.getBlockPolicy(  ) );
+        assertEquals( "keep-alive-time-ms", 11000L, pool.getKeepAliveTime(  ) );
+        assertEquals( "max-queueu-size", 230, pool.getMaximumQueueSize(  ) );
+        assertEquals( "max-pool-size", 15, pool.getMaximumPoolSize(  ) );
+        assertEquals( "min-pool-size", 9, pool.getMinimumPoolSize(  ) );
+        assertEquals( "name", "mypool", pool.getName(  ) );
+        assertEquals( "priority", Thread.MAX_PRIORITY, pool.getPriority(  ) );
+        assertEquals( "queue-size", 0, pool.getQueueSize(  ) );
+        assertEquals( "isQueued", true, pool.isQueued(  ) );
+        assertEquals( "isTerminatedAfterShutdown", false,
+                      pool.isTerminatedAfterShutdown(  ) );
+        verify(  );
+    }
+
+    /*
+     * Class under test for void execute(Runnable)
+     */
+    public final void testExecuteRunnable(  )
+        throws InterruptedException
+    {
+        final MockControl runnableControl =
+            createStrictControl( Runnable.class );
+        final Runnable runnable = (Runnable)runnableControl.getMock(  );
+        runnable.run(  );
+        runnableControl.replay(  );
+
+        final DefaultThreadPool pool = new DefaultThreadPool(  );
+        pool.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ) );
+        pool.setName( "mypool" );
+        // We cannot mock the DefaultThreadFactory as the underlying
+        // PooledExecutor of the DefaultThreadPool will again wrapp it into a
+        // PooledExecutor.Worker instance that does some bookeeping.
+        // Using a easymocked DefaultThreadFactory will prevent the
+        // PooledExecutor from shutting down and thus hangs forever.
+        pool.setThreadFactory( new DefaultThreadFactory() );
+        pool.setQueue( 230 );
+        pool.setMaximumPoolSize( 15 );
+        pool.setMinimumPoolSize( 9 );
+        pool.setKeepAliveTime( 100 );
+        pool.setBlockPolicy( "ABORT" );
+        pool.setShutdownGraceful( false );
+        pool.setShutdownWaitTimeMs( 1234 );
+        pool.execute( runnable );
+        Thread.yield(  );
+        Thread.sleep( 100 );
+        pool.shutdown();
+        verify(  );
+    }
+
+    /**
+     * DOCUMENT ME!
+     *
+     * @throws InterruptedException DOCUMENT ME!
+     */
+    public final void testShutdown(  )
+    throws InterruptedException
+    {
+        final Runnable runnable = new Runnable(){
+            public void run()
+            {
+                final ConsoleLogger logger = new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG );
+                logger.info( "runnable runs" );
+                try
+                {
+                    Thread.sleep( 1000 );
+                }
+                catch( final InterruptedException ie )
+                {
+                    logger.info( "runnable has been interrupted ");
+                }
+                logger.info( "runnable terminated" );
+            }
+        };
+
+        final DefaultThreadPool pool = new DefaultThreadPool(  );
+        pool.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ) );
+        pool.setName( "mypool" );
+        pool.setThreadFactory( new DefaultThreadFactory() );
+        pool.setQueue( 0 );
+        pool.setMaximumPoolSize( 15 );
+        pool.setMinimumPoolSize( 9 );
+        pool.setKeepAliveTime( 1000 );
+        pool.setBlockPolicy( "ABORT" );
+        pool.setShutdownGraceful( true );
+        pool.setShutdownWaitTimeMs( 100 );
+        pool.execute( runnable );
+        pool.execute( runnable );
+        Thread.yield();
+        Thread.sleep( 200 );
+        pool.shutdown(  );
+        Thread.sleep( 200 );
+        verify(  );
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/thread/DefaultThreadPoolTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,236 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.cocoon.components.treeprocessor.variables;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cocoon.SitemapComponentTestCase;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.environment.mock.MockRequest;
+import org.apache.cocoon.sitemap.PatternException;
+
+/**
+ * Test case for the nested variant of the PreparedVariableResolver
+ *
+ * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
+ * @version CVS $Id: PreparedVariableResolverTestCase.java 55517 2004-10-25 17:54:51Z cziegeler $
+ */
+public class PreparedVariableResolverTestCase extends SitemapComponentTestCase {
+
+    public void testNestedExpressions() throws Exception {
+        String expr = "{request-param:{request-param:foo}}";
+        MockRequest request = getRequest();
+        request.reset();
+        request.addParameter("foo", "bar");
+        request.addParameter("bar", "123");
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+        
+        Map sitemapElements = new HashMap();
+        context.pushMap("sitemap", sitemapElements);
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("123", resolver.resolve(context, getObjectModel()));
+    }
+
+    public void testNestedModuleAndSitemapExpressions() throws Exception {
+        String expr = "{request-param:f{1}}";
+        MockRequest request = getRequest();
+        request.reset();
+        request.addParameter("foo", "123");
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+        
+        Map sitemapElements = new HashMap();
+        sitemapElements.put("1", "oo");
+        context.pushMap("sitemap", sitemapElements);
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("123", resolver.resolve(context, getObjectModel()));
+    }
+    
+    public void testAnchors() throws PatternException {
+        String expr = "{#label:name}";
+        
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+        
+        Map sitemapElements = new HashMap();
+        sitemapElements.put("name", "123");
+        context.pushMap("label", sitemapElements);
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("123", resolver.resolve(context, getObjectModel()));        
+    }
+    
+    public void testSitemapVariables() throws PatternException {
+        String expr = "123{1}";
+        
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements = new HashMap();
+        sitemapElements.put("1", "abc");
+        context.pushMap("label", sitemapElements);
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("123abc", resolver.resolve(context, getObjectModel()));
+    }
+
+    public void testSitemapVariablesWithText() throws PatternException {
+        String expr = "123{1}/def";
+    
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements = new HashMap();
+        sitemapElements.put("1", "abc");
+        context.pushMap("label", sitemapElements);
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("123abc/def", resolver.resolve(context, getObjectModel()));
+    }
+    
+    public void testPrefixedSitemapVariable() throws PatternException {
+        String expr = "123{sitemap:1}/def";
+    
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements = new HashMap();
+        sitemapElements.put("1", "abc");
+        context.pushMap("label", sitemapElements);
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("123abc/def", resolver.resolve(context, getObjectModel()));
+    }
+
+    public void testMultilevelSitemapVariables() throws PatternException {
+        String expr = "from {../1} to {1}";
+        
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements;
+        sitemapElements = new HashMap();
+        sitemapElements.put("1", "juliet");
+        context.pushMap("label1", sitemapElements);
+        
+        sitemapElements = new HashMap();
+        sitemapElements.put("1", "oscar");
+        context.pushMap("label2", sitemapElements);
+
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("from juliet to oscar", resolver.resolve(context, getObjectModel()));
+    }
+
+    public void testRootSitemapVariables() throws PatternException {
+        String expr = "from {/1} to {1}";
+        
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements;
+        sitemapElements = new HashMap();
+        sitemapElements.put("1", "juliet");
+        context.pushMap("label1", sitemapElements);
+        
+        sitemapElements = new HashMap();
+        sitemapElements.put("1", "oscar");
+        context.pushMap("label2", sitemapElements);
+
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("from juliet to oscar", resolver.resolve(context, getObjectModel()));
+    }
+    
+    public void testColonInTextContent() throws PatternException {
+        String expr = "http://cocoon.apache.org";
+        
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements;
+        sitemapElements = new HashMap();
+        context.pushMap("label", sitemapElements);
+        
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("http://cocoon.apache.org", resolver.resolve(context, getObjectModel()));
+    }
+    
+    public void testColonBeginningTextContent() throws PatternException {
+        String expr = ":colon-starts-this";
+        
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements;
+        sitemapElements = new HashMap();
+        context.pushMap("label", sitemapElements);
+        
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals(":colon-starts-this", resolver.resolve(context, getObjectModel()));
+    }
+    
+    public void testEmbeddedColon() throws PatternException {
+        String expr = "{1}:{1}";
+        
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements;
+        sitemapElements = new HashMap();
+        sitemapElements.put("1", "abc");
+        context.pushMap("label", sitemapElements);
+        
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("abc:abc", resolver.resolve(context, getObjectModel()));
+    }
+
+    public void testEscapedBraces() throws PatternException {
+        String expr = "This is a \\{brace\\}";
+        
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+
+        Map sitemapElements;
+        sitemapElements = new HashMap();
+        context.pushMap("label", sitemapElements);
+
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("This is a {brace}", resolver.resolve(context, getObjectModel()));
+    }
+
+    public void testModuleWithoutOption() throws PatternException {
+        String expr = "{baselink:}";
+        InvokeContext context = new InvokeContext(true);
+        context.enableLogging(getLogger());
+        
+        Map sitemapElements = new HashMap();
+        context.pushMap("sitemap", sitemapElements);
+        PreparedVariableResolver resolver = new PreparedVariableResolver(expr, getManager());
+        assertEquals("", resolver.resolve(context, getObjectModel()));
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.CocoonTestCase#addSourceFactories()
+     */
+    protected boolean addSourceFactories() {
+        return false;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.CocoonTestCase#addSourceResolver()
+     */
+    protected boolean addSourceResolver() {
+        return false;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest Thu Nov  3 05:41:06 2005
@@ -0,0 +1,31 @@
+<?xml version="1.0" ?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  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.
+-->
+<testcase>
+ <roles>
+  <role name="org.apache.cocoon.components.modules.input.InputModuleSelector"
+        shorthand="input-modules"
+        default-class="org.apache.cocoon.core.container.StandaloneServiceSelector"/>
+ </roles>
+
+ <components>
+   <input-modules>
+       <component-instance class="org.apache.cocoon.components.modules.input.RequestParameterModule" logger="core.modules.input" name="request-param"/>
+       <component-instance class="org.apache.cocoon.components.modules.input.BaseLinkModule" logger="core.modules.input" name="baselink"/>
+   </input-modules>
+ </components>
+
+</testcase>

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,391 @@
+/* 
+ * Copyright 2002-2004 The Apache Software Foundation
+ * 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 org.apache.cocoon.core.container;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.core.Core;
+import org.apache.cocoon.core.MutableSettings;
+
+/**
+ * JUnit TestCase for Cocoon Components.
+ * <p>
+ *   This class extends the JUnit TestCase class to setup an environment which
+ *   makes it possible to easily test Cocoon Components. The following methods
+ *   and instance variables are exposed for convenience testing:
+ * </p>
+ * <dl>
+ *   <dt>getManager()</dt>
+ *   <dd>
+ *     This instance variable contains an initialized service manager which
+ *     can be used to lookup components configured in the test configuration
+ *     file. (see below)
+ *   </dd>
+ *   <dt>getLogger()</dt>
+ *   <dd>
+ *     This method returns a logger for this test case. By default this
+ *     logger logs with log level DEBUG.
+ *   </dd>
+ * </dl>
+ * <p>
+ *   The following test case configuration can be used as a basis for new tests.
+ *   Detailed explanations of the configuration elements can be found after
+ *   the example. 
+ * </p>
+ * <pre>
+ *   &lt;testcase&gt;
+ *     &lt;context&gt;
+ *       &lt;entry name="foo" value="bar"/&gt;
+ *       &lt;entry name="baz" class="my.context.Class"/&gt;
+ *     &lt;/context&gt;
+ *
+ *     &lt;roles&gt;
+ *       &lt;role name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
+ *             shorthand="datasources"
+ *             default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"&gt;
+ *          &lt;hint shorthand="jdbc" class="org.apache.avalon.excalibur.datasource.JdbcDataSource"/&gt;
+ *       &lt;/role&gt;
+ *     &lt;/roles&gt;
+ *
+ *     &lt;components&gt;
+ *       &lt;datasources&gt;
+ *         &lt;jdbc name="personell"&gt;
+ *           &lt;pool-controller min="5" max="10"/&gt;
+ *           &lt;jdbc name="personnel"/&gt;
+ *           &lt;dburl&gt;jdbc:odbc:test&lt;/dburl&gt;
+ *           &lt;user&gt;test&lt;/user&gt;
+ *           &lt;password&gt;test&lt;/password&gt;
+ *           &lt;driver&gt;sun.jdbc.odbc.JdbcOdbcDriver&lt;/driver&gt;
+ *         &lt;/jdbc&gt;
+ *       &lt;/datasources&gt;
+ *     &lt;/components&gt;
+ *   &lt;/testcase&gt;
+ * </pre>
+ * <p>
+ * Element Explanation:
+ * <dl>
+ * <dt>testcase</dt>
+ * <dd>Defines a test case configuration.  Must contain one each of the
+ *  following elements: 
+ *  <code>context</code>, <code>roles</code>, and <code>components</code>
+ *  </dd>.
+ *
+ * <dt>context</dt>
+ * <dd>Allows context properties to be set in the context passed to any
+ *  Contextualizable components.</dd>
+ *
+ * <dt>roles</dt>
+ * <dd>Roles configuration for the components configured in the
+ *  <code>components</code> element.  
+ * </dd>
+ *
+ * <dt>components</dt>
+ * <dd>Used to configure any Components used by the test cases.  
+ * </dd>
+ *
+ * </dl>
+ *
+ * @version $Id: ContainerTestCase.java 225167 2005-07-25 19:24:01Z cziegeler $
+ */
+public class ContainerTestCase extends TestCase {
+    
+    /** The default logger */
+    private Logger logger;
+    
+    /** The service manager to use */
+    private ServiceManager manager;
+
+    /** The context */
+    private Context context;
+    
+    /** Return the logger */
+    protected Logger getLogger() {
+        return logger;
+    }
+
+    /** Return the service manager */
+    protected ServiceManager getManager() {
+        return this.manager;
+    }
+    
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        String level = System.getProperty("junit.test.loglevel", "" + ConsoleLogger.LEVEL_WARN);
+        this.logger = new ConsoleLogger(Integer.parseInt(level));
+        this.prepare();
+    }
+    
+    /**
+     * Initializes the ComponentLocator
+     *
+     * The configuration file is determined by the class name plus .xtest appended,
+     * all '.' replaced by '/' and loaded as a resource via classpath
+     */
+    protected void prepare()
+    throws Exception {
+        final String resourceName = getClass().getName().replace( '.', '/' ) + ".xtest";
+        URL resource = getClass().getClassLoader().getResource( resourceName );
+
+        if( resource != null ) {
+            getLogger().debug( "Loading resource " + resourceName );
+            this.prepare( resource.openStream() );
+        } else {
+            getLogger().debug( "Resource not found " + resourceName );
+            this.prepare( null );
+        }
+    }
+
+    /**
+     * Initializes the ComponentLocator
+     *
+     * @param testconf The configuration file is passed as a <code>InputStream</code>
+     *
+     * A common way to supply a InputStream is to overwrite the initialize() method
+     * in the sub class, do there whatever is needed to get the right InputStream object
+     * supplying a conformant xtest configuartion and pass it to this initialize method.
+     * the mentioned initialize method is also the place to set a different logging priority
+     * to the member variable m_logPriority.
+     */
+    protected final void prepare( final InputStream testconf )
+    throws Exception {
+        if ( getLogger().isDebugEnabled() ) {
+            getLogger().debug( "Initializing " + this.getName() );
+        }
+
+        final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+        final Configuration conf;
+        if ( testconf != null ) {
+            conf = builder.build( testconf );
+        } else {
+            conf = new DefaultConfiguration("", "-");
+        }
+
+        this.prepare( conf.getChild( "context" ),
+                      conf.getChild( "roles" ),
+                      conf.getChild( "components" ) );
+    }
+
+    /**
+     * Initializes the ComponentLocator
+     *
+     * @param context The configuration object for the context
+     * @param roles The configuration object for the roles
+     * @param components The configuration object for the components
+     *
+     * More detailed control over configuration can be achieved by
+     * overriding <code>prepare()</code>, construct the configuration
+     *  objects and call this method.
+     */
+    protected final void prepare( final Configuration context,
+                                  final Configuration roles,
+                                  final Configuration components )
+    throws Exception {
+        this.context = this.setupContext( context );
+
+        this.setupManagers( components, roles );
+    }
+
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        this.done();
+        super.tearDown();
+    }
+
+    /**
+     * Disposes the <code>ComponentLocator</code>
+     */
+    final private void done() {
+        if( manager != null ) {
+            ContainerUtil.dispose(manager);
+            manager = null;
+        }
+    }
+
+    /**
+     * set up a context according to the xtest configuration specifications context
+     * element.
+     *
+     * A method addContext(DefaultContext context) is called here to enable subclasses
+     * to put additional objects into the context programmatically.
+     */
+    final private Context setupContext( final Configuration conf )
+    throws Exception {
+        final DefaultContext context = new DefaultContext();
+        final Configuration[] confs = conf.getChildren( "entry" );
+        for( int i = 0; i < confs.length; i++ ) {
+            final String key = confs[ i ].getAttribute( "name" );
+            final String value = confs[ i ].getAttribute( "value", null );
+            if( value == null ) {
+                String clazz = confs[ i ].getAttribute( "class" );
+                Object obj = getClass().getClassLoader().loadClass( clazz ).newInstance();
+                context.put( key, obj );
+                if( getLogger().isInfoEnabled() ) {
+                    getLogger().info( "ContainerTestCase: added an instance of class " + clazz + " to context entry " + key );
+                }
+            } else {
+                context.put( key, value );
+                if( getLogger().isInfoEnabled() ) {
+                    getLogger().info( "ContainerTestCase: added value \"" + value + "\" to context entry " + key );
+                }
+            }
+        }
+        this.addContext( context );
+        return context ;
+    }
+
+    /**
+     * This method may be overwritten by subclasses to put additional objects
+     * into the context programmatically.
+     */
+    protected void addContext( DefaultContext context ) {
+        // nothing to add here
+    }
+
+    /**
+     * This method may be overwritten by subclasses to add aditional
+     * components.
+     */
+    protected void addComponents( CoreServiceManager manager) 
+    throws ServiceException, ConfigurationException {
+        // subclasses can add components here
+    }
+    
+    final private void setupManagers( final Configuration confCM,
+                                      final Configuration confRM)
+    throws Exception {
+        // Setup the RoleManager
+        RoleManager roleManager = new RoleManager();
+        roleManager.enableLogging( this.getLogger() );
+        roleManager.configure( confRM );
+
+        // Set up root manager for Core
+        Core core = new Core(new MutableSettings(), this.context);
+        ((DefaultContext)this.context).put(Core.ROLE, core);
+        SingleComponentServiceManager rsm = new SingleComponentServiceManager(null, core, Core.ROLE);
+ 
+        // Set up the ComponentLocator
+        CoreServiceManager ecManager = new CoreServiceManager(rsm);
+        ecManager.enableLogging( this.getLogger() );
+        ecManager.contextualize( this.context );
+        ecManager.setRoleManager( roleManager );
+        ecManager.setLoggerManager( new DefaultLoggerManager(this.logger));
+        ecManager.configure( confCM );
+        this.addComponents( ecManager );
+        ecManager.initialize();
+        this.manager = ecManager;
+    }
+
+    protected final Object lookup( final String key )
+    throws ServiceException {
+        return manager.lookup( key );
+    }
+
+    protected final void release( final Object object ) {
+        manager.release( object );
+    }
+    
+    private Object getComponent(String classname,
+                                Configuration conf,
+                                Parameters p) 
+    throws Exception {
+        final Object instance = Class.forName(classname).newInstance();
+        ContainerUtil.enableLogging(instance, getLogger());
+        ContainerUtil.contextualize(instance, this.context);
+        ContainerUtil.service(instance, getManager());
+        if ( instance instanceof Configurable ) {
+            // default configuration to invoke method!
+            if ( conf == null ) {
+                conf = new DefaultConfiguration("", "-");
+            }
+            ContainerUtil.configure(instance, conf);
+        }
+        if ( instance instanceof Parameterizable ) {
+            // default configuration to invoke method!
+            if ( p == null ) {
+                p = new Parameters();
+            }
+            ContainerUtil.parameterize(instance, p);                       
+        }
+        ContainerUtil.initialize(instance);
+        return instance;
+    }
+    
+    protected Object getComponent(String classname,
+                                  Configuration conf) 
+    throws Exception {
+        return this.getComponent(classname, conf, null);
+    }
+
+    protected Object getComponent(String classname,
+                                  Parameters p) 
+    throws Exception {
+        return this.getComponent(classname, null, p);
+    }
+    
+    protected Object getComponent(String classname) 
+    throws Exception {
+        return this.getComponent(classname, null, null);
+    }
+
+    /**
+     * We use this simple logger manager that sends all output to the console (logger)
+     */
+    protected static class DefaultLoggerManager implements LoggerManager {
+        
+        private Logger logger;
+        
+        public DefaultLoggerManager(Logger logger) {
+            this.logger = logger;
+        }
+        /* (non-Javadoc)
+         * @see org.apache.avalon.excalibur.logger.LoggerManager#getDefaultLogger()
+         */
+        public Logger getDefaultLogger() {
+            return this.logger;
+        }
+        /* (non-Javadoc)
+         * @see org.apache.avalon.excalibur.logger.LoggerManager#getLoggerForCategory(java.lang.String)
+         */
+        public Logger getLoggerForCategory(String arg0) {
+            return this.logger;
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/ContainerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/RoleManagerTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/RoleManagerTestCase.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/RoleManagerTestCase.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/RoleManagerTestCase.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,79 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.cocoon.core.container;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.components.ComponentInfo;
+import org.apache.cocoon.core.container.RoleManager;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+
+/**
+ * Test cases for {@link RoleManager}.
+ * 
+ * @version CVS $Id: RoleManagerTestCase.java 312861 2005-10-11 11:46:08Z cziegeler $
+ */
+public class RoleManagerTestCase extends MockObjectTestCase {
+    
+    /**
+     * Constructor for RoleManagerTestCase.
+     * @param name The test name
+     */
+    public RoleManagerTestCase(String name) {
+        super(name);
+    }
+
+    public void testConfigureWithoutHints() throws ConfigurationException {
+        Mock conf = new Mock(Configuration.class);
+        Mock child0 = new Mock(Configuration.class);
+        Configuration roles[] = new Configuration[1];
+        roles[0] = (Configuration) child0.proxy();
+        Configuration hints[] = new Configuration[0];
+        conf.expects(once()).method("getName").will(returnValue("roles-list"));
+        conf.expects(once()).method("getChildren").will(returnValue(roles));
+        child0.expects(once()).method("getName").will(returnValue("role"));
+        child0.expects(once()).method("getAttribute").with(eq("name"))
+                .will(returnValue("testName"));
+        child0.expects(once()).method("getAttribute").with(eq("shorthand"), eq(null))
+                .will(returnValue("testShorthand"));
+        child0.expects(once()).method("getAttribute").with(eq("default-class"), eq(null))
+                .will(returnValue("testClass"));
+        child0.expects(once()).method("getAttribute").with(eq("model"), eq(null))
+                .will(returnValue(ComponentInfo.TYPE_SINGLETON));
+        child0.expects(once()).method("getAttribute").with(eq("init"), eq(null))
+                .will(returnValue(null));
+        child0.expects(once()).method("getAttribute").with(eq("destroy"), eq(null))
+        .will(returnValue(null));
+        child0.expects(once()).method("getAttribute").with(eq("logger"), eq(null))
+                .will(returnValue(null));
+        child0.expects(once()).method("getChildren").with(eq("hint"))
+                .will(returnValue(hints));
+        Mock logger = new Mock(Logger.class);
+        logger.expects(this.atLeastOnce()).method("isDebugEnabled").will(returnValue(false));
+        RoleManager rm = new RoleManager(null);
+        rm.enableLogging((Logger) logger.proxy());
+        rm.configure((Configuration) conf.proxy());
+        conf.verify();
+        child0.verify();
+        assertEquals("Role name for shorthand incorrect", "testName", rm.getRoleForName("testShorthand"));
+        assertEquals("Default service info for role incorrect", "testClass", rm.getDefaultServiceInfoForRole("testName").getServiceClassName());
+        assertNull("Default service info for key must be null", rm.getDefaultServiceInfoForKey("testName", "testShorthand"));
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/RoleManagerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,41 @@
+/* 
+ * Copyright 2002-2004 The Apache Software Foundation
+ * 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 org.apache.cocoon.core.container.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for the {@link PropertyHelper} class.
+ *
+ * @version CVS $Id: AbstractComponentHandler.java 123887 2005-01-02 15:12:01Z sylvain $
+ */
+public class PropertyHelperTestCase extends TestCase {
+
+    public void testReplace() {
+        final String testA = "a simple string";
+        final String testB = "a simple string with a start token ${ somewhere";
+        final String testC = "and this is the } end token";
+        final String testD = "${this.does.not.exists}";
+        // some tests for not! replacing
+        assertEquals(PropertyHelper.replace(testA, null), testA);
+        assertEquals(PropertyHelper.replace(testB, null), testB);
+        assertEquals(PropertyHelper.replace(testC, null), testC);
+        assertEquals(PropertyHelper.replace(testD, null), testD);
+        // and finally we have something to replace
+        assertEquals(PropertyHelper.replace("${java.home}", null), System.getProperty("java.home"));
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/core/container/util/PropertyHelperTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,160 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * 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 org.apache.cocoon.environment.commandline.test;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+
+import org.apache.cocoon.environment.commandline.CommandLineContext;
+
+import junit.framework.TestCase;
+import junit.swingui.TestRunner;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * A simple test case for CommandLineContext.
+ *
+ * @author <a href="mailto:berni_huber@a1.net">Bernhard Huber</a>
+ * @version CVS $Id: CommandLineContextTestCase.java 55858 2004-10-28 14:34:55Z vgritsenko $
+ */
+public final class CommandLineContextTestCase extends TestCase {
+
+    private String commandLineContextDir;
+    private CommandLineContext commandLineContext;
+
+
+    /**
+     * Constructor for the CommandLineContextTestCase object
+     */
+    public CommandLineContextTestCase() {
+        this("CommandLineContextTestCase");
+    }
+
+    /**
+     * Constructor for the CommandLineContextTestCase object
+     */
+    public CommandLineContextTestCase(String name) {
+        super(name);
+    }
+
+    /**
+     * The main program for the CommandLineContextTestCase class
+     *
+     * @param  args           The command line arguments
+     */
+    public static void main(final String[] args) throws Exception {
+        final String[] testCaseName = {CommandLineContextTestCase.class.getName()};
+        TestRunner.main(testCaseName);
+    }
+
+
+    /**
+     * The JUnit setup method
+     */
+    public void setUp() throws Exception {
+        commandLineContextDir = System.getProperty("java.io.tmpdir", "/tmp");
+        new File(commandLineContextDir, "foo" + File.separator + "bar").mkdirs();
+
+        String level = System.getProperty("junit.test.loglevel", "" + ConsoleLogger.LEVEL_DEBUG);
+        Logger logger = new ConsoleLogger(Integer.parseInt(level));
+
+        commandLineContext = new CommandLineContext(commandLineContextDir);
+        commandLineContext.enableLogging(logger);
+    }
+
+    /**
+     * The teardown method for JUnit
+     */
+    public void tearDown() throws Exception {
+        new File(commandLineContextDir, "foo" + File.separator + "bar").delete();
+        new File(commandLineContextDir, "foo").delete();
+    }
+
+    /**
+     * A unit test for <code>getResource()</code>
+     */
+    public void testGetResource() throws Exception {
+        Object[] test_values = {
+                new String[]{"", commandLineContextDir},
+                new String[]{"/", commandLineContextDir},
+                new String[]{"foo", commandLineContextDir + File.separator + "foo"},
+                new String[]{"foo/bar", commandLineContextDir + File.separator + "foo/bar"},
+                new String[]{"foo/bar/nonexistent", null}
+                };
+        for (int i = 0; i < test_values.length; i++) {
+            String tests[] = (String[]) test_values[i];
+            String test = tests[0];
+            URL result = commandLineContext.getResource(test);
+            URL expected = null;
+            if (result != null) {
+                expected = new File(tests[1]).toURL();
+            }
+            String message = "Test " + "'" + test + "'";
+            assertEquals(message, expected, result);
+        }
+    }
+
+    /**
+     * A unit test for <code>getRealPath()</code>
+     */
+    public void testGetRealPath() throws Exception {
+        Object[] test_values = {
+                new String[]{"", ""},
+                new String[]{"/", "/"},
+                new String[]{"foo", "foo"},
+                new String[]{"foo/bar", "foo/bar"}
+                };
+        for (int i = 0; i < test_values.length; i++) {
+            String tests[] = (String[]) test_values[i];
+            String test = tests[0];
+            File expected_file = new File(commandLineContextDir, tests[1]);
+            String expected = expected_file.getAbsolutePath();
+
+            String result = commandLineContext.getRealPath(test);
+            String message = "Test " +
+                    "'" + test + "'";
+            assertEquals(message, expected, result);
+        }
+    }
+
+    /**
+     * A unit test for <code>getAttribute</code>,
+     * <code>setAttribute</code>, and <code>removeAttribute()</code>
+     */
+    public void testAttributes() throws Exception {
+        Object[] test_values = {
+                new String[]{"a", "b"},
+                new String[]{"foo", "foo"},
+                new String[]{"foo/bar", "foo/bar"}
+                };
+        for (int i = 0; i < test_values.length; i++) {
+            String tests[] = (String[]) test_values[i];
+            String name = tests[0];
+            String expected = tests[1];
+
+            commandLineContext.setAttribute(name, expected);
+
+            String result = (String) commandLineContext.getAttribute(name);
+            assertEquals("Test " + "'" + "n" + "'", expected, result);
+
+            commandLineContext.removeAttribute(name);
+            result = (String) commandLineContext.getAttribute(name);
+            assertEquals("Test " + "'" + "<null>" + "'", null, result);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/package.html
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/package.html?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/package.html (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/package.html Thu Nov  3 05:41:06 2005
@@ -0,0 +1,28 @@
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  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.
+-->
+<html>
+<head>
+  <title>Search</title>
+</head>
+<body>
+  <h1>Test Cases Environment Commandline</h1>
+  <p>
+    This package provides Cocoon environment commandline test cases.
+  </p>
+  <p>
+    For more information @see org.apache.cocoon.environment.commandline
+  </p>
+</body>

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/commandline/test/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,83 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.cocoon.environment.mock;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.io.InputStream;
+
+import org.apache.cocoon.environment.impl.AbstractContext;
+
+public class MockContext extends AbstractContext {
+
+    private Hashtable attributes = new Hashtable();
+    private Hashtable resources = new Hashtable();
+    private Hashtable mappings = new Hashtable();
+    private Hashtable initparameters = new Hashtable();
+
+    public Object getAttribute(String name) {
+        return attributes.get(name);
+    }
+
+    public void setAttribute(String name, Object value) {
+        attributes.put(name, value);
+    }
+
+    public void removeAttribute(String name) {
+        attributes.remove(name);
+    }
+
+    public Enumeration getAttributeNames() {
+        return attributes.keys();
+    }
+
+    public void setResource(String path, URL url) {
+        resources.put(path, url);
+    }
+
+    public URL getResource(String path) throws MalformedURLException {
+        return (URL)resources.get(path);
+    }
+
+    public String getRealPath(String path) {
+      return path;
+    }
+
+    public String getMimeType(String file) {
+        return (String)mappings.get(file.substring(file.lastIndexOf(".")+1)); 
+    }
+
+    public void setInitParameter(String name, String value) {
+        initparameters.put(name, value);
+    }
+
+    public String getInitParameter(String name) {
+        return (String)initparameters.get(name);
+    }
+
+    public InputStream getResourceAsStream(String path) {
+        return null;
+    }
+
+    public void reset() {
+        attributes.clear();
+        resources.clear();
+        mappings.clear();
+        initparameters.clear();
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockCookie.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockCookie.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockCookie.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockCookie.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.cocoon.environment.mock;
+
+import org.apache.cocoon.environment.Cookie;
+
+public class MockCookie implements Cookie {
+
+    private String comment;
+    private String domain;
+    private int maxage;
+    private String path;
+    private boolean secure;
+    private String name;
+    private String value;
+    private int version; 
+
+    public void setComment(String comment) {
+        this.comment = comment;
+    }
+
+    public String getComment() {
+        return comment;
+    }
+
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+
+    public String getDomain() {
+        return domain;
+    }
+
+    public void setMaxAge(int maxage) {
+        this.maxage = maxage;
+    }
+
+    public int getMaxAge() {
+        return maxage;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setSecure(boolean secure) {
+        this.secure = secure;
+    }
+
+    public boolean getSecure() {
+        return secure;
+    }
+
+    public void setName(String name) {
+        this.name= name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}
+

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockCookie.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockEnvironment.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockEnvironment.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockEnvironment.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,163 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.cocoon.environment.mock;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Map;
+import junit.framework.AssertionFailedError;
+import org.apache.cocoon.environment.Environment;
+
+public class MockEnvironment implements Environment {
+
+    private String uri;
+    private String uriprefix;
+    private String view;
+    private String action;
+    private String contenttype;
+    private int contentlength;
+    private int status;
+    private ByteArrayOutputStream outputstream;
+    private Map objectmodel;
+    private Hashtable attributes = new Hashtable();
+
+    public MockEnvironment() {
+        // empty constructor
+    }
+
+    public String getURI() {
+        return uri;
+    }
+
+    public String getURIPrefix() {
+        return uriprefix;
+    }
+
+    public String getView() {
+        return view;
+    }
+
+    public String getAction() {
+        return action;
+    }
+
+    public void setURI(String prefix, String uri) {
+        this.uriprefix = prefix;
+        this.uri = uri;
+    }
+
+    public void redirect(String url, boolean global, boolean permanent) throws IOException {
+        throw new AssertionFailedError("Use Redirector.redirect instead!");
+    }
+
+    public void setContentType(String contenttype) {
+        this.contenttype = contenttype;
+    }
+
+    public String getContentType() {
+        return contenttype;
+    }
+
+    public void setContentLength(int length) {
+        this.contentlength = length;
+    }
+
+    public int getContentLength() {
+        return contentlength;
+    }
+
+    public void setStatus(int statusCode) {
+        this.status = statusCode;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public OutputStream getOutputStream(int bufferSize) throws IOException {
+        outputstream = new ByteArrayOutputStream();
+        return outputstream;
+    }
+
+    public byte[] getOutput() {
+        return outputstream.toByteArray();
+    }
+
+    public Map getObjectModel() {
+        return objectmodel;
+    }
+
+    public void setObjectModel(Map objectmodel) {
+        this.objectmodel = objectmodel;
+    }
+
+    public boolean isResponseModified(long lastModified) {
+        return true;
+    }
+
+    public void setResponseIsNotModified() {
+        // nothing to do
+    }
+
+    public void setAttribute(String name, Object value) {
+        attributes.put(name, value);
+    }
+
+    public Object getAttribute(String name) {
+        return attributes.get(name);
+    }
+
+    public void removeAttribute(String name) {
+        attributes.remove(name);
+    }
+
+    public Enumeration getAttributeNames() {
+        return attributes.keys();
+    }
+
+    public boolean tryResetResponse() throws IOException {
+        return false;
+    }
+
+    public void commitResponse() throws IOException {
+        // do nothing
+    }
+    
+    public void startingProcessing() {
+        // do nothing
+    }
+    
+    public void finishingProcessing() {
+        // do nothing
+    }
+
+    /**
+     * Always return <code>true</code>.
+     */
+    public boolean isExternal() {
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Environment#isInternalRedirect()
+     */
+    public boolean isInternalRedirect() {
+        return false;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockEnvironment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRedirector.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRedirector.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRedirector.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRedirector.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.cocoon.environment.mock;
+
+import org.apache.cocoon.ProcessingException;
+import java.io.IOException;
+
+import org.apache.cocoon.environment.Redirector;
+
+public class MockRedirector implements Redirector {
+
+    protected boolean hasRedirected = false;
+
+    private String redirect;
+
+    public void redirect(boolean sessionmode, String url) throws IOException, ProcessingException {
+        this.hasRedirected = true;
+
+        redirect = url;
+    }
+  
+    public void globalRedirect(boolean sessionmode, String url) throws IOException, ProcessingException {
+        redirect(sessionmode, url);
+    }
+
+    public String getRedirect() {
+        return redirect;
+    }
+    
+    public boolean hasRedirected() {
+        return this.hasRedirected;
+    }
+
+    public void reset() {
+        redirect = null;
+        hasRedirected = false;
+    }
+    
+    public void sendStatus(int sc) {
+        hasRedirected = true;
+    }
+}
+

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRedirector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRequest.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRequest.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRequest.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRequest.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,475 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * 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 org.apache.cocoon.environment.mock;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.Principal;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Vector;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+
+import junit.framework.AssertionFailedError;
+
+import org.apache.cocoon.environment.Cookie;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.impl.AbstractRequest;
+
+/**
+ * @version $Id: MockRequest.java 202268 2005-06-28 19:03:15Z vgritsenko $
+ */
+public class MockRequest extends AbstractRequest {
+    
+    private Hashtable attributes = new Hashtable();
+    private Hashtable globalAttributes = new Hashtable();
+    private String scheme;
+    private String protocol = "HTTP/1.1";
+    private String requestURI;
+    private String contextPath = "";
+    private String servletPath;
+    private String pathInfo;
+    private String queryString;
+    private String method = "GET";
+    private String contentType;
+    private Locale locale = Locale.US;
+    private Principal principal;
+    private String remoteAddr;
+    private String remoteHost;
+    private String remoteUser;
+    private String userRole;
+    private String reqSessionId;
+    private String authType;
+    private String charEncoding;
+    private String serverName;
+    private int port = 80;
+    private InputStream inputStream;
+    
+    private Hashtable parameters = new Hashtable();
+    private Hashtable headers = new Hashtable();
+    private Map cookies = new HashMap();
+    
+    private MockSession session;
+    private Environment environment = null;
+    
+    private boolean isRequestedSessionIdFromCookie = true;
+    private boolean isRequestedSessionIdFromURL = false;
+
+    // Needed to get getSitemapURI and getSitemapPath right
+    public void setEnvironment(Environment environment) {
+        this.environment = environment;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#get(java.lang.String)
+     */
+    public Object get(String name) { 
+        String[] values = this.getParameterValues(name);
+        if (values == null || values.length == 0) {
+            return null;
+        } else if (values.length == 1) {
+            return values[0];
+        } else {
+            Vector vect = new Vector(values.length);
+            for (int i = 0; i < values.length; i++) {
+                vect.add(values[i]);
+            }
+            return vect;
+        }
+    }
+    
+    public String getAuthType() {
+        return authType;
+    }
+    
+    public String getCharacterEncoding() {
+        return charEncoding;
+    }
+
+    public void setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException {
+        charEncoding = enc;
+    }
+
+    public int getContentLength() {
+        return -1;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public String getParameter(String name) {
+        return (String)parameters.get(name);
+    }
+
+    public Enumeration getParameterNames() {
+        return parameters.keys();
+    }
+
+    public String[] getParameterValues(String name) {
+        Object param = parameters.get(name);
+        if ( null == param ) {
+            return null;
+        }
+        if (param.getClass().isArray()) {
+            return (String[]) param;
+        }
+        return new String[] {(String) param};
+    }
+
+    public void addParameter(String name, String value) {
+        parameters.put(name, value);
+    }
+
+    public String getProtocol() {
+        return protocol;
+    }
+
+    public String getScheme() {
+        return scheme;
+    }
+
+    public String getServerName() {
+        return serverName;
+    }
+
+    public int getServerPort() {
+        return port;
+    }
+    
+    public String getRemoteAddr() {
+        return remoteAddr;
+    }
+    
+    public String getRemoteHost() {
+        return remoteHost;
+    }
+    
+    public Locale getLocale() {
+        return locale;
+    }
+    
+    public Enumeration getLocales() {
+        return Collections.enumeration(Collections.singleton(getLocale()));
+    }
+    
+    public boolean isSecure() {
+        if (scheme==null) {
+            return false;
+        }
+        return scheme.equalsIgnoreCase("HTTPS");
+    }
+    
+    public Cookie[] getCookies() {
+        if (cookies.isEmpty()) {
+            return null;
+        }
+        Cookie[] cookieArray = new Cookie[cookies.size()];
+        return (Cookie []) cookies.values().toArray(cookieArray);
+    }
+
+    public Map getCookieMap() {
+        return cookies;
+    }
+
+    public long getDateHeader(String name) {
+        String s1 = getHeader(name);
+        if (s1 == null) {
+            return -1L;
+        }
+        try {
+            DateFormat dateFormat = new SimpleDateFormat();
+            return dateFormat.parse(s1).getTime();
+        }
+        catch(ParseException exception) {
+            throw new IllegalArgumentException("Cannot parse date: " + s1);
+        }
+    }
+
+    public String getHeader(String name) {
+        return (String) headers.get(name);
+    }
+
+    public Enumeration getHeaders(String name) {
+        throw new AssertionFailedError("Not implemented");
+    }
+    
+    public Enumeration getHeaderNames() {
+        return headers.keys();
+    }
+    
+    public String getMethod() {
+        return method;
+    }
+    
+    public String getPathInfo() {
+        return pathInfo;
+    }
+    
+    public String getPathTranslated() {
+        throw new AssertionFailedError("Not implemented");
+    }
+    
+    public String getContextPath() {
+        return contextPath;
+    }
+    
+    public void setContextPath(String path) {
+        contextPath = path;
+    }
+    
+    public String getQueryString() {
+        return queryString;
+    }
+    
+    public void setQueryString(String string) {
+        queryString = string;
+    }
+    
+    public String getRemoteUser() {
+        return remoteUser;
+    }
+    
+    public Principal getUserPrincipal() {
+        return principal;
+    }
+    
+    public boolean isUserInRole(String role) {
+        return userRole.equals(role);
+    }
+    
+    public String getRequestedSessionId() {
+        return reqSessionId;
+    }
+    
+    public String getRequestURI() {
+        if (this.environment == null) {
+            return requestURI;
+        }
+        return this.environment.getURI();
+    }
+    
+    public void setRequestURI(String uri) {
+        requestURI = uri;
+    }
+    
+    public String getSitemapURI() {
+        if (this.environment == null) {
+            return requestURI;
+        }
+        return this.environment.getURI();
+    }
+    
+    public String getSitemapPath() {
+        if (this.environment == null) {
+            return "";
+        }
+        return this.environment.getURIPrefix();
+    }
+
+    public String getSitemapURIPrefix() {
+        return "";
+    }
+
+    public String getServletPath() {
+        return servletPath;
+    }
+
+    public Session getSession(boolean create) {
+        if ((session == null) && (create)) {
+            this.session = new MockSession();
+        } else if ((session != null) && (!(session).isValid()) && (create)) {
+            this.session = new MockSession();
+        }
+        if ((session != null) && ((session).isValid())) {
+            return this.session;
+        }
+        return null;
+    }
+
+    public Session getSession() {
+        return getSession(true);
+    }
+
+    public boolean isRequestedSessionIdValid() {
+        if (session != null) {
+            try {
+                session.getId();
+                return true;
+            } catch (IllegalStateException e) {
+                return false;
+            }
+        }
+        return false;
+    }
+
+    public boolean isRequestedSessionIdFromCookie() {
+        return isRequestedSessionIdFromCookie;
+    }
+
+    public boolean isRequestedSessionIdFromURL() {
+        return isRequestedSessionIdFromURL;
+    }
+
+    public void reset() {
+        attributes.clear();
+        globalAttributes.clear();
+        scheme = null;
+        protocol = "HTTP/1.1";
+        requestURI = null;
+        contextPath = null;
+        servletPath = null;
+        pathInfo = null;
+        queryString = null;
+        method = "GET";
+        contentType = null;
+        locale = Locale.US;
+        principal = null;
+        remoteAddr = null;
+        remoteHost = null;
+        remoteUser = null;
+        userRole = null;
+        reqSessionId = null;
+        authType = null;
+        charEncoding = null;
+        serverName = null;
+        port = 80;
+        
+        parameters.clear();
+        headers.clear();
+    }
+
+    public void setHeader( String key, String value ) {
+        this.headers.put(key, value );
+    }
+
+    public void setMethod( String method ) {
+        this.method = method;
+    }
+
+    public void clearSession() {
+        this.session = null;
+    }
+
+    public void setIsRequestedSessionIdFromURL( boolean isRequestedSessionIdFromURL ) {
+        this.isRequestedSessionIdFromURL = isRequestedSessionIdFromURL;
+    }
+    
+    public void setIsRequestedSessionIdFromCooki( boolean isRequestedSessionIdFromCookie ) {
+        this.isRequestedSessionIdFromCookie = isRequestedSessionIdFromCookie;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttribute(java.lang.String)
+     */
+    public Object getAttribute(String name) {
+        return this.getAttribute(name, Request.GLOBAL_SCOPE);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttributeNames()
+     */
+    public Enumeration getAttributeNames() {
+        return this.getAttributeNames(Request.GLOBAL_SCOPE);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#setAttribute(java.lang.String, java.lang.Object)
+     */
+    public void setAttribute(String name, Object value) {
+        this.setAttribute(name, value, Request.GLOBAL_SCOPE);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#removeAttribute(java.lang.String)
+     */
+    public void removeAttribute(String name) {
+        this.removeAttribute(name, Request.GLOBAL_SCOPE);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+     */
+    public Object getAttribute(String name, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            return this.attributes.get(name);
+        }
+        return this.globalAttributes.get(name);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+     */
+    public Enumeration getAttributeNames(int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            return this.attributes.keys();
+        }
+        return this.globalAttributes.keys();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#setAttribute(java.lang.String, java.lang.Object, int)
+     */
+    public void setAttribute(String name, Object value, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            this.attributes.put(name, value);
+        } else {
+            this.globalAttributes.put(name, value);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+     */
+    public void removeAttribute(String name, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            this.attributes.remove(name);
+        } else {
+            this.globalAttributes.remove(name);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getInputStream()
+     */
+    public InputStream getInputStream() throws IOException, UnsupportedOperationException {
+        return this.inputStream;
+    }
+
+    public void setInputStream(InputStream is) {
+        this.inputStream = is;
+    }
+
+    /**
+     * @see org.apache.cocoon.environment.Request#searchAttribute(java.lang.String)
+     */
+    public Object searchAttribute(String name) {
+        Object result = this.getAttribute(name, REQUEST_SCOPE);
+        if ( result == null ) {
+            result = this.getAttribute(name, GLOBAL_SCOPE);
+        }
+        return result;
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockResponse.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockResponse.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockResponse.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockResponse.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,120 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.cocoon.environment.mock;
+
+import java.util.Locale;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.cocoon.environment.Cookie;
+import org.apache.cocoon.environment.Response;
+import org.apache.cocoon.environment.Session;
+
+public class MockResponse implements Response {
+
+    private String encoding;
+    private Locale locale;
+    private Set cookies = new HashSet();
+    private Map header = new HashMap();
+
+    private Session session;
+    
+    public void setCharacterEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public String getCharacterEncoding() {
+        return encoding;
+    }
+
+    public void setLocale(Locale locale) {
+        this.locale = locale;
+    }
+
+    public Locale getLocale() {
+        return locale;
+    }
+
+    public Cookie createCookie(String name, String value) {
+        MockCookie cookie = new MockCookie();
+        cookie.setName(name);
+        cookie.setValue(value);
+        return cookie;
+    }
+
+    public void addCookie(Cookie cookie) {
+        cookies.add(cookie);
+    }
+
+    public Set getCookies() {
+        return cookies;
+    }
+
+    public boolean containsHeader(String name) {
+        return header.containsKey(name);
+    }
+
+    public String encodeURL(String url) {
+        //throw new AssertionFailedError("Not implemented");
+        StringBuffer sb = new StringBuffer();
+            sb.append( url );
+        if (session != null) {
+            sb.append( "?JSESSIONID=");
+            sb.append( session.getId() );
+        }
+        return sb.toString();
+    }
+
+    public void setDateHeader(String name, long date) {
+        header.put(name, new Long(date));
+    }
+
+    public void addDateHeader(String name, long date) {
+        header.put(name, new Long(date));
+    }
+
+    public void setHeader(String name, String value) {
+        header.put(name, value);
+    }
+
+    public void addHeader(String name, String value) {
+        header.put(name, value);
+    }
+
+    public void setIntHeader(String name, int value) {
+        header.put(name, new Integer(value));
+    }
+
+    public void addIntHeader(String name, int value) {
+        header.put(name, new Integer(value));
+    }
+
+    public Map getHeader() {
+        return header;
+    }
+
+    public void reset() {
+        encoding = null;
+        locale = null;
+        cookies.clear();
+        header.clear();
+    }
+    
+    public void setSession( Session session ) {
+        this.session = session;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockSession.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockSession.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockSession.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockSession.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,108 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.cocoon.environment.mock;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import junit.framework.AssertionFailedError;
+
+import org.apache.cocoon.environment.impl.AbstractSession;
+
+public class MockSession extends AbstractSession {
+
+    private long creationtime = System.currentTimeMillis();
+    private String id = "MockSession";
+    private long lastaccessedtime = System.currentTimeMillis();
+    private int maxinactiveinterval = -1;
+    private Hashtable attributes = new Hashtable();
+    private boolean valid = true;
+    private boolean isNew = false;
+
+    public long getCreationTime() {
+        checkValid();
+        return creationtime;
+    }
+  
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getId() {
+        checkValid();
+        return id;
+    }
+
+    public long getLastAccessedTime() {
+        checkValid();
+        return lastaccessedtime;
+    }
+
+    public void setMaxInactiveInterval(int interval) {
+        checkValid();
+        this.maxinactiveinterval = interval;
+    }
+
+    public int getMaxInactiveInterval() {
+        checkValid();
+        return maxinactiveinterval;
+    }
+
+    public Object getAttribute(String name) {
+        checkValid();
+        return attributes.get(name);
+    }
+
+    public Enumeration getAttributeNames() {
+        checkValid();
+        return attributes.keys();
+    }
+
+    public void setAttribute(String name, Object value) {
+        checkValid();
+        attributes.put(name, value);
+    }
+
+    public void removeAttribute(String name) {
+        checkValid();
+        attributes.remove(name);
+    }
+
+    public void invalidate() {
+        checkValid();
+        this.valid = false;
+    }
+
+    public boolean isNew() {
+        checkValid();
+        return isNew;
+    }
+
+    private void checkValid() throws IllegalStateException {
+        if (!valid) {
+            throw new AssertionFailedError("session has been invalidated!");
+        }
+    }
+
+    public boolean isValid() {
+        return valid;
+    }
+    
+    public void setIsNew(boolean isNew ) {
+        this.isNew = isNew;
+    }
+}
+

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/test/java/org/apache/cocoon/environment/mock/MockSession.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message