You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by gr...@apache.org on 2005/02/15 05:36:29 UTC

svn commit: r153893 [1/2] - in lenya/trunk/src/test/org/apache: cocoon/ cocoon/components/ cocoon/components/sax/ cocoon/components/source/ cocoon/components/treeprocessor/ cocoon/components/treeprocessor/variables/ cocoon/core/ cocoon/core/container/ cocoon/environment/ cocoon/environment/commandline/ cocoon/environment/commandline/test/ cocoon/environment/mock/ cocoon/xml/ cocoon/xml/dom/ lenya/ac/impl/ lenya/cms/ lenya/cms/workflow/

Author: gregor
Date: Mon Feb 14 20:36:23 2005
New Revision: 153893

URL: http://svn.apache.org/viewcvs?view=rev&rev=153893
Log:
Updated tests to use ContainerTestCase and related Cocoon helper classes

Added:
    lenya/trunk/src/test/org/apache/cocoon/
    lenya/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/components/
    lenya/trunk/src/test/org/apache/cocoon/components/sax/
    lenya/trunk/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/components/source/
    lenya/trunk/src/test/org/apache/cocoon/components/source/SourceResolverAdapter.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/
    lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/
    lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest   (with props)
    lenya/trunk/src/test/org/apache/cocoon/core/
    lenya/trunk/src/test/org/apache/cocoon/core/container/
    lenya/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/
    lenya/trunk/src/test/org/apache/cocoon/environment/commandline/
    lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/
    lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/package.html   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/mock/
    lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockContext.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockCookie.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockRedirector.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockRequest.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockResponse.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockSession.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/xml/
    lenya/trunk/src/test/org/apache/cocoon/xml/AbstractXMLTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/xml/DefaultHandlerWrapper.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/xml/SaxBufferTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/xml/WhitespaceFilter.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/xml/dom/
    lenya/trunk/src/test/org/apache/cocoon/xml/dom/DOMBuilderStreamerTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/cocoon/xml/dom/DOMBuilderTestCase.java   (with props)
    lenya/trunk/src/test/org/apache/lenya/ac/impl/AccessController.xtest   (with props)
    lenya/trunk/src/test/org/apache/lenya/ac/impl/IdentityTest.xtest   (contents, props changed)
      - copied, changed from r153453, lenya/trunk/src/test/org/apache/lenya/ac/impl/IdentityTestCase.xtest
    lenya/trunk/src/test/org/apache/lenya/cms/workflow/WorkflowTest.xtest   (with props)
Removed:
    lenya/trunk/src/test/org/apache/lenya/ac/impl/IdentityTestCase.xtest
Modified:
    lenya/trunk/src/test/org/apache/lenya/ac/impl/AccessControlTest.java
    lenya/trunk/src/test/org/apache/lenya/cms/lenya.xtest

Added: lenya/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java Mon Feb 14 20:36:23 2005
@@ -0,0 +1,761 @@
+/*
+ * 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;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.acting.Action;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.components.flow.AbstractInterpreter;
+import org.apache.cocoon.components.flow.FlowHelper;
+import org.apache.cocoon.components.flow.Interpreter;
+import org.apache.cocoon.components.source.SourceResolverAdapter;
+import org.apache.cocoon.core.container.ContainerTestCase;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.mock.MockContext;
+import org.apache.cocoon.environment.mock.MockRedirector;
+import org.apache.cocoon.environment.mock.MockRequest;
+import org.apache.cocoon.environment.mock.MockResponse;
+import org.apache.cocoon.generation.Generator;
+import org.apache.cocoon.matching.Matcher;
+import org.apache.cocoon.serialization.Serializer;
+import org.apache.cocoon.sitemap.PatternException;
+import org.apache.cocoon.transformation.Transformer;
+import org.apache.cocoon.xml.WhitespaceFilter;
+import org.apache.cocoon.xml.dom.DOMBuilder;
+import org.apache.cocoon.xml.dom.DOMStreamer;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.xml.sax.SAXParser;
+import org.custommonkey.xmlunit.Diff;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Testcase for actions, generators, transformers and serializer components. 
+ *
+ * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
+ * @author <a href="mailto:mark.leicester@energyintellect.com">Mark Leicester</a>
+ * @version CVS $Id$
+ */
+public abstract class SitemapComponentTestCase extends ContainerTestCase {
+    
+    public final static Parameters EMPTY_PARAMS = Parameters.EMPTY_PARAMETERS;
+
+    private MockRequest request = new MockRequest();
+    private MockResponse response = new MockResponse();
+    private MockContext context = new MockContext();
+    private MockRedirector redirector = new MockRedirector();
+    private Map objectmodel = new HashMap();
+
+    public final MockRequest getRequest() {
+        return request;
+    }
+
+    public final MockResponse getResponse() {
+        return response;
+    }
+
+    public final MockContext getContext() {
+        return context;
+    }
+
+    public final MockRedirector getRedirector() { 
+        return redirector;
+    }
+
+    public final Map getObjectModel() {
+        return objectmodel;
+    }
+    
+    protected void addContext(DefaultContext context) {
+        context.put(ContextHelper.CONTEXT_REQUEST_OBJECT, request);
+        context.put(ContextHelper.CONTEXT_RESPONSE_OBJECT, response);
+        context.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectmodel);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        objectmodel.clear();
+
+        request.reset();
+        objectmodel.put(ObjectModelHelper.REQUEST_OBJECT, request);
+
+        response.reset();
+        objectmodel.put(ObjectModelHelper.RESPONSE_OBJECT, response);
+
+        context.reset();
+        objectmodel.put(ObjectModelHelper.CONTEXT_OBJECT, context);
+
+        redirector.reset();
+    }
+
+    /**
+     * Match with a pattern.
+     *
+     * @param type Hint of the matcher. 
+     * @param pattern Pattern for the matcher.
+     * @param parameters Matcher parameters.
+     */
+    public final Map match(String type, String pattern, Parameters parameters) throws PatternException {
+
+        ServiceSelector selector = null;
+        Matcher matcher = null;
+        SourceResolver resolver = null;
+
+        Map result = null;
+        try {
+            selector = (ServiceSelector) this.lookup(Matcher.ROLE +
+                "Selector");
+            assertNotNull("Test lookup of matcher selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            assertNotNull("Test if matcher name is not null", type);
+            matcher = (Matcher) selector.select(type);
+            assertNotNull("Test lookup of matcher", matcher);
+
+            result = matcher.match(pattern, objectmodel, parameters);
+
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve matcher", ce);
+            fail("Could not retrieve matcher: " + ce.toString());
+        } finally {
+            if (matcher != null) {
+                selector.release(matcher);
+            }
+            this.release(selector);
+            this.release(resolver);
+        }
+        return result;
+    }
+
+    /**
+     * Select with a pattern.
+     *
+     * @param type Hint of the matcher. 
+     * @param expression Expression for the selector.
+     * @param parameters Matcher parameters.
+     */
+    public final boolean select(String type, String expression, Parameters parameters) {
+
+        ServiceSelector selector = null;
+        org.apache.cocoon.selection.Selector sel = null;
+        SourceResolver resolver = null;
+
+        boolean result = false;
+        try {
+            selector = (ServiceSelector) this.lookup(org.apache.cocoon.selection.Selector.ROLE +
+                "Selector");
+            assertNotNull("Test lookup of selector selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            assertNotNull("Test if selector name is not null", type);
+            sel = (org.apache.cocoon.selection.Selector) selector.select(type);
+            assertNotNull("Test lookup of selector", sel);
+            
+
+            result = sel.select(expression, objectmodel, parameters);
+
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve selector", ce);
+            fail("Could not retrieve selector: " + ce.toString());
+        } finally {
+            if (sel != null) {
+                selector.release(sel);
+            }
+            this.release(selector);
+            this.release(resolver);
+        }
+        return result;
+    }
+
+    /**
+     * Perform the action component.
+     *
+     * @param type Hint of the action. 
+     * @param source Source for the action.
+     * @param parameters Action parameters.
+     */
+    public final Map act(String type, String source, Parameters parameters) throws Exception {
+        
+        redirector.reset();
+
+        ServiceSelector selector = null;
+        Action action = null;
+        SourceResolver resolver = null;
+
+        Map result = null;
+        try {
+            selector = (ServiceSelector) this.lookup(Action.ROLE +
+                "Selector");
+            assertNotNull("Test lookup of action selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            assertNotNull("Test if action name is not null", type);
+            action = (Action) selector.select(type);
+            assertNotNull("Test lookup of action", action);
+
+            result = action.act(redirector, new SourceResolverAdapter(resolver),
+                                objectmodel, source, parameters);
+
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve action", ce);
+            fail("Could not retrieve action: " + ce.toString());
+        } finally {
+            if (action != null) {
+                selector.release(action);
+            }
+            this.release(selector);
+            this.release(resolver);
+        }
+        return result;
+    }
+
+    /**
+     * Generate the generator output.
+     *
+     * @param type Hint of the generator. 
+     * @param source Source for the generator.
+     * @param parameters Generator parameters.
+     */
+    public final Document generate(String type, String source, Parameters parameters) 
+        throws IOException, SAXException, ProcessingException {
+
+        ServiceSelector selector = null;
+        Generator generator = null;
+        SourceResolver resolver = null;
+        SAXParser parser = null;
+
+        Document document = null;
+        try {
+            selector = (ServiceSelector) this.lookup(Generator.ROLE +
+                "Selector");
+            assertNotNull("Test lookup of generator selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            parser = (SAXParser) this.lookup(SAXParser.ROLE);
+            assertNotNull("Test lookup of parser", parser);
+
+            assertNotNull("Test if generator name is not null", type);
+
+            generator = (Generator) selector.select(type);
+            assertNotNull("Test lookup of generator", generator);
+
+            generator.setup(new SourceResolverAdapter(resolver),
+                            objectmodel, source, parameters);
+
+            DOMBuilder builder = new DOMBuilder();
+            generator.setConsumer(new WhitespaceFilter(builder));
+
+            generator.generate();
+
+            document = builder.getDocument();
+
+            assertNotNull("Test for generator document", document);
+
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve generator", ce);
+            fail("Could not retrieve generator: " + ce.toString());
+        } finally {
+            if (generator != null) {
+                selector.release(generator);
+            }
+            this.release(selector);
+            this.release(resolver);
+            this.release(parser);
+        }
+
+        return document;
+    }
+
+    /**     
+     * Trannsform a document by a transformer
+     *      
+     * @param type Hint of the transformer. 
+     * @param source Source for the transformer.
+     * @param parameters Generator parameters.
+     * @param input Input document.
+     */ 
+    public final Document transform(String type, String source, Parameters parameters, Document input) 
+        throws SAXException, ProcessingException, IOException {
+
+        ServiceSelector selector = null;
+        Transformer transformer = null;
+        SourceResolver resolver = null;
+        SAXParser parser = null;
+        Source inputsource = null;
+
+        assertNotNull("Test for component manager", this.getManager());
+
+        Document document = null;
+        try {
+            selector = (ServiceSelector) this.lookup(Transformer.ROLE+
+                "Selector");
+            assertNotNull("Test lookup of transformer selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            parser = (SAXParser) this.lookup(SAXParser.ROLE);
+            assertNotNull("Test lookup of parser", parser);
+
+
+            assertNotNull("Test if transformer name is not null", type);
+            transformer = (Transformer) selector.select(type);
+            assertNotNull("Test lookup of transformer", transformer);
+
+            transformer.setup(new SourceResolverAdapter(resolver),
+                                  objectmodel, source, parameters);
+
+            DOMBuilder builder = new DOMBuilder();
+            transformer.setConsumer(new WhitespaceFilter(builder));
+
+            assertNotNull("Test if input document is not null", input);
+            DOMStreamer streamer = new DOMStreamer(transformer);
+            streamer.stream(input);
+
+            document = builder.getDocument();
+            assertNotNull("Test for transformer document", document);
+
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve transformer", ce);
+            ce.printStackTrace();
+            fail("Could not retrieve transformer:"+ce.toString());
+        } finally {
+            if (transformer!=null) {
+                selector.release(transformer);
+            }
+
+            if (selector!=null) {
+                this.release(selector);
+            }
+
+            if (inputsource!=null) {
+                resolver.release(inputsource);
+            }
+
+            if (resolver!=null) {
+                this.release(resolver);
+            }
+
+            if (parser!=null) {
+                this.release(parser);
+            }
+        }
+
+        return document; 
+    }
+
+    /**
+     * Serialize a document by a serializer
+     *
+     * @param type Hint of the serializer.
+     * @param parameters Serializer parameters.
+     * @param input Input document.
+     *
+     * @return Serialized data.
+     */
+    public final byte[] serialize(String type, Parameters parameters,
+                                  Document input) throws SAXException, IOException{
+
+        ServiceSelector selector = null;
+        Serializer serializer = null;
+        SourceResolver resolver = null;
+        Source inputsource = null;
+
+        assertNotNull("Test for component manager", this.getManager());
+
+        ByteArrayOutputStream document = null;
+
+        try {
+            selector = (ServiceSelector) this.lookup(Serializer.ROLE+
+                "Selector");
+            assertNotNull("Test lookup of serializer selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            assertNotNull("Test if serializer name is not null", type);
+            serializer = (Serializer) selector.select(type);
+            assertNotNull("Test lookup of serializer", serializer);
+
+            document = new ByteArrayOutputStream();
+            serializer.setOutputStream(document);
+
+            assertNotNull("Test if input document is not null", input);
+            DOMStreamer streamer = new DOMStreamer(serializer);
+
+            streamer.stream(input);
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve serializer", ce);
+            fail("Could not retrieve serializer:"+ce.toString());
+        } finally {
+            if (serializer!=null) {
+                selector.release(serializer);
+            }
+
+            if (selector!=null) {
+                this.release(selector);
+            }
+
+            if (inputsource!=null) {
+                resolver.release(inputsource);
+            }
+
+            if (resolver!=null) {
+                this.release(resolver);
+            }
+        }
+
+        return document.toByteArray();
+    }
+    
+    public String callFunction(String type, String source, String function, Map params) throws Exception {
+        
+        redirector.reset();
+        
+        ServiceSelector selector = null;
+        Interpreter interpreter = null;
+        SourceResolver resolver = null;
+
+        try {
+            selector = (ServiceSelector) this.lookup(Interpreter.ROLE);
+            assertNotNull("Test lookup of interpreter selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            assertNotNull("Test if interpreter name is not null", type);
+            interpreter = (Interpreter) selector.select(type);
+            assertNotNull("Test lookup of interpreter", interpreter);
+            
+            ((AbstractInterpreter)interpreter).register(source);
+            
+            ArrayList parameters = new ArrayList();
+            for (Iterator i = params.entrySet().iterator(); i.hasNext();) {
+                Map.Entry me = (Map.Entry)i.next();
+                String name = (String)me.getKey();
+                String value = (String)me.getValue();
+                parameters.add(new Interpreter.Argument(name, value));
+            }
+            interpreter.callFunction(function, parameters, getRedirector());
+            
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve interpeter", ce);
+            fail("Could not retrieve interpreter: " + ce.toString());
+        } finally {
+            if (interpreter != null) {
+                selector.release(interpreter);
+            }
+            this.release(selector);
+            this.release(resolver);
+        }
+        return FlowHelper.getWebContinuation(getObjectModel()).getId();
+    }
+    
+    public String callContinuation(String type, String source, String id, Map params) throws Exception {
+        
+        redirector.reset();
+        
+        ServiceSelector selector = null;
+        Interpreter interpreter = null;
+        SourceResolver resolver = null;
+
+        try {
+            selector = (ServiceSelector) this.lookup(Interpreter.ROLE);
+            assertNotNull("Test lookup of interpreter selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            assertNotNull("Test if interpreter name is not null", type);
+            interpreter = (Interpreter) selector.select(type);
+            assertNotNull("Test lookup of interpreter", interpreter);
+
+            ((AbstractInterpreter)interpreter).register(source);
+            
+            ArrayList parameters = new ArrayList();
+            for (Iterator i = params.entrySet().iterator(); i.hasNext();) {
+                Map.Entry me = (Map.Entry)i.next();
+                String name = (String)me.getKey();
+                String value = (String)me.getValue();
+                parameters.add(new Interpreter.Argument(name, value));
+            }
+            interpreter.handleContinuation(id, parameters, getRedirector());
+
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve interpreter", ce);
+            fail("Could not retrieve interpreter: " + ce.toString());
+        } finally {
+            if (interpreter != null) {
+                selector.release(interpreter);
+            }
+            this.release(selector);
+            this.release(resolver);
+        }
+        return FlowHelper.getWebContinuation(getObjectModel()).getId();
+    }
+    
+    public Object getFlowContextObject() {
+        return FlowHelper.getContextObject(getObjectModel());
+    }
+
+    public final void print(Document document) {
+        TransformerFactory factory = TransformerFactory.newInstance();
+        try
+        {
+          javax.xml.transform.Transformer serializer = factory.newTransformer();
+          serializer.transform(new DOMSource(document), new StreamResult(System.out));
+          System.out.println();
+        } 
+        catch (TransformerException te)
+        {
+          te.printStackTrace();
+        }
+    }
+
+    public final Document load(String source) {
+
+        SourceResolver resolver = null;
+        SAXParser parser = null;
+        Source assertionsource = null;
+
+        assertNotNull("Test for component manager", this.getManager());
+
+        Document assertiondocument = null;
+        try {
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            parser = (SAXParser) this.lookup(SAXParser.ROLE);
+            assertNotNull("Test lookup of parser", parser);
+
+            assertNotNull("Test if assertion document is not null",
+                          source);
+            assertionsource = resolver.resolveURI(source);
+            assertNotNull("Test lookup of assertion source",
+                          assertionsource);
+            assertTrue("Test if source exist", assertionsource.exists());
+
+            DOMBuilder builder = new DOMBuilder();
+            assertNotNull("Test if inputstream of the assertion source is not null",
+                          assertionsource.getInputStream());
+
+            parser.parse(new InputSource(assertionsource.getInputStream()),
+                         new WhitespaceFilter(builder),
+                         builder);
+
+            assertiondocument = builder.getDocument();
+            assertNotNull("Test if assertion document exists", assertiondocument);
+
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve generator", ce);
+            fail("Could not retrieve generator: " + ce.toString());
+        } catch (Exception e) {
+            getLogger().error("Could not execute test", e);
+            fail("Could not execute test: " + e);
+        } finally {
+            if (resolver != null) {
+                resolver.release(assertionsource);
+            }
+            this.release(resolver);
+            this.release(parser);
+        }
+
+        return assertiondocument;
+    }
+
+    /**
+     * Load a binary document.
+     *
+     * @param source Source location.
+     *
+     * @return Binary data.
+     */
+    public final byte[] loadByteArray(String source) {
+
+        SourceResolver resolver = null;
+        SAXParser parser = null;
+        Source assertionsource = null;
+
+        assertNotNull("Test for component manager", this.getManager());
+
+        byte[] assertiondocument = null;
+
+        try {
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            parser = (SAXParser) this.lookup(SAXParser.ROLE);
+            assertNotNull("Test lookup of parser", parser);
+
+            assertNotNull("Test if assertion document is not null", source);
+            assertionsource = resolver.resolveURI(source);
+            assertNotNull("Test lookup of assertion source", assertionsource);
+            assertTrue("Test if source exist", assertionsource.exists());
+
+            assertNotNull("Test if inputstream of the assertion source is not null",
+                          assertionsource.getInputStream());
+
+            InputStream input = assertionsource.getInputStream();
+            long size = assertionsource.getContentLength();
+
+            assertiondocument = new byte[(int) size];
+            int i = 0;
+            int c;
+
+            while ((c = input.read())!=-1) {
+                assertiondocument[i] = (byte) c;
+                i++;
+            }
+
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve generator", ce);
+            fail("Could not retrieve generator: "+ce.toString());
+        } catch (Exception e) {
+            getLogger().error("Could not execute test", e);
+            fail("Could not execute test: "+e);
+        } finally {
+            if (resolver!=null) {
+                resolver.release(assertionsource);
+            }
+            this.release(resolver);
+            this.release(parser);
+        }
+
+        return assertiondocument;
+    }
+
+    /**
+     * Compare two XML documents provided as strings
+     * @param control Control document
+     * @param test Document to test
+     * @return Diff object describing differences in documents
+     */
+    public final Diff compareXML(Document control, Document test) {
+        return new Diff(control, test);
+    }
+
+    /**
+     * Assert that the result of an XML comparison is similar.
+     *
+     * @param msg The assertion message
+     * @param expected The expected XML document
+     * @param actual The actual XML Document
+     */
+    public final void assertEqual(String msg, Document expected, Document actual) {
+
+        expected.getDocumentElement().normalize();
+        actual.getDocumentElement().normalize();
+
+        Diff diff = compareXML(expected, actual);
+
+        assertEquals(msg + ", " + diff.toString(), true, diff.similar());
+    }
+
+    /**
+     * Assert that the result of an XML comparison is similar.
+     *
+     * @param expected The expected XML document
+     * @param actual The actual XML Document
+     */  
+    public final void assertEqual(Document expected, Document actual) {
+
+        expected.getDocumentElement().normalize();
+        actual.getDocumentElement().normalize();
+
+        Diff diff = compareXML(expected, actual);
+
+        assertEquals("Test if the assertion document is equal, " + diff.toString(), true, diff.similar());
+    }
+
+    /**
+     * Assert that the result of an XML comparison is identical.
+     *
+     * @param msg The assertion message
+     * @param expected The expected XML document
+     * @param actual The actual XML Document
+     */
+    public final void assertIdentical(String msg, Document expected, Document actual) {
+
+        expected.getDocumentElement().normalize();
+        actual.getDocumentElement().normalize();
+
+        Diff diff = compareXML(expected, actual);
+
+        assertEquals(msg + ", " + diff.toString(), true, diff.identical());
+    }
+
+    /**
+     * Assert that the result of an XML comparison is identical.
+     *
+     * @param expected The expected XML document
+     * @param actual The actual XML Document
+     */
+    public final void assertIdentical(Document expected, Document actual) {
+
+        expected.getDocumentElement().normalize();
+        actual.getDocumentElement().normalize();
+
+        Diff diff = compareXML(expected, actual);
+
+        assertEquals("Test if the assertion document is equal, " + diff.toString(), true, diff.identical());
+    }
+
+    /**
+     * Assert that the result of a byte comparison is identical.
+     *
+     * @param expected The expected byte array
+     * @param actual The actual byte array
+     */
+    public final void assertIdentical(byte[] expected, byte[] actual) {
+        assertEquals("Byte arrays of differing sizes, ", expected.length,
+                     actual.length);
+
+        if (expected.length>0) {
+            for (int i = 0; i<expected.length; i++) {
+                assertEquals("Byte array differs at index "+i, expected[i],
+                             actual[i]);
+            }
+        }
+
+    }
+}

Propchange: lenya/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/SitemapComponentTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java Mon Feb 14 20:36:23 2005
@@ -0,0 +1,140 @@
+/*
+ * 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.sax;
+
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.ContentHandler;
+import org.apache.cocoon.xml.dom.DOMBuilder;
+import org.apache.cocoon.xml.AbstractXMLTestCase;
+import org.apache.cocoon.xml.DefaultHandlerWrapper;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Testcase for XMLByteStreamCompiler and Interpreter
+ *
+ * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
+ * @version
+ */
+
+public final class XMLByteStreamCompilerInterpreterTestCase extends AbstractXMLTestCase {
+    public XMLByteStreamCompilerInterpreterTestCase(String s) {
+        super(s);
+    }
+
+    public void testCompareDOM() throws Exception {
+        // reference
+        DOMBuilder in = new DOMBuilder();
+        generateLargeSAX(in);
+
+        // capture events
+        XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
+        generateLargeSAX(xmlc);
+
+        // recall events and build a DOM from it
+        XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
+        DOMBuilder out = new DOMBuilder();
+        xmli.setConsumer(out);
+        xmli.deserialize(xmlc.getSAXFragment());
+
+        // compare DOMs
+        assertXMLEqual(in.getDocument(), out.getDocument());
+    }
+
+    public void testCompareByteArray() throws Exception {
+        // capture events
+        XMLByteStreamCompiler sa = new XMLByteStreamCompiler();
+        generateLargeSAX(sa);
+
+        // serialize events
+        byte[] aa = (byte[]) sa.getSAXFragment();
+
+        // deserialize and capture
+        XMLByteStreamCompiler sb = new XMLByteStreamCompiler();
+        XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
+        xmli.setConsumer(sb);
+        xmli.deserialize(aa);
+
+        // serialize again
+        byte[] ab = (byte[]) sb.getSAXFragment();
+
+        assertTrue(aa.length == ab.length);
+
+        for (int i=0;i<aa.length;i++) {
+            assertEquals(aa[i],ab[i]);
+        }
+    }
+
+    public void testStressLoop() throws Exception {
+        XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
+
+        long loop = 10000;
+
+        // simply consume documents
+        long start = System.currentTimeMillis();
+        for(int i=0;i<loop;i++) {
+            generateSmallSAX(xmlc);
+            xmlc.recycle();
+        }
+        long stop = System.currentTimeMillis();
+
+        double r = 1000*loop/(stop-start);
+        System.out.println("consuming: "+ r + " documents per second");
+    }
+
+    public void testCompareToParsing() throws Exception {
+        DOMBuilder in = new DOMBuilder();
+        generateSmallSAX(in);
+
+        SAXParserFactory pfactory = SAXParserFactory.newInstance();
+        SAXParser p = pfactory.newSAXParser();
+
+        XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
+        DefaultHandlerWrapper wrapper = new DefaultHandlerWrapper(xmlc);
+
+        ByteArrayInputStream bis = new ByteArrayInputStream(generateByteArray());
+
+        long loop = 10000;
+
+        // parse documents
+        long start = System.currentTimeMillis();
+        for(int i=0;i<loop;i++) {
+            xmlc.recycle();
+            bis.reset();
+            p.parse(bis,wrapper);
+        }
+        long stop = System.currentTimeMillis();
+
+        double r = 1000*loop/(stop-start);
+        System.out.println("parsed: " + r + " documents per second");
+
+
+        XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
+        ContentHandler ch = new DefaultHandler();
+
+        // recall documents
+        start = System.currentTimeMillis();
+        for(int i=0;i<loop;i++) {
+            xmli.setContentHandler(ch);
+            xmli.deserialize(xmlc.getSAXFragment());
+        }
+        stop = System.currentTimeMillis();
+
+        r = 1000*loop/(stop-start);
+        System.out.println("recalling: " + r + " documents per second");
+    }
+}

Propchange: lenya/trunk/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/components/source/SourceResolverAdapter.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/components/source/SourceResolverAdapter.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/components/source/SourceResolverAdapter.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/components/source/SourceResolverAdapter.java Mon Feb 14 20:36:23 2005
@@ -0,0 +1,90 @@
+/*
+ * 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.source;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.environment.SourceResolver;
+import org.xml.sax.SAXException;
+
+/**
+ * An adapter for the Excalibur SourceResolver.
+ *
+ * @version CVS $Id$
+ */
+public class SourceResolverAdapter implements SourceResolver
+{
+    private org.apache.excalibur.source.SourceResolver resolver;
+
+    public SourceResolverAdapter(org.apache.excalibur.source.SourceResolver resolver) {
+        this.resolver = resolver;
+    }
+
+    /**
+     * Get a <code>Source</code> object.
+     * This is a shortcut for <code>resolve(location, null, null)</code>
+     * @throws org.apache.excalibur.source.SourceException if the source cannot be resolved
+     */
+    public org.apache.excalibur.source.Source resolveURI( String location )
+        throws MalformedURLException, IOException, org.apache.excalibur.source.SourceException {
+  
+        return this.resolver.resolveURI(location);
+    }
+
+    /**
+     * Get a <code>Source</code> object.
+     * @param location - the URI to resolve. If this is relative it is either
+     *                   resolved relative to the base parameter (if not null)
+     *                   or relative to a base setting of the source resolver
+     *                   itself.
+     * @param base - a base URI for resolving relative locations. This
+     *               is optional and can be <code>null</code>.
+     * @param parameters - Additional parameters for the URI. The parameters
+     *                     are specific to the used protocol.
+     * @throws org.apache.excalibur.source.SourceException if the source cannot be resolved
+     */
+    public org.apache.excalibur.source.Source resolveURI( String location,
+                                                          String base,
+                                                          Map parameters )
+        throws MalformedURLException, IOException, org.apache.excalibur.source.SourceException {
+
+        return this.resolver.resolveURI(location, base, parameters);
+    }
+
+    /**
+     * Releases a resolved resource
+     */
+    public void release( org.apache.excalibur.source.Source source ) {
+        this.resolver.release(source);
+    }
+
+    /**
+     * Resolve the source.
+     * @param systemID This is either a system identifier
+     * (<code>java.net.URL</code> or a local file.
+     * @deprecated Use the resolveURI methods instead
+     */
+    public Source resolve(String systemID)
+        throws ProcessingException, SAXException, IOException {
+
+        throw new RuntimeException("Method SourceResolver.resolve(String) is deprecated");
+    }
+}

Propchange: lenya/trunk/src/test/org/apache/cocoon/components/source/SourceResolverAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/components/source/SourceResolverAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java Mon Feb 14 20:36:23 2005
@@ -0,0 +1,222 @@
+/*
+ * 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$
+ */
+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()));
+    }
+}

Propchange: lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest (added)
+++ lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest Mon Feb 14 20:36:23 2005
@@ -0,0 +1,32 @@
+<?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.components.ExtendedComponentSelector"/>
+ </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>

Propchange: lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolverTestCase.xtest
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java Mon Feb 14 20:36:23 2005
@@ -0,0 +1,299 @@
+/*
+ * 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.component.DefaultRoleManager;
+import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
+import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.avalon.framework.configuration.Configuration;
+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.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.WrapperServiceManager;
+
+/**
+ * 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>annotation</code>,
+ *  <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$
+ */
+public class ContainerTestCase extends TestCase {
+
+    /** The default logger */
+    private Logger logger;
+
+    /** The service manager to use */
+    private ServiceManager manager;
+
+    /** 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_DEBUG);
+        this.logger = new ConsoleLogger(Integer.parseInt(level));
+
+        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);
+            prepare(resource.openStream());
+        } else {
+            getLogger().debug("Resource not found " + resourceName);
+        }
+    }
+
+    /**
+     * 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("ContainerTestCase.initialize");
+        }
+
+        final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+        final Configuration conf = builder.build(testconf);
+
+        Context context = this.setupContext(conf.getChild("context"));
+
+        setupManagers(conf.getChild("components"),
+                      conf.getChild("roles"),
+                      context);
+    }
+
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        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);
+                }
+            }
+        }
+        addContext(context);
+        return context ;
+    }
+
+    /**
+     * This method may be overwritten by subclasses to put additional objects
+     * into the context programmatically.
+     */
+    protected void addContext(DefaultContext context) {
+    }
+
+    final private void setupManagers(final Configuration confCM,
+                                     final Configuration confRM,
+                                     final Context context)
+    throws Exception {
+        // Setup the RoleManager
+        DefaultRoleManager roleManager = new DefaultRoleManager();
+        roleManager.enableLogging(getLogger());
+        roleManager.configure(confRM);
+
+        // Set up the ComponentLocator
+        ExcaliburComponentManager ecManager = new ExcaliburComponentManager();
+        ecManager.enableLogging(getLogger());
+        ecManager.contextualize(context);
+        ecManager.setRoleManager(roleManager);
+        ecManager.setLoggerManager(new DefaultLoggerManager(getLogger()));
+        ecManager.configure(confCM);
+        ecManager.initialize();
+        this.manager = new WrapperServiceManager(ecManager);
+    }
+
+    protected final Object lookup(final String key)
+    throws ServiceException {
+        return manager.lookup(key);
+    }
+
+    protected final void release(final Object object) {
+        manager.release(object);
+    }
+
+    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: lenya/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java Mon Feb 14 20:36:23 2005
@@ -0,0 +1,162 @@
+/*
+ * 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$
+ */
+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 {
+        super.setUp();
+        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 {
+        super.tearDown();
+        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: lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/package.html
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/package.html?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/package.html (added)
+++ lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/package.html Mon Feb 14 20:36:23 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: lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/environment/commandline/test/package.html
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockContext.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockContext.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockContext.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockContext.java Mon Feb 14 20:36:23 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.Context;
+
+public class MockContext implements Context {
+
+    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: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockCookie.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockCookie.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockCookie.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockCookie.java Mon Feb 14 20:36:23 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: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockCookie.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockCookie.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java?view=auto&rev=153893
==============================================================================
--- lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java (added)
+++ lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java Mon Feb 14 20:36:23 2005
@@ -0,0 +1,232 @@
+/*
+ * 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.net.MalformedURLException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import junit.framework.AssertionFailedError;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+public class MockEnvironment implements Environment {
+
+    private SourceResolver resolver;
+
+    private String uri;
+    private String uriprefix;
+    private String rootcontext;
+    private String context;
+    private String view;
+    private String action;
+    private String contenttype;
+    private int contentlength;
+    private int status;
+    private ByteArrayOutputStream outputstream;
+    private HashMap objectmodel;
+    private Hashtable attributes = new Hashtable();
+
+    public MockEnvironment(SourceResolver resolver) {
+        this.resolver = resolver;
+    }
+
+    public String getURI() {
+        return uri;
+    }
+
+    public String getURIPrefix() {
+        return uriprefix;
+    }
+
+    public String getRootContext() {
+        return rootcontext;
+    }
+
+    public String getContext() {
+        return context;
+    }
+
+    public String getView() {
+        return view;
+    }
+
+    public String getAction() {
+        return action;
+    }
+
+    public void setContext(String prefix, String uri, String context) {
+        throw new AssertionFailedError("Not implemented");
+    }
+
+    public void changeContext(String uriprefix, String context) throws Exception {
+        throw new AssertionFailedError("Not implemented");
+    }
+
+    public void redirect(boolean sessionmode, String url) 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() throws IOException {
+        outputstream = new ByteArrayOutputStream();
+        return outputstream;
+    }
+
+    public OutputStream getOutputStream(int bufferSize) throws IOException {
+        outputstream = new ByteArrayOutputStream();
+        return outputstream;
+    }
+
+    public byte[] getOutput() {
+        return outputstream.toByteArray();
+    }
+
+    public Map getObjectModel() {
+        return objectmodel;
+    }
+
+    public boolean isResponseModified(long lastModified) {
+        throw new AssertionFailedError("Not implemented");
+    }
+
+    public void setResponseIsNotModified() {
+        throw new AssertionFailedError("Not implemented");
+    }
+
+    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 {
+        throw new AssertionFailedError("Not implemented");
+    }
+
+    public void commitResponse() throws IOException {
+        throw new AssertionFailedError("Not implemented");
+    }
+    
+    public void startingProcessing() {
+        throw new AssertionFailedError("Not implemented");
+    }
+    
+    public void finishingProcessing() {
+        throw new AssertionFailedError("Not implemented");
+    }
+
+
+    public Source resolve(String systemID)
+      throws ProcessingException, SAXException, IOException {
+  
+        throw new AssertionFailedError("Not not use deprecated methods!");
+    }
+
+    public void toSAX(org.apache.excalibur.source.Source source,
+                ContentHandler handler)
+      throws SAXException, IOException, ProcessingException {
+
+        throw new AssertionFailedError("Not not use deprecated methods!");
+    }
+
+    public void toSAX(org.apache.excalibur.source.Source source,
+               String         mimeTypeHint,
+               ContentHandler handler)
+      throws SAXException, IOException, ProcessingException {
+
+        throw new AssertionFailedError("Not not use deprecated methods!");
+    }
+
+    public org.apache.excalibur.source.Source resolveURI(String location)
+        throws MalformedURLException, IOException, org.apache.excalibur.source.SourceException {
+
+        return resolver.resolveURI(location);
+    }
+
+    public org.apache.excalibur.source.Source resolveURI(String location,
+                                                         String base,
+                                                         Map parameters)
+        throws MalformedURLException, IOException, org.apache.excalibur.source.SourceException {
+
+        return resolver.resolveURI(location, base, parameters);
+    }
+
+    /**
+     * Releases a resolved resource
+     */
+    public void release(org.apache.excalibur.source.Source source) {
+        resolver.release(source);
+    }
+    
+    /**
+     * Always return <code>true</code>.
+     */
+    public boolean isExternal() {
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Environment#isInternRedirect()
+     */
+    public boolean isInternalRedirect() {
+        return false;
+    }
+}
+

Propchange: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/test/org/apache/cocoon/environment/mock/MockEnvironment.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org