You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2003/08/13 10:35:33 UTC
cvs commit: incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/config ConfigurationTest.java test1.xml
jdillon 2003/08/13 01:35:33
Added: modules/twiddle/src/test/org/apache/geronimo/twiddle/command
CommandFactoryTest.java CommandPathParserTest.java
TestCommand.java
modules/twiddle/src/test/org/apache/geronimo/twiddle/config
ConfigurationTest.java test1.xml
Log:
o Some initial tests for Twiddle
Revision Changes Path
1.1 incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/command/CommandFactoryTest.java
Index: CommandFactoryTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Geronimo" 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",
* "Apache Geronimo", 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.geronimo.twiddle.command;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Assert;
import org.apache.geronimo.twiddle.config.CommandConfig;
import org.apache.geronimo.twiddle.config.Attribute;
/**
* Tests for <code>CommandFactory</code>.
*
* @version <code>$Id: CommandFactoryTest.java,v 1.1 2003/08/13 08:35:33 jdillon Exp $</code>
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
*/
public class CommandFactoryTest
extends TestCase
{
/**
* Return the tests included in this test suite.
*/
public static Test suite()
{
return new TestSuite(CommandFactoryTest.class);
}
/**
* Construct a new instance of this test case.
*
* @param name Name of the test case
*/
public CommandFactoryTest(final String name)
{
super(name);
}
/**
* Set up instance variables required by this test case.
*/
protected void setUp()
{
}
/**
* Tear down instance variables required by this test case.
*/
protected void tearDown()
{
}
/////////////////////////////////////////////////////////////////////////
// Tests //
/////////////////////////////////////////////////////////////////////////
public void testCreateCommand() throws Exception
{
CommandConfig config = new CommandConfig();
String name = "mytest";
String desc = "my test description";
String type = "org.apache.geronimo.twiddle.command.TestCommand";
config.setName(name);
config.setDescription(desc);
config.setClazz(type);
CommandInfo protoInfo = new CommandInfo(config);
Command command = protoInfo.getPrototype();
// Verify command info
CommandInfo info = command.getCommandInfo();
Assert.assertNotNull(command.getCommandInfo());
Assert.assertEquals(name, info.getName());
Assert.assertEquals(desc, info.getDescription());
// Verify the class type
Assert.assertEquals(type, command.getClass().getName());
command.execute(new String[0]);
}
public void testCreateCommandWithAttribute() throws Exception
{
CommandConfig config = new CommandConfig();
config.setName("mytest");
config.setClazz("org.apache.geronimo.twiddle.command.TestCommand");
Attribute attr = new Attribute();
String text = "this is the value for the text attribute";
attr.setName("text");
attr.setContent(text);
config.addAttribute(attr);
CommandInfo protoInfo = new CommandInfo(config);
Command command = protoInfo.getPrototype();
// Verify that the text attribute was set correctly
Assert.assertEquals(text, ((TestCommand)command).getText());
command.execute(new String[0]);
}
}
1.1 incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/command/CommandPathParserTest.java
Index: CommandPathParserTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Geronimo" 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",
* "Apache Geronimo", 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.geronimo.twiddle.command;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Assert;
/**
* Tests for <code>CommandPathParser</code>.
*
* @version <code>$Id: CommandPathParserTest.java,v 1.1 2003/08/13 08:35:33 jdillon Exp $</code>
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
*/
public class CommandPathParserTest
extends TestCase
{
/**
* Return the tests included in this test suite.
*/
public static Test suite()
{
return new TestSuite(CommandPathParserTest.class);
}
/**
* Construct a new instance of this test case.
*
* @param name Name of the test case
*/
public CommandPathParserTest(final String name)
{
super(name);
}
/**
* Set up instance variables required by this test case.
*/
protected void setUp()
{
}
/**
* Tear down instance variables required by this test case.
*/
protected void tearDown()
{
}
/////////////////////////////////////////////////////////////////////////
// Tests //
/////////////////////////////////////////////////////////////////////////
public void testRoot()
{
CommandPathParser parser = new CommandPathParser("/");
String[] elements = parser.elements();
Assert.assertEquals(true, parser.isAbsolute());
Assert.assertEquals(1, elements.length);
Assert.assertEquals("/", elements[0]);
}
public void testTrailing()
{
CommandPathParser parser = new CommandPathParser("/one/");
String[] elements = parser.elements();
Assert.assertEquals(true, parser.isAbsolute());
Assert.assertEquals(2, elements.length);
Assert.assertEquals("/", elements[0]);
Assert.assertEquals("one", elements[1]);
}
public void testAbsolute2()
{
CommandPathParser parser = new CommandPathParser("/one");
String[] elements = parser.elements();
Assert.assertEquals(true, parser.isAbsolute());
Assert.assertEquals(2, elements.length);
Assert.assertEquals("/", elements[0]);
Assert.assertEquals("one", elements[1]);
}
public void testAbsolute3()
{
CommandPathParser parser = new CommandPathParser("/one/two");
String[] elements = parser.elements();
Assert.assertEquals(true, parser.isAbsolute());
Assert.assertEquals(3, elements.length);
Assert.assertEquals("/", elements[0]);
Assert.assertEquals("one", elements[1]);
Assert.assertEquals("two", elements[2]);
}
public void testAbsolute4()
{
CommandPathParser parser = new CommandPathParser("/one/two/three");
String[] elements = parser.elements();
Assert.assertEquals(true, parser.isAbsolute());
Assert.assertEquals(4, elements.length);
Assert.assertEquals("/", elements[0]);
Assert.assertEquals("one", elements[1]);
Assert.assertEquals("two", elements[2]);
Assert.assertEquals("three", elements[3]);
}
public void testRelative1()
{
CommandPathParser parser = new CommandPathParser("one");
String[] elements = parser.elements();
Assert.assertEquals(false, parser.isAbsolute());
Assert.assertEquals(1, elements.length);
Assert.assertEquals("one", elements[0]);
}
public void testRelative2()
{
CommandPathParser parser = new CommandPathParser("one/two");
String[] elements = parser.elements();
Assert.assertEquals(false, parser.isAbsolute());
Assert.assertEquals(2, elements.length);
Assert.assertEquals("one", elements[0]);
Assert.assertEquals("two", elements[1]);
}
public void testRelative3()
{
CommandPathParser parser = new CommandPathParser("one/two/three");
String[] elements = parser.elements();
Assert.assertEquals(false, parser.isAbsolute());
Assert.assertEquals(3, elements.length);
Assert.assertEquals("one", elements[0]);
Assert.assertEquals("two", elements[1]);
Assert.assertEquals("three", elements[2]);
}
}
1.1 incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/command/TestCommand.java
Index: TestCommand.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Geronimo" 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",
* "Apache Geronimo", 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.geronimo.twiddle.command;
/**
* A simple test command.
*
* @version <code>$Id: TestCommand.java,v 1.1 2003/08/13 08:35:33 jdillon Exp $</code>
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
*/
public class TestCommand
extends AbstractCommand
{
private String text = "my default text";
public void setText(String text)
{
this.text = text;
}
public String getText()
{
return text;
}
public int execute(String[] args) throws Exception
{
System.out.println("Name: " + getCommandInfo().getName());
System.out.println("Description: " + getCommandInfo().getDescription());
System.out.println("Text: " + text);
return Command.SUCCESS;
}
}
1.1 incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/config/ConfigurationTest.java
Index: ConfigurationTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 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 Geronimo" 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",
* "Apache Geronimo", 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.geronimo.twiddle.config;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Reader;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Assert;
/**
* Tests for <code>Configuration</code>.
*
* @version <code>$Id: ConfigurationTest.java,v 1.1 2003/08/13 08:35:33 jdillon Exp $</code>
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
*/
public class ConfigurationTest
extends TestCase
{
/**
* Return the tests included in this test suite.
*/
public static Test suite()
{
return new TestSuite(ConfigurationTest.class);
}
/**
* Construct a new instance of this test case.
*
* @param name Name of the test case
*/
public ConfigurationTest(final String name)
{
super(name);
}
protected ConfigurationReader reader;
/**
* Set up instance variables required by this test case.
*/
protected void setUp()
{
reader = new ConfigurationReader();
}
/**
* Tear down instance variables required by this test case.
*/
protected void tearDown()
{
reader = null;
}
/////////////////////////////////////////////////////////////////////////
// Tests //
/////////////////////////////////////////////////////////////////////////
protected Reader getReader(final String filename) throws IOException
{
InputStream input = this.getClass().getResourceAsStream(filename);
if (input == null) {
throw new FileNotFoundException("Missing test data file: " + filename);
}
return new BufferedReader(new InputStreamReader(input));
}
protected Configuration read(final String filename) throws Exception
{
Reader input = getReader(filename);
Configuration config = null;
try {
config = reader.read(input);
}
finally {
input.close();
}
return config;
}
public void testReader() throws Exception
{
Configuration config = read("test1.xml");
}
public void testProperties() throws Exception
{
Configuration config = read("test1.xml");
Properties p = config.getProperties();
Assert.assertNotNull(p);
Property[] props = p.getProperty();
Assert.assertEquals(2, props.length);
Assert.assertEquals("property1", props[0].getName());
Assert.assertEquals("value1", props[0].getContent());
Assert.assertEquals("property2", props[1].getName());
Assert.assertEquals("value2", props[1].getContent());
}
public void testLibraries() throws Exception
{
Configuration config = read("test1.xml");
Libraries l = config.getLibraries();
Assert.assertNotNull(l);
String[] libs = l.getLibrary();
Assert.assertEquals(2, libs.length);
Assert.assertEquals("library1", libs[0]);
Assert.assertEquals("library2", libs[1]);
}
public void testIncludes() throws Exception
{
Configuration config = read("test1.xml");
Includes i = config.getIncludes();
Assert.assertNotNull(i);
String[] incs = i.getInclude();
Assert.assertEquals(2, incs.length);
Assert.assertEquals("include1", incs[0]);
Assert.assertEquals("include2", incs[1]);
}
public void testSearchPath() throws Exception
{
Configuration config = read("test1.xml");
SearchPath s = config.getSearchPath();
Assert.assertNotNull(s);
String[] paths = s.getPathElement();
Assert.assertEquals(3, paths.length);
Assert.assertEquals("path1", paths[0]);
Assert.assertEquals("path2", paths[1]);
Assert.assertEquals("path3", paths[2]);
}
}
1.1 incubator-geronimo/modules/twiddle/src/test/org/apache/geronimo/twiddle/config/test1.xml
Index: test1.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: test1.xml,v 1.1 2003/08/13 08:35:33 jdillon Exp $ -->
<configuration xmlns="http://geronimo.apache.org/xml/schema/Twiddle/Configuration">
<!-- ================= -->
<!-- System Properties -->
<!-- ================= -->
<properties>
<property name="property1">value1</property>
<property name="property2">value2</property>
</properties>
<!-- ==================== -->
<!-- Additional Libraries -->
<!-- ==================== -->
<libraries>
<library>library1</library>
<library>library2</library>
</libraries>
<!-- ====================== -->
<!-- Configuration Includes -->
<!-- ====================== -->
<includes>
<include>include1</include>
<include>include2</include>
</includes>
<!-- ================== -->
<!-- Global Environment -->
<!-- ================== -->
<environment>
<attribute name="default1">value</attribute>
<attribute name="string1" type="string">value</attribute>
<attribute name="number1" type="number">1</attribute>
<attribute name="boolean1" type="boolean">true</attribute>
<attribute name="class1" type="class">my.class</attribute>
<complex-attribute name="complex1" class="my.complex.class">
<attribute name="default2">value2</attribute>
<attribute name="string2" type="string">value</attribute>
<attribute name="number2" type="number">2</attribute>
<attribute name="boolean2" type="boolean">false</attribute>
<attribute name="class2" type="class">my.other.class</attribute>
</complex-attribute>
</environment>
<!-- =================== -->
<!-- Command Search Path -->
<!-- =================== -->
<search-path>
<path-element>path1</path-element>
<path-element>path2</path-element>
<path-element>path3</path-element>
</search-path>
<!-- ======== -->
<!-- Commands -->
<!-- ======== -->
<commands>
<command name="help" class="org.geronimo.twiddle.commands.HelpCommand"/>
<command-set name="whatever">
<command name="whatever" class="whatever">
<attribute name="Foo">Bar</attribute>
</command>
</command-set>
</commands>
</configuration>