You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by st...@apache.org on 2003/04/19 18:11:17 UTC
cvs commit: cocoon-2.1/src/test/org/apache/cocoon/acting AbstractActionTestCase.java RequestParamActionTestCase.java RequestParamActionTestCase.xtest ResourceExistsActionTestCase.java ResourceExistsActionTestCase.xtest
stephan 2003/04/19 09:11:17
Added: src/test/org/apache/cocoon/acting
AbstractActionTestCase.java
RequestParamActionTestCase.java
RequestParamActionTestCase.xtest
ResourceExistsActionTestCase.java
ResourceExistsActionTestCase.xtest
Log:
Add abstract testcase for actions.
Revision Changes Path
1.1 cocoon-2.1/src/test/org/apache/cocoon/acting/AbstractActionTestCase.java
Index: AbstractActionTestCase.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.acting;
import java.util.Map;
import java.util.HashMap;
import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.parameters.Parameters;
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.components.source.SourceResolverAdapter;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
/**
* Testcase for action components.
*
* @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
* @version CVS $Id: AbstractActionTestCase.java,v 1.1 2003/04/19 16:11:17 stephan Exp $
*/
public abstract class AbstractActionTestCase extends ExcaliburTestCase
{
private MockRequest request = new MockRequest();
private MockResponse response = new MockResponse();
private MockContext context = new MockContext();
private MockRedirector redirector = new MockRedirector();
private HashMap objectmodel = new HashMap();
/**
* Create a new generator test case.
*
* @param name Name of test case.
*/
public AbstractActionTestCase(String name) {
super(name);
}
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;
}
public void setUp() {
objectmodel.put(ObjectModelHelper.REQUEST_OBJECT, request);
objectmodel.put(ObjectModelHelper.RESPONSE_OBJECT, response);
objectmodel.put(ObjectModelHelper.CONTEXT_OBJECT, context);
}
/**
* 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) {
ComponentSelector selector = null;
Action action = null;
SourceResolver resolver = null;
Map result = null;
try {
selector = (ComponentSelector) this.manager.lookup(Action.ROLE +
"Selector");
assertNotNull("Test lookup of action selector", selector);
resolver = (SourceResolver) this.manager.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, this.manager),
objectmodel, source, parameters);
} catch (ComponentException 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 (action != null) {
selector.release(action);
}
this.manager.release(selector);
this.manager.release(resolver);
}
return result;
}
}
1.1 cocoon-2.1/src/test/org/apache/cocoon/acting/RequestParamActionTestCase.java
Index: RequestParamActionTestCase.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.acting;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
/**
*
*
* @author <a href="mailto:stephan@apache.org">Stephan Michels </a>
* @version CVS $Id: RequestParamActionTestCase.java,v 1.1 2003/04/19 16:11:17 stephan Exp $
*/
public class RequestParamActionTestCase extends AbstractActionTestCase {
public RequestParamActionTestCase(String name) {
super(name);
}
public void testRequestAction() {
getRequest().setRequestURI("test.xml?abc=def&ghi=jkl");
getRequest().setQueryString("abc=def&ghi=jkl");
getRequest().setContextPath("servlet");
getRequest().addParameter("abc", "def");
Parameters parameters = new Parameters();
parameters.setParameter("parameters", "true");
Map result = act("request", null, parameters);
assertNotNull("Test if resource exists", result);
assertEquals("Test for parameter", "test.xml?abc=def&ghi=jkl", (String)result.get("requestURI"));
assertEquals("Test for parameter", "?abc=def&ghi=jkl", (String)result.get("requestQuery"));
assertEquals("Test for parameter", "servlet", (String)result.get("context"));
assertEquals("Test for parameter", "def", (String)result.get("abc"));
assertNull("Test for parameter", (String)result.get("ghi"));
}
}
1.1 cocoon-2.1/src/test/org/apache/cocoon/acting/RequestParamActionTestCase.xtest
Index: RequestParamActionTestCase.xtest
===================================================================
<?xml version="1.0" ?>
<testcase>
<annotation>
Test Cases: RequestParamAction
</annotation>
<logkit>
<factories>
<factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
</factories>
<targets>
<stream id="root">
<stream>System.out</stream>
<format type="extended">
%7.7{priority} %5.5{time} [%9.9{category}] (%{context}): %{message}\n%{throwable}
</format>
</stream>
</targets>
<categories>
<category name="test" log-level="WARN">
<log-target id-ref="root"/>
</category>
</categories>
</logkit>
<context/>
<roles>
<role name="org.apache.excalibur.source.SourceFactorySelector"
shorthand="source-factories"
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
<role name="org.apache.excalibur.source.SourceResolver"
shorthand="source-resolver"
default-class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
<role name="org.apache.cocoon.acting.ActionSelector"
shorthand="actions"
default-class="org.apache.cocoon.sitemap.DefaultSitemapComponentSelector"/>
</roles>
<components>
<source-factories>
<component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/>
<component-instance class="org.apache.excalibur.source.impl.URLSourceFactory" name="*"/>
</source-factories>
<source-resolver class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
<actions logger="test">
<component-instance class="org.apache.cocoon.acting.RequestParamAction"
name="request"/>
</actions>
</components>
</testcase>
1.1 cocoon-2.1/src/test/org/apache/cocoon/acting/ResourceExistsActionTestCase.java
Index: ResourceExistsActionTestCase.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.acting;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
/**
*
*
* @author <a href="mailto:stephan@apache.org">Stephan Michels </a>
* @version CVS $Id: ResourceExistsActionTestCase.java,v 1.1 2003/04/19 16:11:17 stephan Exp $
*/
public class ResourceExistsActionTestCase extends AbstractActionTestCase {
public ResourceExistsActionTestCase(String name) {
super(name);
}
public void testExistAction() {
String src = "resource://org/apache/cocoon/acting/ResourceExistsActionTestCase.xtest";
Parameters parameters = new Parameters();
Map result = act("exist", src, parameters);
assertNotNull("Test if resource exists", result);
src = "resource://org/apache/cocoon/acting/ResourceExistsActionTestCase.abc";
result = act("exist", src, parameters);
assertNull("Test if resource not exists", result);
}
}
1.1 cocoon-2.1/src/test/org/apache/cocoon/acting/ResourceExistsActionTestCase.xtest
Index: ResourceExistsActionTestCase.xtest
===================================================================
<?xml version="1.0" ?>
<testcase>
<annotation>
Test Cases: ResourceExistsAction
</annotation>
<logkit>
<factories>
<factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
</factories>
<targets>
<stream id="root">
<stream>System.out</stream>
<format type="extended">
%7.7{priority} %5.5{time} [%9.9{category}] (%{context}): %{message}\n%{throwable}
</format>
</stream>
</targets>
<categories>
<category name="test" log-level="WARN">
<log-target id-ref="root"/>
</category>
</categories>
</logkit>
<context/>
<roles>
<role name="org.apache.excalibur.source.SourceFactorySelector"
shorthand="source-factories"
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"/>
<role name="org.apache.excalibur.source.SourceResolver"
shorthand="source-resolver"
default-class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
<role name="org.apache.cocoon.acting.ActionSelector"
shorthand="actions"
default-class="org.apache.cocoon.sitemap.DefaultSitemapComponentSelector"/>
</roles>
<components>
<source-factories>
<component-instance class="org.apache.excalibur.source.impl.ResourceSourceFactory" name="resource"/>
<component-instance class="org.apache.excalibur.source.impl.URLSourceFactory" name="*"/>
</source-factories>
<source-resolver class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
<actions logger="test">
<component-instance class="org.apache.cocoon.acting.ResourceExistsAction"
name="exist"/>
</actions>
</components>
</testcase>