taylor 2004/02/19 19:54:49
Modified: cps maven.xml
cps/src/java/org/apache/jetspeed/cps/template
TemplateLocatorComponentImpl.java
cps/src/test/org/apache/jetspeed/components
TestComponentManager.java
TestNanoComponentManager.java
cps/src/test/org/apache/jetspeed/cps TestPico.java
cps/test/WEB-INF/conf container.groovy
cps/test/rewriter test-001-output.html
Added: cps/src/test/org/apache/jetspeed/components
ComponentAssemblyTestCase.java
cps/src/test/org/apache/jetspeed/cps/template
TestTemplateLocatorComponent.java
cps/test/assembly TestTemplateLocatorComponent.groovy
Log:
completed first conversion of a service to a pico component (template locator)
wrote test for component
wrote a groovy script for assembling the container to bootstrap the component test
ComponentAssemblyTestCase can be used to base other component unit tests based on
assembly
Revision Changes Path
1.9 +1 -1 jakarta-jetspeed-2/cps/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/cps/maven.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- maven.xml 18 Feb 2004 21:20:59 -0000 1.8
+++ maven.xml 20 Feb 2004 03:54:49 -0000 1.9
@@ -4,7 +4,7 @@
xmlns:reactor="reactor">
<!-- Target of maven test:single test -->
- <property name='testcase'
value='org.apache.jetspeed.components.TestComponentManager'/>
+ <property name='testcase'
value='org.apache.jetspeed.cps.template.TestTemplateLocatorComponent'/>
<goal name="deployJar">
<attainGoal name="jar:install"/>
1.3 +98 -113
jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/template/TemplateLocatorComponentImpl.java
Index: TemplateLocatorComponentImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/template/TemplateLocatorComponentImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TemplateLocatorComponentImpl.java 13 Feb 2004 03:48:27 -0000 1.2
+++ TemplateLocatorComponentImpl.java 20 Feb 2004 03:54:49 -0000 1.3
@@ -55,18 +55,14 @@
import java.util.Iterator;
import java.io.File;
-import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.StringTokenizer;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.PropertiesConfiguration;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.cps.CPSInitializationException;
-import org.apache.jetspeed.cps.CommonPortletServices;
+import org.picocontainer.Startable;
/**
* TemplateLocatorComponentImpl
@@ -74,54 +70,102 @@
* @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
* @version $Id$
*/
-public class TemplateLocatorComponentImpl implements TemplateLocatorComponent
+public class TemplateLocatorComponentImpl implements TemplateLocatorComponent,
Startable
{
private final static Log log =
LogFactory.getLog(TemplateLocatorServiceImpl.class);
- private final static String MSG_MISSING_PARAMETER =
- "TemplateLocatorService initialization failed. Missing parameter: ";
+
private static final String PATH_SEPARATOR = "/";
/** the template root directories, all application root relative */
- private String[] templateRoots;
- private final static String TEMPLATE_ROOTS = "roots";
+ private List roots;
+
+ /** the Template class is factory created */
+ private Class templateClass = TemplateImpl.class;
- /** use the name cache when looking up a template */
- private boolean useNameCache = true;
+ /** the TemplateLocator class is factory created */
+ private Class locatorClass = TemplateLocatorImpl.class;
+ /** the default locator type */
+ private String defaultLocatorType = "layout";
+
/** template name cache used to speed up searches for templates */
private Map templateMap = null;
+
+ /** use the name cache when looking up a template */
+ private boolean useNameCache = true;
+
+ private TemplateLocatorComponentImpl()
+ {
+ // need to know roots
+ }
- /** the TemplateLocator class is factory created */
- private static String locatorClassName = null;
- private static Class locatorClass = null;
- private final static String TEMPLATE_LOCATOR_CLASS = "locator.class";
-
- /** the default locator type */
- private String defaultLocatorType = "portlet";
- private final static String DEFAULT_LOCATOR_TYPE = "locator.default.type";
+ /**
+ * Minimal assembly with a list of resource directory roots.
+ *
+ * @param roots A list of resource root directories where templates are
located.
+ */
+ public TemplateLocatorComponentImpl(List roots)
+ {
+ this.roots = roots;
+ }
+
+ /**
+ * Construct with a root list and a default locator type.
+ *
+ * @param roots A list of resource root directories where templates are located.
+ * @param defaultLocatorType Under root directories, subdirectories represent
locator types.
+ * A locator type represents a classification of
templates.
+ * Any value is allowed. Use locator types to group
templates together.
+ */
+ public TemplateLocatorComponentImpl(List roots,
+ String defaultLocatorType)
+ {
+ this.roots = roots;
+ this.defaultLocatorType = defaultLocatorType;
+ }
- /** the default template name */
- private String defaultTemplateName = "default.vm";
- private final static String DEFAULT_TEMPLATE_NAME = "default.template.name";
-
- /** the default template name */
- private String defaultExtension = "vm";
- private final static String DEFAULT_EXTENSION = "default.extension";
+ /**
+ * Assemble with list resource directory roots and OM classes and a
defaultLocatorType.
+ *
+ * @param roots A list of resource root directories where templates are located.
+ * @param omClasses Template replacable object model implementations for
Template and TemplateLocator.
+ * Required order, with second optional: [
<code>Template</code>, <code>TemplateLocator</code> implementations.
+ * @param defaultLocatorType Under root directories, subdirectories represent
locator types.
+ * A locator type represents a classification of
templates.
+ * Any value is allowed. Use locator types to group
templates together.
+ */
+ public TemplateLocatorComponentImpl(List roots,
+ List omClasses,
+ String defaultLocatorType)
+ {
+ System.out.println("Initializing template locator component: " +
locatorClass.getName());
+ this.roots = roots;
+ this.defaultLocatorType = defaultLocatorType;
+ if (omClasses.size() > 0)
+ {
+ this.templateClass = (Class)omClasses.get(0);
+ if (omClasses.size() > 1)
+ {
+ this.locatorClass = (Class)omClasses.get(1);
+ }
+ }
+ }
-
+
+
/* (non-Javadoc)
* @see
org.apache.jetspeed.cps.template.TemplateLocatorService#locateTemplate(org.apache.jetspeed.cps.template.TemplateLocator)
*/
public Template locateTemplate(TemplateLocator locator)
{
- for (int ix = 0; ix < templateRoots.length; ix++)
+ for (int ix = 0; ix < roots.size(); ix++)
{
- Template template = locateTemplate(locator, templateRoots[ix]);
+ Template template = locateTemplate(locator, (String)roots.get(ix));
if (null == template)
{
// Try to locate it directly on file system, perhaps it was
recently added
useNameCache = false;
- template = locateTemplate(locator, templateRoots[ix]);
+ template = locateTemplate(locator, (String)roots.get(ix));
if (null != template)
{
// add it to the map
@@ -169,7 +213,7 @@
do // fallback
{
workingPath = path + PATH_SEPARATOR + templateName;
- // TODO: realPath =
CommonPortletServices.getInstance().getRealPath(root + workingPath);
+ realPath = root + workingPath;
// the current template exists, return the corresponding path
if (templateExists(realPath))
@@ -269,7 +313,7 @@
*/
private Template createTemplateFromPath(String path, String name, String
realPath, String relativePath)
{
- TemplateImpl template = new TemplateImpl();
+ Template template = this.createTemplate();
template.setAbsolutePath(realPath);
if(relativePath.indexOf("/") != 0)
{
@@ -309,21 +353,7 @@
throws TemplateLocatorException
{
TemplateLocator locator = null;
-
- if (null == locatorClass)
- {
- try
- {
- locatorClassName =
getConfiguration().getString(TEMPLATE_LOCATOR_CLASS);
- locatorClass = Class.forName(locatorClassName);
- }
- catch(Exception e)
- {
- throw new TemplateLocatorException(
- "TemplateLocator Factory: Failed to create a Class object for
TemplateLocator implementation: ", e);
- }
- }
-
+
try
{
locator = (TemplateLocator)locatorClass.newInstance();
@@ -336,87 +366,42 @@
return locator;
}
-/*
- public TemplateLocatorComponentImpl()
- {
- System.out.println("--- DEFAULT constructing template locator impl");
- }
-*/
- public TemplateLocatorComponentImpl(Configuration configuration)
- {
- System.out.println("--- CONFIGURATION constructing template locator impl");
- this.configuration = configuration;
-/*
- try
- {
- init();
- System.out.println("-- TLC implemented ok");
- }
- catch (Throwable t)
- {
- t.printStackTrace();
- log.error(t);
- }
-*/
- }
-
-
- private Configuration configuration = null;
- private boolean isInit = false;
-
- public Configuration getConfiguration()
+ private Template createTemplate()
{
- return configuration;
- }
-
- /* (non-Javadoc)
- * @see org.apache.fulcrum.Service#init()
- */
- public void init() throws CPSInitializationException
- {
- if (isInit)
+ Template template= null;
+
+ try
{
- return;
+ template = (Template)templateClass.newInstance();
}
-
- this.defaultLocatorType =
getConfiguration().getString(DEFAULT_LOCATOR_TYPE, defaultLocatorType);
- this.defaultTemplateName =
getConfiguration().getString(DEFAULT_TEMPLATE_NAME, defaultTemplateName);
- this.defaultExtension = getConfiguration().getString(DEFAULT_EXTENSION,
defaultExtension);
-
- this.templateRoots = getConfiguration().getStringArray(TEMPLATE_ROOTS);
-
- if ((this.templateRoots == null) || (this.templateRoots.length == 0))
+ catch(Exception e)
{
- throw new CPSInitializationException(MSG_MISSING_PARAMETER +
TEMPLATE_ROOTS);
+ log.error("Failed to create template", e);
+ template = new TemplateImpl();
}
+ return template;
+ }
+ public void start()
+ {
this.templateMap = new HashMap();
- for (int ix = 0; ix < this.templateRoots.length; ix++)
+ for (int ix = 0; ix < roots.size(); ix++)
{
- String templateRoot = this.templateRoots[ix];
+ String templateRoot = (String)roots.get(ix);
if (!templateRoot.endsWith(PATH_SEPARATOR))
{
templateRoot = templateRoot + PATH_SEPARATOR;
}
- if (log.isDebugEnabled())
- {
- log.debug("TemplateLocator: Adding templateRoot:" + templateRoot);
- }
-
- // traverse starting from the root template directory and add resources
- String templateRootPath =
CommonPortletServices.getInstance().getRealPath(templateRoot);
- if (null != templateRootPath)
- {
- loadNameCache(templateRootPath, "");
- }
+ loadNameCache(templateRoot, "");
}
-
- isInit = true;
}
+ public void stop()
+ {
+ }
/* (non-Javadoc)
* @see
org.apache.jetspeed.cps.template.TemplateLocatorService#query(org.apache.jetspeed.cps.template.TemplateLocator)
1.3 +8 -4
jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/TestComponentManager.java
Index: TestComponentManager.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/TestComponentManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestComponentManager.java 18 Feb 2004 19:37:19 -0000 1.2
+++ TestComponentManager.java 20 Feb 2004 03:54:49 -0000 1.3
@@ -108,7 +108,10 @@
public void testManager()
throws Exception
{
- Configuration config = getConfiguration();
+ }
+ /**
+ SOON TO BE deprecated
+ Configuration config = getConfiguration();
ComponentManager cm = new ComponentManager(config);
cm.start();
@@ -142,8 +145,9 @@
cm.stop();
- System.out.println("Component Manager Test completed");
- }
+ System.out.println("Component Manager Test completed");
+ **/
+
public Configuration getConfiguration()
throws Exception
1.3 +8 -24
jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/TestNanoComponentManager.java
Index: TestNanoComponentManager.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/TestNanoComponentManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestNanoComponentManager.java 19 Feb 2004 22:12:44 -0000 1.2
+++ TestNanoComponentManager.java 20 Feb 2004 03:54:49 -0000 1.3
@@ -68,7 +68,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
* @version $Id$
*/
-public class TestNanoComponentManager extends TestCase
+public class TestNanoComponentManager extends ComponentAssemblyTestCase
{
public TestNanoComponentManager(String name)
{
@@ -85,7 +85,8 @@
junit.awtui.TestRunner.main( new String[] {
TestNanoComponentManager.class.getName() } );
}
- public void setup()
+ public void setUp()
+ throws Exception
{
}
@@ -95,37 +96,20 @@
// All methods starting with "test" will be executed in the test suite.
return new TestSuite(TestNanoComponentManager.class);
}
-
- public String getApplicationRoot()
- {
- String applicationRoot = "test";
- File testPath = new File(applicationRoot);
- if (!testPath.exists())
- {
- testPath = new File( "cps" + File.separator + applicationRoot);
- if (testPath.exists())
- {
- applicationRoot = testPath.getAbsolutePath();
- }
- }
- return applicationRoot;
- }
-
+
public void testLoadGroovy() throws Exception
{
- String applicationRoot = getApplicationRoot();
+ String applicationRoot = getApplicationRoot("cps", "test");
File containerAssembler = new File(applicationRoot +
"/WEB-INF/conf/container.groovy");
assertTrue(containerAssembler.exists());
NanoComponentManager containerManager = new
NanoComponentManager(containerAssembler);
ObjectReference rootContainerRef = new SimpleReference();
-
-
+
containerManager.getContainerBuilder().buildContainer(rootContainerRef, null,
"TEST_SCOPE");
assertNotNull(rootContainerRef.get());
- assertNotNull(containerManager.getComponent("locator"));
-
+ assertNotNull(containerManager.getComponent("templateLocator"));
}
1.1
jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/ComponentAssemblyTestCase.java
Index: ComponentAssemblyTestCase.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Jetspeed", 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 (INCLUDING, 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.components;
import java.io.File;
import org.picocontainer.defaults.ObjectReference;
import org.picocontainer.defaults.SimpleReference;
import junit.framework.TestCase;
/**
* ComponentAssemblyTestCase
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
* @version $Id: ComponentAssemblyTestCase.java,v 1.1 2004/02/20 03:54:49 taylor Exp
$
*/
public abstract class ComponentAssemblyTestCase extends TestCase
{
public ComponentAssemblyTestCase(String name)
{
super( name );
}
public String getAssemblyScriptType()
{
return ".groovy";
}
public String getTestName()
{
String className = this.getClass().getName();
int ix = className.lastIndexOf(".");
if (ix > -1)
{
className = className.substring(ix + 1);
}
return className;
}
public static String getApplicationRoot(String baseProject, String relativePath)
{
String applicationRoot = relativePath;
File testPath = new File(applicationRoot);
if (!testPath.exists())
{
testPath = new File( baseProject + File.separator + applicationRoot);
if (testPath.exists())
{
applicationRoot = testPath.getAbsolutePath();
}
}
return applicationRoot;
}
protected NanoComponentManager componentManager = null;
public void setUp()
throws Exception
{
String applicationRoot = getApplicationRoot("cps", "test");
File containerAssembler = new File(applicationRoot + "/assembly/" +
getTestName() + getAssemblyScriptType());
assertTrue(containerAssembler.exists());
componentManager = new NanoComponentManager(containerAssembler);
ObjectReference rootContainerRef = new SimpleReference();
componentManager.getContainerBuilder().buildContainer(rootContainerRef,
null, "TEST_SCOPE");
assertNotNull(rootContainerRef.get());
}
}
1.3 +9 -2
jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/cps/TestPico.java
Index: TestPico.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/cps/TestPico.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestPico.java 13 Feb 2004 03:48:27 -0000 1.2
+++ TestPico.java 20 Feb 2004 03:54:49 -0000 1.3
@@ -54,14 +54,18 @@
package org.apache.jetspeed.cps;
import java.io.File;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.jetspeed.cps.template.Template;
+import org.apache.jetspeed.cps.template.TemplateImpl;
import org.apache.jetspeed.cps.template.TemplateLocator;
import org.apache.jetspeed.cps.template.TemplateLocatorComponent;
import org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl;
+import org.apache.jetspeed.cps.template.TemplateLocatorImpl;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.defaults.ConstantParameter;
@@ -120,11 +124,14 @@
MutablePicoContainer pico = new DefaultPicoContainer();
// pico.registerComponentImplementation(TemplateLocatorComponent.class,
TemplateLocatorComponentImpl.class);
+ List roots = new ArrayList();
+ roots.add("test/WEB-INF/templates");
- Parameter [] parameters = {new ConstantParameter(configuration)};
+ Parameter [] parameters = { new ConstantParameter(roots) };
System.out.println("parameters: " + parameters.length);
+
pico.registerComponentImplementation(
TemplateLocatorComponent.class,
TemplateLocatorComponentImpl.class,
1.1
jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/cps/template/TestTemplateLocatorComponent.java
Index: TestTemplateLocatorComponent.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Jetspeed", 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 (INCLUDING, 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.cps.template;
import org.apache.jetspeed.components.ComponentAssemblyTestCase;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* TestTemplateLocatorComponent
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
* @version $Id: TestTemplateLocatorComponent.java,v 1.1 2004/02/20 03:54:49 taylor
Exp $
*/
public class TestTemplateLocatorComponent extends ComponentAssemblyTestCase
{
public TestTemplateLocatorComponent(String name)
{
super( name );
}
/**
* Start the tests.
*
* @param args the arguments. Not used
*/
public static void main(String args[])
{
junit.awtui.TestRunner.main( new String[] {
TestTemplateLocatorComponent.class.getName() } );
}
public static Test suite()
{
// All methods starting with "test" will be executed in the test suite.
return new TestSuite(TestTemplateLocatorComponent.class);
}
public void testLocateTemplate()
throws Exception
{
TemplateLocatorComponent component =
(TemplateLocatorComponent)componentManager.getComponent("templateLocator");
assertNotNull("template service is null", component);
TemplateLocator locator = component.createLocator("email");
locator.setName("test.vm");
Template template = component.locateTemplate(locator);
assertNotNull("template is null", template);
System.out.println("template1 = " + template);
assertTrue("template1 result",
"type/email/name/test.vm".endsWith(template.toString()));
TemplateLocator locator2 = component.createLocator("email");
locator2.setName("htmltest.vm");
locator2.setMediaType("html");
template = component.locateTemplate(locator2);
assertNotNull("template is null", template);
System.out.println("template2 = " + template);
assertTrue("template2 result",
"type/email/media-type/html/name/htmltest.vm".endsWith(template.toString()));
TemplateLocator locator3 = component.createLocator("email");
locator3.setName("entest.vm");
locator3.setMediaType("html");
locator3.setLanguage("en");
template = component.locateTemplate(locator3);
assertNotNull("template is null", template);
System.out.println("template3 = " + template);
assertTrue("template3 result",
"type/email/media-type/html/language/en/name/entest.vm".endsWith(template.toString()));
TemplateLocator locator4 = component.createLocator("email");
locator4.setName("ustest.vm");
locator4.setMediaType("html");
locator4.setLanguage("en");
locator4.setCountry("US");
template = component.locateTemplate(locator4);
assertNotNull("template is null", template);
System.out.println("template4 = " + template);
assertTrue("template4 result",
"type/email/media-type/html/language/en/country/US/name/ustest.vm".endsWith(template.toString()));
// test fallback
TemplateLocator locator5 = component.createLocator("email");
locator5.setName("entest.vm");
locator5.setMediaType("html");
locator5.setLanguage("en");
locator5.setCountry("UZ");
template = component.locateTemplate(locator5);
assertNotNull("template is null", template);
System.out.println("template5 = " + template);
assertTrue("template5 result",
"type/email/media-type/html/language/en/name/entest.vm".endsWith(template.toString()));
// test fallback all the way to email
TemplateLocator locator6 = component.createLocator("email");
locator6.setName("test.vm");
locator6.setMediaType("html");
locator6.setLanguage("en");
locator6.setCountry("UZ");
template = component.locateTemplate(locator6);
System.out.println("template6 = " + template);
assertTrue("template6 result",
"type/email/name/test.vm".endsWith(template.toString()));
}
}
1.2 +10 -14 jakarta-jetspeed-2/cps/test/WEB-INF/conf/container.groovy
Index: container.groovy
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/cps/test/WEB-INF/conf/container.groovy,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- container.groovy 19 Feb 2004 21:34:36 -0000 1.1
+++ container.groovy 20 Feb 2004 03:54:49 -0000 1.2
@@ -1,20 +1,16 @@
import org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl
-import org.apache.jetspeed.cps.template.TemplateLocatorComponent
import org.picocontainer.defaults.DefaultPicoContainer
-import org.apache.commons.configuration.PropertiesConfiguration
-
-container = new DefaultPicoContainer()
-
-PropertiesConfiguration locator1Conf = new PropertiesConfiguration();
-locator1Conf.setProperty("roots", " WEB-INF/templates")
-locator1Conf.setProperty("template.class",
"org.apache.jetspeed.cps.template.TemplateImpl")
-locator1Conf.setProperty("default.type", "layout")
-locator1Conf.setProperty("default.template.name", "columns.vm")
-locator1Conf.setProperty("default.extension", "vm")
-
-container.registerComponentInstance("locator", new
TemplateLocatorComponentImpl(locator1Conf))
+import org.apache.jetspeed.components.ComponentAssemblyTestCase
+applicationRoot = ComponentAssemblyTestCase.getApplicationRoot("cps", "test")
+// create the root container
+container = new DefaultPicoContainer()
+//
+// Template Locator component assembly
+//
+roots = [ applicationRoot + "/WEB-INF/templates" ]
+container.registerComponentInstance("templateLocator", new
TemplateLocatorComponentImpl(roots))
-return container
\ No newline at end of file
+return container
1.1
jakarta-jetspeed-2/cps/test/assembly/TestTemplateLocatorComponent.groovy
Index: TestTemplateLocatorComponent.groovy
===================================================================
import org.picocontainer.defaults.DefaultPicoContainer
import org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl
import org.apache.jetspeed.components.ComponentAssemblyTestCase
applicationRoot = ComponentAssemblyTestCase.getApplicationRoot("cps", "test")
// create the root container
container = new DefaultPicoContainer()
//
// Template Locator component assembly
//
roots = [ applicationRoot + "/WEB-INF/templates" ]
omClasses = [ org.apache.jetspeed.cps.template.TemplateImpl,
org.apache.jetspeed.cps.template.TemplateLocatorImpl ]
defaultType = "email"
container.registerComponentInstance("templateLocator",
new TemplateLocatorComponentImpl(roots,
omClasses, defaultType))
return container
1.21 +3 -3 jakarta-jetspeed-2/cps/test/rewriter/test-001-output.html
Index: test-001-output.html
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/cps/test/rewriter/test-001-output.html,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- test-001-output.html 18 Feb 2004 21:20:59 -0000 1.20
+++ test-001-output.html 20 Feb 2004 03:54:49 -0000 1.21
@@ -1,8 +1,8 @@
<p>
This is a test</p>
-<a target="_BLANK" href="http://www.bluesunrise.com/suffix" name="1">keep this</a>
- <a target="_BLANK"
href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" name="2">junk</a>
- <a target="_BLANK"
href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" name="3">junk2</a>
+<a href="http://www.bluesunrise.com/suffix" target="_BLANK" name="1">keep this</a>
+ <a href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix"
target="_BLANK" name="2">junk</a>
+ <a href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix"
target="_BLANK" name="3">junk2</a>
<a href="javascript:whatever()" name="4">script</a>
<a href="mailto:[EMAIL PROTECTED]" name="5">script</a>
<a href="#INTERNAL" name="6">internal</a>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]