Skip to Content.
Sympa Menu

notify-dpml - r888 - in trunk/main/util: cli/src/test/net/dpml/cli cli/src/test/net/dpml/cli/application cli/src/test/net/dpml/cli/bug cli/src/test/net/dpml/cli/builder cli/src/test/net/dpml/cli/commandline cli/src/test/net/dpml/cli/option cli/src/test/net/dpml/cli/resource cli/src/test/net/dpml/cli/util cli/src/test/net/dpml/cli/validation cli/src/test/net/dpml/cli/validation/protect configuration/impl/src/test/net/dpml/configuration/test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r888 - in trunk/main/util: cli/src/test/net/dpml/cli cli/src/test/net/dpml/cli/application cli/src/test/net/dpml/cli/bug cli/src/test/net/dpml/cli/builder cli/src/test/net/dpml/cli/commandline cli/src/test/net/dpml/cli/option cli/src/test/net/dpml/cli/resource cli/src/test/net/dpml/cli/util cli/src/test/net/dpml/cli/validation cli/src/test/net/dpml/cli/validation/protect configuration/impl/src/test/net/dpml/configuration/test
  • Date: Mon, 9 Jan 2006 03:14:09 +0100

Author: mcconnell
Date: 2006-01-09 03:12:59 +0100 (Mon, 09 Jan 2006)
New Revision: 888

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/AbstractCLITestCase.java
trunk/main/util/cli/src/test/net/dpml/cli/AbstractCommandLineTestCase.java

trunk/main/util/cli/src/test/net/dpml/cli/AbstractWriteableCommandLineTestCase.java
trunk/main/util/cli/src/test/net/dpml/cli/CommandLineDefaultsTest.java
trunk/main/util/cli/src/test/net/dpml/cli/DocumentationTest.java
trunk/main/util/cli/src/test/net/dpml/cli/PrecedenceTest.java
trunk/main/util/cli/src/test/net/dpml/cli/application/AntTest.java
trunk/main/util/cli/src/test/net/dpml/cli/application/CpTest.java
trunk/main/util/cli/src/test/net/dpml/cli/application/CvsTest.java
trunk/main/util/cli/src/test/net/dpml/cli/application/LsTest.java
trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug13886Test.java
trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug13935Test.java
trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug15046Test.java
trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug15648Test.java
trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug27575Test.java
trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug28005Test.java
trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug32533Test.java

trunk/main/util/cli/src/test/net/dpml/cli/bug/BugLoopingOptionLookAlikeTest.java
trunk/main/util/cli/src/test/net/dpml/cli/builder/ArgumentBuilderTest.java

trunk/main/util/cli/src/test/net/dpml/cli/builder/DefaultOptionBuilderTest.java

trunk/main/util/cli/src/test/net/dpml/cli/commandline/DefaultingCommandLineTest.java
trunk/main/util/cli/src/test/net/dpml/cli/commandline/ParserTest.java

trunk/main/util/cli/src/test/net/dpml/cli/commandline/PreferencesCommandLineTest.java

trunk/main/util/cli/src/test/net/dpml/cli/commandline/PropertiesCommandLineTest.java

trunk/main/util/cli/src/test/net/dpml/cli/commandline/WriteableCommandLineImplTest.java

trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractArgumentTestCase.java
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractGroupTestCase.java

trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractOptionTestCase.java

trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractParentTestCase.java
trunk/main/util/cli/src/test/net/dpml/cli/option/ArgumentTest.java
trunk/main/util/cli/src/test/net/dpml/cli/option/CommandTest.java
trunk/main/util/cli/src/test/net/dpml/cli/option/DefaultOptionTest.java
trunk/main/util/cli/src/test/net/dpml/cli/option/GroupTest.java
trunk/main/util/cli/src/test/net/dpml/cli/option/NestedGroupTest.java
trunk/main/util/cli/src/test/net/dpml/cli/option/ParentTest.java
trunk/main/util/cli/src/test/net/dpml/cli/option/PropertyOptionTest.java
trunk/main/util/cli/src/test/net/dpml/cli/option/SwitchTest.java
trunk/main/util/cli/src/test/net/dpml/cli/resource/ResourceHelperTest.java
trunk/main/util/cli/src/test/net/dpml/cli/util/ComparatorsTest.java
trunk/main/util/cli/src/test/net/dpml/cli/util/HelpFormatterTest.java

trunk/main/util/cli/src/test/net/dpml/cli/validation/ClassValidatorTest.java
trunk/main/util/cli/src/test/net/dpml/cli/validation/DateValidatorTest.java
trunk/main/util/cli/src/test/net/dpml/cli/validation/EnumValidatorTest.java
trunk/main/util/cli/src/test/net/dpml/cli/validation/FileValidatorTest.java

trunk/main/util/cli/src/test/net/dpml/cli/validation/NumberValidatorTest.java
trunk/main/util/cli/src/test/net/dpml/cli/validation/TimeZoneTestSuite.java
trunk/main/util/cli/src/test/net/dpml/cli/validation/URLValidatorTest.java

trunk/main/util/cli/src/test/net/dpml/cli/validation/protect/ProtectedClass.java

trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationBuilderTestCase.java

trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationSerializerTestCase.java

trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationTestCase.java

trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/SAXConfigurationHandlerTestCase.java
Log:
bring down the checkstyle issue count to something reasonable

Modified: trunk/main/util/cli/src/test/net/dpml/cli/AbstractCLITestCase.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/AbstractCLITestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/AbstractCLITestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,84 +1,191 @@
-/**
- * Copyright 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 net.dpml.cli;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public abstract class AbstractCLITestCase extends TestCase {
-
- public static List list() {
- return Collections.EMPTY_LIST;
- }
-
- public static List list(final Object args[]) {
- return new LinkedList(Arrays.asList(args));
- }
-
- public static List list(final Object arg0) {
- return list(new Object[] { arg0 });
- }
-
- public static List list(final Object arg0, final Object arg1) {
- return list(new Object[] { arg0, arg1 });
- }
-
- public static List list(final Object arg0, final Object arg1, final
Object arg2) {
- return list(new Object[] { arg0, arg1, arg2 });
- }
-
- public static List list(final Object arg0, final Object arg1, final
Object arg2, final Object arg3) {
- return list(new Object[] { arg0, arg1, arg2, arg3 });
- }
-
- public static List list(final Object arg0, final Object arg1, final
Object arg2, final Object arg3, final Object arg4) {
- return list(new Object[] { arg0, arg1, arg2, arg3, arg4 });
- }
-
- public static List list(final Object arg0, final Object arg1, final
Object arg2, final Object arg3, final Object arg4, final Object arg5) {
- return list(new Object[] { arg0, arg1, arg2, arg3, arg4, arg5 });
- }
-
- public static void assertListContentsEqual(final List expected, final
List found) {
-
- final Iterator e = expected.iterator();
- final Iterator f = found.iterator();
-
- while (e.hasNext() && f.hasNext()) {
- assertEquals(e.next(), f.next());
- }
-
- if (e.hasNext()) {
- fail("Expected more elements");
- }
-
- if (f.hasNext()) {
- fail("Found more elements");
- }
- }
-
- public static void assertContentsEqual(final Collection expected,
final Collection found) {
- assertTrue(expected.containsAll(found));
- assertTrue(found.containsAll(expected));
- assertEquals(expected.size(), found.size());
- }
-}
+/**
+ * Copyright 2004 The Apache Software Foundation
+ * Copyright 2005-2006 Stephen McConnell, Digital Product Meta Library
+ *
+ * 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 net.dpml.cli;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public abstract class AbstractCLITestCase extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static List list( )
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param args DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static List list( final Object[] args )
+ {
+ return new LinkedList( Arrays.asList( args ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param arg0 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static List list( final Object arg0 )
+ {
+ return list( new Object[]{arg0} );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param arg0 DOCUMENT ME!
+ * @param arg1 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static List list( final Object arg0, final Object arg1 )
+ {
+ return list( new Object[]{arg0, arg1} );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param arg0 DOCUMENT ME!
+ * @param arg1 DOCUMENT ME!
+ * @param arg2 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static List list( final Object arg0, final Object arg1,
+ final Object arg2 )
+ {
+ return list( new Object[]{arg0, arg1, arg2} );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param arg0 DOCUMENT ME!
+ * @param arg1 DOCUMENT ME!
+ * @param arg2 DOCUMENT ME!
+ * @param arg3 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static List list( final Object arg0, final Object arg1,
+ final Object arg2, final Object arg3 )
+ {
+ return list( new Object[]{arg0, arg1, arg2, arg3} );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param arg0 DOCUMENT ME!
+ * @param arg1 DOCUMENT ME!
+ * @param arg2 DOCUMENT ME!
+ * @param arg3 DOCUMENT ME!
+ * @param arg4 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static List list( final Object arg0, final Object arg1,
+ final Object arg2, final Object arg3, final Object arg4 )
+ {
+ return list( new Object[]{arg0, arg1, arg2, arg3, arg4} );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param arg0 DOCUMENT ME!
+ * @param arg1 DOCUMENT ME!
+ * @param arg2 DOCUMENT ME!
+ * @param arg3 DOCUMENT ME!
+ * @param arg4 DOCUMENT ME!
+ * @param arg5 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static List list( final Object arg0, final Object arg1,
+ final Object arg2, final Object arg3, final Object arg4,
+ final Object arg5 )
+ {
+ return list( new Object[]{arg0, arg1, arg2, arg3, arg4, arg5} );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param expected DOCUMENT ME!
+ * @param found DOCUMENT ME!
+ */
+ public static void assertListContentsEqual( final List expected,
+ final List found )
+ {
+ final Iterator e = expected.iterator( );
+ final Iterator f = found.iterator( );
+
+ while( e.hasNext( ) && f.hasNext( ) )
+ {
+ assertEquals( e.next( ), f.next( ) );
+ }
+
+ if( e.hasNext( ) )
+ {
+ fail( "Expected more elements" );
+ }
+
+ if( f.hasNext( ) )
+ {
+ fail( "Found more elements" );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param expected DOCUMENT ME!
+ * @param found DOCUMENT ME!
+ */
+ public static void assertContentsEqual( final Collection expected,
+ final Collection found )
+ {
+ assertTrue( expected.containsAll( found ) );
+ assertTrue( found.containsAll( expected ) );
+ assertEquals( expected.size( ), found.size( ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/AbstractCommandLineTestCase.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/AbstractCommandLineTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/AbstractCommandLineTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,511 +1,728 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-import net.dpml.cli.option.ArgumentTest;
-import net.dpml.cli.option.CommandTest;
-import net.dpml.cli.option.DefaultOptionTest;
-import net.dpml.cli.option.AbstractOptionTestCase;
-import net.dpml.cli.option.PropertyOption;
-import net.dpml.cli.option.SwitchTest;
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-public abstract class AbstractCommandLineTestCase
- extends AbstractCLITestCase {
- private static final ResourceHelper resources =
ResourceHelper.getResourceHelper();
- public final Option present =
- new
DefaultOptionBuilder().withLongName("present").withLongName("alsopresent").create();
- public final Option missing = new
DefaultOptionBuilder().withLongName("missing").create();
- public final Option multiple = new
DefaultOptionBuilder().withLongName("multiple").create();
- public final Option bool = new
DefaultOptionBuilder().withLongName("bool").create();
- public final Option root =
- new
GroupBuilder().withOption(present).withOption(missing).withOption(multiple)
- .withOption(bool).create();
- private CommandLine commandLine;
-
- protected abstract CommandLine createCommandLine();
-
- /*
- * @see TestCase#setUp()
- */
- public void setUp()
- throws Exception {
- super.setUp();
- commandLine = createCommandLine();
- }
-
- /*
- * Class to test for boolean hasOption(String)
- */
- public final void testHasOptionString() {
- assertTrue(commandLine.hasOption("--present"));
- assertTrue(commandLine.hasOption("--alsopresent"));
- assertFalse(commandLine.hasOption("--missing"));
- }
-
- /*
- * Class to test for boolean hasOption(Option)
- */
- public final void testHasOptionOption() {
- assertTrue(commandLine.hasOption(present));
- assertFalse(commandLine.hasOption(missing));
- }
-
- public final void testGetOption() {
- assertSame(present, commandLine.getOption("--present"));
- assertSame(present, commandLine.getOption("--alsopresent"));
-
- //TODO decide whether the following assertion is valid
- //assertSame(missing,commandLine.getOption("--missing"));
- }
-
- /*
- * Class to test for List getValues(String)
- */
- public final void testGetValuesString() {
- assertListContentsEqual(list("present value"),
commandLine.getValues("--present"));
- assertListContentsEqual(list("value 1", "value 2", "value 3"),
- commandLine.getValues("--multiple"));
- assertTrue(commandLine.getValues("--missing").isEmpty());
- }
-
- /*
- * Class to test for List getValues(String, List)
- */
- public final void testGetValuesStringList() {
- assertListContentsEqual(list("present value"),
commandLine.getValues("--present", null));
- assertListContentsEqual(list("present value"),
commandLine.getValues("--alsopresent", null));
- assertSame(commandLine.getValues("--missing",
Collections.EMPTY_LIST),
- Collections.EMPTY_LIST);
-
- final List def = Collections.singletonList("default value");
- assertSame(def, commandLine.getValues("--missing", def));
- }
-
- /*
- * Class to test for List getValues(Option)
- */
- public final void testGetValuesOption() {
- assertListContentsEqual(list("present value"),
commandLine.getValues(present));
- assertTrue(commandLine.getValues(missing).isEmpty());
- }
-
- /*
- * Class to test for List getValues(Option, List)
- */
- public final void testGetValuesOptionList() {
- assertListContentsEqual(list("present value"),
commandLine.getValues(present));
- assertSame(commandLine.getValues(missing, Collections.EMPTY_LIST),
Collections.EMPTY_LIST);
-
- final List defs = Collections.singletonList("custom default");
- assertSame(defs, commandLine.getValues(missing, defs));
- }
-
- /*
- * Class to test for Object getValue(String)
- */
- public final void testGetValueString() {
- assertEquals("present value", commandLine.getValue("--present"));
- assertEquals("present value", commandLine.getValue("--alsopresent"));
- assertNull(commandLine.getValue("--missing"));
-
- try {
- commandLine.getValue("--multiple");
- fail("expected IllegalStateException");
- } catch (IllegalStateException e) {
-
assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
- e.getMessage());
- }
- }
-
- /*
- * Class to test for Object getValue(String, Object)
- */
- public final void testGetValueStringObject() {
- assertEquals("present value", commandLine.getValue("--present",
"default value"));
- assertEquals("present value", commandLine.getValue("--alsopresent",
"default value"));
- assertEquals("default value", commandLine.getValue("--missing",
"default value"));
-
- try {
- commandLine.getValue("--multiple");
- fail("expected IllegalStateException");
- } catch (IllegalStateException e) {
-
assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
- e.getMessage());
- }
- }
-
- /*
- * Class to test for Object getValue(Option)
- */
- public final void testGetValueOption() {
- assertEquals("present value", commandLine.getValue(present));
- assertNull(commandLine.getValue(missing));
-
- try {
- commandLine.getValue(multiple);
- fail("expected IllegalStateException");
- } catch (IllegalStateException e) {
-
assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
- e.getMessage());
- }
- }
-
- /*
- * Class to test for Object getValue(Option, Object)
- */
- public final void testGetValueOptionObject() {
- assertEquals("present value", commandLine.getValue(present, "default
value"));
- assertEquals("default value", commandLine.getValue(missing, "default
value"));
-
- try {
- commandLine.getValue(multiple);
- fail("expected IllegalStateException");
- } catch (IllegalStateException e) {
-
assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
- e.getMessage());
- }
- }
-
- /*
- * Class to test for Boolean getSwitch(String)
- */
- public final void testGetSwitchString() {
- assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool"));
- assertNull(commandLine.getSwitch("--missing"));
- }
-
- /*
- * Class to test for Boolean getSwitch(String, Boolean)
- */
- public final void testGetSwitchStringBoolean() {
- assertEquals(Boolean.TRUE, commandLine.getSwitch("--bool",
Boolean.FALSE));
- assertEquals(Boolean.FALSE, commandLine.getSwitch("--missing",
Boolean.FALSE));
- }
-
- /*
- * Class to test for Boolean getSwitch(Option)
- */
- public final void testGetSwitchOption() {
- assertEquals(Boolean.TRUE, commandLine.getSwitch(bool));
- assertNull(commandLine.getSwitch(missing));
- }
-
- /*
- * Class to test for Boolean getSwitch(Option, Boolean)
- */
- public final void testGetSwitchOptionBoolean() {
- assertEquals(Boolean.TRUE, commandLine.getSwitch(bool,
Boolean.FALSE));
- assertEquals(Boolean.FALSE, commandLine.getSwitch(missing,
Boolean.FALSE));
- }
-
- /*
- * Class to test for String getProperty(String)
- */
- public final void testGetPropertyString() {
- assertEquals("present property", commandLine.getProperty("present"));
- assertNull(commandLine.getProperty("missing"));
- }
-
- /*
- * Class to test for String getProperty(String, String)
- */
- public final void testGetPropertyStringString() {
- assertEquals("present property", commandLine.getProperty("present",
"default property"));
- assertEquals("default property", commandLine.getProperty("missing",
"default property"));
- }
-
- public final void testGetProperties() {
- assertTrue(commandLine.getProperties().containsAll(list("present")));
- }
-
- /*
- * Class to test for int getOptionCount(String)
- */
- public final void testGetOptionCountString() {
- // one option, one switch
- assertTrue(1 <= commandLine.getOptionCount("--present"));
- assertTrue(1 <= commandLine.getOptionCount("--bool"));
- assertEquals(0, commandLine.getOptionCount("--missing"));
- }
-
- /*
- * Class to test for int getOptionCount(Option)
- */
- public final void testGetOptionCountOption() {
- // one option, one switch
- assertTrue(1 <= commandLine.getOptionCount(present));
- assertTrue(1 <= commandLine.getOptionCount(bool));
- assertEquals(0, commandLine.getOptionCount(missing));
- }
-
- public final void testGetOptions() {
- //TODO Implement getOptions().
- }
-
- public final void testGetOptionTriggers() {
- //TODO Implement getOptionTriggers().
- }
-
- // OLD TESTS FOLLOW
- public final void testProperties() {
- final Option option = new PropertyOption();
- final List args = AbstractCLITestCase.list();
- final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine(option, args);
-
- assertTrue(writeable.getProperties().isEmpty());
-
- writeable.addProperty("myprop", "myval");
- assertEquals(1, writeable.getProperties().size());
- assertEquals("myval", writeable.getProperty("myprop"));
-
- writeable.addProperty("myprop", "myval2");
- assertEquals(1, writeable.getProperties().size());
- assertEquals("myval2", writeable.getProperty("myprop"));
-
- writeable.addProperty("myprop2", "myval3");
- assertEquals(2, writeable.getProperties().size());
- assertEquals("myval3", writeable.getProperty("myprop2"));
- }
-
- public final void testOptions() {
- final Option option = new PropertyOption();
- final List args = AbstractCLITestCase.list();
- final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine(option, args);
-
- final Option start = CommandTest.buildStartCommand();
-
- assertFalse(writeable.hasOption(start));
- assertFalse(writeable.hasOption("start"));
- assertFalse(writeable.hasOption("go"));
-
- writeable.addOption(start);
-
- assertTrue(writeable.hasOption(start));
- assertTrue(writeable.hasOption("start"));
- assertTrue(writeable.hasOption("go"));
- }
-
- public final void testValues() {
- final Option option = new PropertyOption();
- final List args = AbstractCLITestCase.list();
- final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine(option, args);
-
- final Option start = CommandTest.buildStartCommand();
-
- assertNull(writeable.getValue(start));
- assertTrue(writeable.getValues(start).isEmpty());
-
- writeable.addOption(start);
-
- assertTrue(writeable.getValues(start).isEmpty());
-
- writeable.addValue(start, "file1");
-
- assertEquals("file1", writeable.getValue(start));
- assertEquals("file1", writeable.getValue("start"));
- assertEquals("file1", writeable.getValue("go"));
- assertEquals(1, writeable.getValues(start).size());
- assertEquals(1, writeable.getValues("start").size());
- assertEquals(1, writeable.getValues("go").size());
- assertTrue(writeable.getValues(start).contains("file1"));
- assertTrue(writeable.getValues("start").contains("file1"));
- assertTrue(writeable.getValues("go").contains("file1"));
-
- writeable.addValue(start, "file2");
-
- try {
- writeable.getValue(start);
- fail("Cannot get single value if multiple are present");
- } catch (IllegalStateException ise) {
-
assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
- ise.getMessage());
- }
-
- try {
- writeable.getValue("start");
- fail("Cannot get single value if multiple are present");
- } catch (IllegalStateException ise) {
-
assertEquals(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_VALUES),
- ise.getMessage());
- }
-
- writeable.getValues(start).add("file3");
- }
-
- public final void testSwitches() {
- final Option option = new PropertyOption();
- final List args = AbstractCLITestCase.list();
- final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine(option, args);
-
- final Option start = CommandTest.buildStartCommand();
-
- assertNull(writeable.getSwitch(start));
- assertNull(writeable.getSwitch("start"));
- assertNull(writeable.getSwitch("go"));
-
- writeable.addSwitch(start, true);
-
- try {
- writeable.addSwitch(start, false);
- fail("Switch cannot be changed");
- } catch (IllegalStateException ise) {
-
assertEquals(resources.getMessage(ResourceConstants.SWITCH_ALREADY_SET),
- ise.getMessage());
- }
- }
-
- public final void testSwitches_True() {
- final Option option = new PropertyOption();
- final List args = AbstractCLITestCase.list();
- final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine(option, args);
-
- final Option start = CommandTest.buildStartCommand();
-
- writeable.addSwitch(start, true);
- assertSame(Boolean.TRUE, writeable.getSwitch(start));
- }
-
- public final void testSwitches_False() {
- final Option option = new PropertyOption();
- final List args = AbstractCLITestCase.list();
- final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine(option, args);
-
- final Option start = CommandTest.buildStartCommand();
-
- writeable.addSwitch(start, false);
- assertSame(Boolean.FALSE, writeable.getSwitch(start));
- }
-
- // public final void testLooksLikeOption() {
- // final Option option = new PropertyOption();
- // final List args = AbstractOptionTestCase.list();
- // final WriteableCommandLine commandLine =
- // AbstractOptionTestCase.commandLine(option, args);
- //
- // assertTrue(commandLine.looksLikeOption("-D"));
- // assertFalse(commandLine.looksLikeOption("--help"));
- // assertFalse(commandLine.looksLikeOption("+display"));
- // assertFalse(commandLine.looksLikeOption("myprefix"));
- // assertFalse(commandLine.looksLikeOption("myprefix2"));
- // assertFalse(commandLine.looksLikeOption("myprefference"));
- // assertFalse(commandLine.looksLikeOption("/SCANDISK"));
- // assertFalse(commandLine.looksLikeOption("update"));
- // }
- public final void testGetOptions_Order()
- throws OptionException {
- final Option help = DefaultOptionTest.buildHelpOption();
- final Option login = CommandTest.buildLoginCommand();
- final Option targets = ArgumentTest.buildTargetsArgument();
-
- final Group group =
- new
GroupBuilder().withOption(help).withOption(login).withOption(targets).create();
-
- final Parser parser = new Parser();
- parser.setGroup(group);
-
- final CommandLine cl =
- parser.parse(new String[] { "login", "rob", "--help", "target1",
"target2" });
-
- final Iterator i = cl.getOptions().iterator();
-
- assertSame(login, i.next());
- assertSame(help, i.next());
- assertSame(targets, i.next());
- assertSame(targets, i.next());
- assertFalse(i.hasNext());
- }
-
- public final void testGetOptionCount()
- throws OptionException {
- final Option help = DefaultOptionTest.buildHelpOption();
- final Option login = CommandTest.buildLoginCommand();
- final Option targets = ArgumentTest.buildTargetsArgument();
- final Option display = SwitchTest.buildDisplaySwitch();
-
- final Group group =
- new
GroupBuilder().withOption(help).withOption(login).withOption(targets)
- .withOption(display).create();
-
- final Parser parser = new Parser();
- parser.setGroup(group);
-
- final CommandLine cl =
- parser.parse(new String[] {
- "--help", "login", "rob", "+display", "--help",
"--help", "target1",
- "target2"
- });
-
- assertEquals(1, cl.getOptionCount(login));
- assertEquals(3, cl.getOptionCount(help));
- assertEquals(2, cl.getOptionCount(targets));
- assertEquals(1, cl.getOptionCount(display));
- }
-
- public final void testGetOptionCount_Strings()
- throws OptionException {
- final Option help = DefaultOptionTest.buildHelpOption();
- final Option login = CommandTest.buildLoginCommand();
- final Option targets = ArgumentTest.buildTargetsArgument();
- final Option display = SwitchTest.buildDisplaySwitch();
-
- final Group group =
- new
GroupBuilder().withOption(help).withOption(login).withOption(targets)
- .withOption(display).create();
-
- final Parser parser = new Parser();
- parser.setGroup(group);
-
- final CommandLine cl =
- parser.parse(new String[] {
- "--help", "login", "rob", "+display", "--help",
"--help", "target1",
- "target2"
- });
-
- assertEquals(1, cl.getOptionCount("login"));
- assertEquals(3, cl.getOptionCount("-?"));
- assertEquals(1, cl.getOptionCount("+display"));
- }
-
- public final void testOptionAsArgument()
- throws OptionException {
- final Option p = new
DefaultOptionBuilder().withShortName("p").create();
- final Argument argument = new ArgumentBuilder().create();
- final Option withArgument =
- new
DefaultOptionBuilder().withShortName("attr").withArgument(argument).create();
-
- final Group group = new
GroupBuilder().withOption(p).withOption(withArgument).create();
-
- final Parser parser = new Parser();
- parser.setGroup(group);
-
- final CommandLine cl = parser.parse(new String[] { "-p", "-attr",
"p" });
-
- assertEquals(1, cl.getOptionCount("-p"));
- assertTrue(cl.hasOption("-p"));
- assertTrue(cl.hasOption("-attr"));
- assertTrue(cl.getValue("-attr").equals("p"));
- }
-}
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli;
+
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+import net.dpml.cli.option.AbstractOptionTestCase;
+import net.dpml.cli.option.ArgumentTest;
+import net.dpml.cli.option.CommandTest;
+import net.dpml.cli.option.DefaultOptionTest;
+import net.dpml.cli.option.PropertyOption;
+import net.dpml.cli.option.SwitchTest;
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public abstract class AbstractCommandLineTestCase extends AbstractCLITestCase
+{
+ private static final ResourceHelper resources =
ResourceHelper.getResourceHelper( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final Option m_present = new DefaultOptionBuilder(
).withLongName(
+ "present" ).withLongName( "alsopresent" ).create( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final Option m_missing = new DefaultOptionBuilder(
).withLongName(
+ "missing" ).create( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final Option m_multiple = new DefaultOptionBuilder(
).withLongName(
+ "multiple" ).create( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final Option m_bool = new DefaultOptionBuilder( ).withLongName(
+ "bool" ).create( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final Option m_root = new GroupBuilder( ).withOption( m_present )
+ .withOption( m_missing )
+ .withOption( m_multiple
)
+ .withOption( m_bool )
+ .create( );
+ private CommandLine m_commandLine;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected abstract CommandLine createCommandLine( );
+
+ /*
+ * @see TestCase#setUp()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void setUp( ) throws Exception
+ {
+ super.setUp( );
+ m_commandLine = createCommandLine( );
+ }
+
+ /*
+ * Class to test for boolean hasOption(String)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testHasOptionString( )
+ {
+ assertTrue( m_commandLine.hasOption( "--present" ) );
+ assertTrue( m_commandLine.hasOption( "--alsopresent" ) );
+ assertFalse( m_commandLine.hasOption( "--missing" ) );
+ }
+
+ /*
+ * Class to test for boolean hasOption(Option)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testHasOptionOption( )
+ {
+ assertTrue( m_commandLine.hasOption( m_present ) );
+ assertFalse( m_commandLine.hasOption( m_missing ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetOption( )
+ {
+ assertSame( m_present, m_commandLine.getOption( "--present" ) );
+ assertSame( m_present, m_commandLine.getOption( "--alsopresent" ) );
+
+ //TODO decide whether the following assertion is valid
+ //assertSame( missing,m_commandLine.getOption( "--missing" ) );
+ }
+
+ /*
+ * Class to test for List getValues(String)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetValuesString( )
+ {
+ assertListContentsEqual( list( "present value" ),
+ m_commandLine.getValues( "--present" ) );
+ assertListContentsEqual( list( "value 1", "value 2", "value 3" ),
+ m_commandLine.getValues( "--multiple" ) );
+ assertTrue( m_commandLine.getValues( "--missing" ).isEmpty( ) );
+ }
+
+ /*
+ * Class to test for List getValues(String, List)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetValuesStringList( )
+ {
+ assertListContentsEqual( list( "present value" ),
+ m_commandLine.getValues( "--present", null ) );
+ assertListContentsEqual( list( "present value" ),
+ m_commandLine.getValues( "--alsopresent", null ) );
+ assertSame( m_commandLine.getValues( "--missing",
Collections.EMPTY_LIST ),
+ Collections.EMPTY_LIST );
+
+ final List def = Collections.singletonList( "default value" );
+ assertSame( def, m_commandLine.getValues( "--missing", def ) );
+ }
+
+ /*
+ * Class to test for List getValues(Option)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetValuesOption( )
+ {
+ assertListContentsEqual( list( "present value" ),
+ m_commandLine.getValues( m_present ) );
+ assertTrue( m_commandLine.getValues( m_missing ).isEmpty( ) );
+ }
+
+ /*
+ * Class to test for List getValues(Option, List)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetValuesOptionList( )
+ {
+ assertListContentsEqual( list( "present value" ),
+ m_commandLine.getValues( m_present ) );
+ assertSame( m_commandLine.getValues( m_missing,
Collections.EMPTY_LIST ),
+ Collections.EMPTY_LIST );
+
+ final List defs = Collections.singletonList( "custom default" );
+ assertSame( defs, m_commandLine.getValues( m_missing, defs ) );
+ }
+
+ /*
+ * Class to test for Object getValue(String)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetValueString( )
+ {
+ assertEquals( "present value", m_commandLine.getValue( "--present" )
);
+ assertEquals( "present value", m_commandLine.getValue(
"--alsopresent" ) );
+ assertNull( m_commandLine.getValue( "--missing" ) );
+
+ try
+ {
+ m_commandLine.getValue( "--multiple" );
+ fail( "expected IllegalStateException" );
+ }
+ catch( IllegalStateException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.ARGUMENT_TOO_MANY_VALUES ),
+ e.getMessage( ) );
+ }
+ }
+
+ /*
+ * Class to test for Object getValue(String, Object)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetValueStringObject( )
+ {
+ assertEquals( "present value",
+ m_commandLine.getValue( "--present", "default value" ) );
+ assertEquals( "present value",
+ m_commandLine.getValue( "--alsopresent", "default value" ) );
+ assertEquals( "default value",
+ m_commandLine.getValue( "--missing", "default value" ) );
+
+ try
+ {
+ m_commandLine.getValue( "--multiple" );
+ fail( "expected IllegalStateException" );
+ }
+ catch( IllegalStateException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.ARGUMENT_TOO_MANY_VALUES ),
+ e.getMessage( ) );
+ }
+ }
+
+ /*
+ * Class to test for Object getValue(Option)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetValueOption( )
+ {
+ assertEquals( "present value", m_commandLine.getValue( m_present ) );
+ assertNull( m_commandLine.getValue( m_missing ) );
+
+ try
+ {
+ m_commandLine.getValue( m_multiple );
+ fail( "expected IllegalStateException" );
+ }
+ catch( IllegalStateException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.ARGUMENT_TOO_MANY_VALUES ),
+ e.getMessage( ) );
+ }
+ }
+
+ /*
+ * Class to test for Object getValue(Option, Object)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetValueOptionObject( )
+ {
+ assertEquals( "present value",
+ m_commandLine.getValue( m_present, "default value" ) );
+ assertEquals( "default value",
+ m_commandLine.getValue( m_missing, "default value" ) );
+
+ try
+ {
+ m_commandLine.getValue( m_multiple );
+ fail( "expected IllegalStateException" );
+ }
+ catch( IllegalStateException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.ARGUMENT_TOO_MANY_VALUES ),
+ e.getMessage( ) );
+ }
+ }
+
+ /*
+ * Class to test for Boolean getSwitch(String)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetSwitchString( )
+ {
+ assertEquals( Boolean.TRUE, m_commandLine.getSwitch( "--bool" ) );
+ assertNull( m_commandLine.getSwitch( "--missing" ) );
+ }
+
+ /*
+ * Class to test for Boolean getSwitch(String, Boolean)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetSwitchStringBoolean( )
+ {
+ assertEquals( Boolean.TRUE,
+ m_commandLine.getSwitch( "--bool", Boolean.FALSE ) );
+ assertEquals( Boolean.FALSE,
+ m_commandLine.getSwitch( "--missing", Boolean.FALSE ) );
+ }
+
+ /*
+ * Class to test for Boolean getSwitch(Option)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetSwitchOption( )
+ {
+ assertEquals( Boolean.TRUE, m_commandLine.getSwitch( m_bool ) );
+ assertNull( m_commandLine.getSwitch( m_missing ) );
+ }
+
+ /*
+ * Class to test for Boolean getSwitch(Option, Boolean)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetSwitchOptionBoolean( )
+ {
+ assertEquals( Boolean.TRUE,
+ m_commandLine.getSwitch( m_bool, Boolean.FALSE ) );
+ assertEquals( Boolean.FALSE,
+ m_commandLine.getSwitch( m_missing, Boolean.FALSE ) );
+ }
+
+ /*
+ * Class to test for String getProperty(String)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetPropertyString( )
+ {
+ assertEquals( "present property", m_commandLine.getProperty(
"present" ) );
+ assertNull( m_commandLine.getProperty( "missing" ) );
+ }
+
+ /*
+ * Class to test for String getProperty(String, String)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetPropertyStringString( )
+ {
+ assertEquals( "present property",
+ m_commandLine.getProperty( "present", "default property" ) );
+ assertEquals( "default property",
+ m_commandLine.getProperty( "missing", "default property" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetProperties( )
+ {
+ assertTrue( m_commandLine.getProperties( )
+ .containsAll( list( "present" ) ) );
+ }
+
+ /*
+ * Class to test for int getOptionCount(String)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetOptionCountString( )
+ {
+ // one option, one switch
+ assertTrue( 1 <= m_commandLine.getOptionCount( "--present" ) );
+ assertTrue( 1 <= m_commandLine.getOptionCount( "--bool" ) );
+ assertEquals( 0, m_commandLine.getOptionCount( "--missing" ) );
+ }
+
+ /*
+ * Class to test for int getOptionCount(Option)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetOptionCountOption( )
+ {
+ // one option, one switch
+ assertTrue( 1 <= m_commandLine.getOptionCount( m_present ) );
+ assertTrue( 1 <= m_commandLine.getOptionCount( m_bool ) );
+ assertEquals( 0, m_commandLine.getOptionCount( m_missing ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetOptions( )
+ {
+ //TODO Implement getOptions().
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testGetOptionTriggers( )
+ {
+ //TODO Implement getOptionTriggers().
+ }
+
+ // OLD TESTS FOLLOW
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testProperties( )
+ {
+ final Option option = new PropertyOption( );
+ final List args = AbstractCLITestCase.list( );
+ final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine( option,
+ args );
+
+ assertTrue( writeable.getProperties( ).isEmpty( ) );
+
+ writeable.addProperty( "myprop", "myval" );
+ assertEquals( 1, writeable.getProperties( ).size( ) );
+ assertEquals( "myval", writeable.getProperty( "myprop" ) );
+
+ writeable.addProperty( "myprop", "myval2" );
+ assertEquals( 1, writeable.getProperties( ).size( ) );
+ assertEquals( "myval2", writeable.getProperty( "myprop" ) );
+
+ writeable.addProperty( "myprop2", "myval3" );
+ assertEquals( 2, writeable.getProperties( ).size( ) );
+ assertEquals( "myval3", writeable.getProperty( "myprop2" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testOptions( )
+ {
+ final Option option = new PropertyOption( );
+ final List args = AbstractCLITestCase.list( );
+ final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine( option,
+ args );
+
+ final Option start = CommandTest.buildStartCommand( );
+
+ assertFalse( writeable.hasOption( start ) );
+ assertFalse( writeable.hasOption( "start" ) );
+ assertFalse( writeable.hasOption( "go" ) );
+
+ writeable.addOption( start );
+
+ assertTrue( writeable.hasOption( start ) );
+ assertTrue( writeable.hasOption( "start" ) );
+ assertTrue( writeable.hasOption( "go" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testValues( )
+ {
+ final Option option = new PropertyOption( );
+ final List args = AbstractCLITestCase.list( );
+ final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine( option,
+ args );
+
+ final Option start = CommandTest.buildStartCommand( );
+
+ assertNull( writeable.getValue( start ) );
+ assertTrue( writeable.getValues( start ).isEmpty( ) );
+
+ writeable.addOption( start );
+
+ assertTrue( writeable.getValues( start ).isEmpty( ) );
+
+ writeable.addValue( start, "file1" );
+
+ assertEquals( "file1", writeable.getValue( start ) );
+ assertEquals( "file1", writeable.getValue( "start" ) );
+ assertEquals( "file1", writeable.getValue( "go" ) );
+ assertEquals( 1, writeable.getValues( start ).size( ) );
+ assertEquals( 1, writeable.getValues( "start" ).size( ) );
+ assertEquals( 1, writeable.getValues( "go" ).size( ) );
+ assertTrue( writeable.getValues( start ).contains( "file1" ) );
+ assertTrue( writeable.getValues( "start" ).contains( "file1" ) );
+ assertTrue( writeable.getValues( "go" ).contains( "file1" ) );
+
+ writeable.addValue( start, "file2" );
+
+ try
+ {
+ writeable.getValue( start );
+ fail( "Cannot get single value if multiple are present" );
+ }
+ catch( IllegalStateException ise )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.ARGUMENT_TOO_MANY_VALUES ),
+ ise.getMessage( ) );
+ }
+
+ try
+ {
+ writeable.getValue( "start" );
+ fail( "Cannot get single value if multiple are present" );
+ }
+ catch( IllegalStateException ise )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.ARGUMENT_TOO_MANY_VALUES ),
+ ise.getMessage( ) );
+ }
+
+ writeable.getValues( start ).add( "file3" );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testSwitches( )
+ {
+ final Option option = new PropertyOption( );
+ final List args = AbstractCLITestCase.list( );
+ final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine( option,
+ args );
+
+ final Option start = CommandTest.buildStartCommand( );
+
+ assertNull( writeable.getSwitch( start ) );
+ assertNull( writeable.getSwitch( "start" ) );
+ assertNull( writeable.getSwitch( "go" ) );
+
+ writeable.addSwitch( start, true );
+
+ try
+ {
+ writeable.addSwitch( start, false );
+ fail( "Switch cannot be changed" );
+ }
+ catch( IllegalStateException ise )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.SWITCH_ALREADY_SET ), ise.getMessage(
) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testSwitches_True( )
+ {
+ final Option option = new PropertyOption( );
+ final List args = AbstractCLITestCase.list( );
+ final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine( option,
+ args );
+
+ final Option start = CommandTest.buildStartCommand( );
+
+ writeable.addSwitch( start, true );
+ assertSame( Boolean.TRUE, writeable.getSwitch( start ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testSwitches_False( )
+ {
+ final Option option = new PropertyOption( );
+ final List args = AbstractCLITestCase.list( );
+ final WriteableCommandLine writeable =
AbstractOptionTestCase.commandLine( option,
+ args );
+
+ final Option start = CommandTest.buildStartCommand( );
+
+ writeable.addSwitch( start, false );
+ assertSame( Boolean.FALSE, writeable.getSwitch( start ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public final void testGetOptions_Order( ) throws OptionException
+ {
+ final Option help = DefaultOptionTest.buildHelpOption( );
+ final Option login = CommandTest.buildLoginCommand( );
+ final Option targets = ArgumentTest.buildTargetsArgument( );
+
+ final Group group = new GroupBuilder( ).withOption( help )
+ .withOption( login )
+ .withOption( targets
).create( );
+
+ final Parser parser = new Parser( );
+ parser.setGroup( group );
+
+ final CommandLine cl = parser.parse( new String[]
+ {
+ "login", "rob", "--help", "target1", "target2"
+ } );
+
+ final Iterator i = cl.getOptions( ).iterator( );
+
+ assertSame( login, i.next( ) );
+ assertSame( help, i.next( ) );
+ assertSame( targets, i.next( ) );
+ assertSame( targets, i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public final void testGetOptionCount( ) throws OptionException
+ {
+ final Option help = DefaultOptionTest.buildHelpOption( );
+ final Option login = CommandTest.buildLoginCommand( );
+ final Option targets = ArgumentTest.buildTargetsArgument( );
+ final Option display = SwitchTest.buildDisplaySwitch( );
+
+ final Group group = new GroupBuilder( ).withOption( help )
+ .withOption( login )
+ .withOption( targets )
+ .withOption( display
).create( );
+
+ final Parser parser = new Parser( );
+ parser.setGroup( group );
+
+ final CommandLine cl = parser.parse( new String[]
+ {
+ "--help", "login", "rob", "+display", "--help", "--help",
+ "target1", "target2"
+ } );
+
+ assertEquals( 1, cl.getOptionCount( login ) );
+ assertEquals( 3, cl.getOptionCount( help ) );
+ assertEquals( 2, cl.getOptionCount( targets ) );
+ assertEquals( 1, cl.getOptionCount( display ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public final void testGetOptionCount_Strings( ) throws OptionException
+ {
+ final Option help = DefaultOptionTest.buildHelpOption( );
+ final Option login = CommandTest.buildLoginCommand( );
+ final Option targets = ArgumentTest.buildTargetsArgument( );
+ final Option display = SwitchTest.buildDisplaySwitch( );
+
+ final Group group = new GroupBuilder( ).withOption( help )
+ .withOption( login )
+ .withOption( targets )
+ .withOption( display
).create( );
+
+ final Parser parser = new Parser( );
+ parser.setGroup( group );
+
+ final CommandLine cl = parser.parse( new String[]
+ {
+ "--help", "login", "rob", "+display", "--help", "--help",
+ "target1", "target2"
+ } );
+
+ assertEquals( 1, cl.getOptionCount( "login" ) );
+ assertEquals( 3, cl.getOptionCount( "-?" ) );
+ assertEquals( 1, cl.getOptionCount( "+display" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public final void testOptionAsArgument( ) throws OptionException
+ {
+ final Option p = new DefaultOptionBuilder( ).withShortName( "p" )
+ .create( );
+ final Argument argument = new ArgumentBuilder( ).create( );
+ final Option withArgument = new DefaultOptionBuilder(
).withShortName(
+ "attr" ).withArgument( argument ).create( );
+
+ final Group group = new GroupBuilder( ).withOption( p )
+ .withOption( withArgument )
+ .create( );
+
+ final Parser parser = new Parser( );
+ parser.setGroup( group );
+
+ final CommandLine cl = parser.parse( new String[]{"-p", "-attr",
"p"} );
+
+ assertEquals( 1, cl.getOptionCount( "-p" ) );
+ assertTrue( cl.hasOption( "-p" ) );
+ assertTrue( cl.hasOption( "-attr" ) );
+ assertTrue( cl.getValue( "-attr" ).equals( "p" ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/AbstractWriteableCommandLineTestCase.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/AbstractWriteableCommandLineTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/AbstractWriteableCommandLineTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,94 +1,130 @@
-/**
- * Copyright 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 net.dpml.cli;
-
-import net.dpml.cli.option.ArgumentTest;
-
-/**
- * @author Rob Oxspring
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-public abstract class AbstractWriteableCommandLineTestCase extends
AbstractCommandLineTestCase {
-
- private WriteableCommandLine writeable;
-
- protected abstract WriteableCommandLine createWriteableCommandLine();
-
- /* (non-Javadoc)
- * @see net.dpml.cli.CommandLineTest#createCommandLine()
- */
- protected final CommandLine createCommandLine() {
- final WriteableCommandLine cl = createWriteableCommandLine();
- cl.addOption(present);
- cl.addProperty("present","present property");
- cl.addSwitch(bool,true);
- cl.addValue(present,"present value");
- cl.addOption(multiple);
- cl.addValue(multiple,"value 1");
- cl.addValue(multiple,"value 2");
- cl.addValue(multiple,"value 3");
- return cl;
- }
-
- /*
- * @see CommandLineTest#setUp()
- */
- public void setUp() throws Exception {
- super.setUp();
- writeable = createWriteableCommandLine();
- }
- public final void testAddOption() {
- assertFalse(writeable.hasOption(present));
- writeable.addOption(present);
- assertTrue(writeable.hasOption(present));
- }
- public final void testAddValue() {
- assertFalse(writeable.hasOption(present));
- assertTrue(writeable.getValues(present).isEmpty());
- writeable.addValue(present,"value");
-
assertContentsEqual(list("value"),writeable.getValues(present));
-
- // most options shouldn't appear due to adding values
- assertFalse(writeable.hasOption(present));
-
- final Argument arg = ArgumentTest.buildHostArgument();
-
- assertFalse(writeable.hasOption(arg));
- assertTrue(writeable.getValues(arg).isEmpty());
- writeable.addValue(arg,"value");
- assertContentsEqual(list("value"),writeable.getValues(arg));
-
- // Arguments should force the option present
- assertTrue(writeable.hasOption(arg));
- }
- public final void testAddSwitch() {
- assertFalse(writeable.hasOption(present));
- assertNull(writeable.getSwitch(present));
- writeable.addSwitch(present,true);
- assertEquals(Boolean.TRUE,writeable.getSwitch(present));
- assertTrue(writeable.hasOption(present));
- }
- public final void testAddProperty() {
- assertNull(writeable.getProperty("present"));
- writeable.addProperty("present","present value");
- assertEquals("present
value",writeable.getProperty("present"));
- }
- public final void testLooksLikeOption() {
- //TODO Implement looksLikeOption().
- }
-}
+/**
+ * Copyright 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 net.dpml.cli;
+
+import net.dpml.cli.option.ArgumentTest;
+
+/**
+ * @author Rob Oxspring
+ *
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+public abstract class AbstractWriteableCommandLineTestCase
+ extends AbstractCommandLineTestCase
+{
+ private WriteableCommandLine m_writeable;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected abstract WriteableCommandLine createWriteableCommandLine( );
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.CommandLineTest#createCommandLine()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected final CommandLine createCommandLine( )
+ {
+ final WriteableCommandLine cl = createWriteableCommandLine( );
+ cl.addOption( m_present );
+ cl.addProperty( "present", "present property" );
+ cl.addSwitch( m_bool, true );
+ cl.addValue( m_present, "present value" );
+ cl.addOption( m_multiple );
+ cl.addValue( m_multiple, "value 1" );
+ cl.addValue( m_multiple, "value 2" );
+ cl.addValue( m_multiple, "value 3" );
+
+ return cl;
+ }
+
+ /*
+ * @see CommandLineTest#setUp()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void setUp( ) throws Exception
+ {
+ super.setUp( );
+ m_writeable = createWriteableCommandLine( );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testAddOption( )
+ {
+ assertFalse( m_writeable.hasOption( m_present ) );
+ m_writeable.addOption( m_present );
+ assertTrue( m_writeable.hasOption( m_present ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testAddValue( )
+ {
+ assertFalse( m_writeable.hasOption( m_present ) );
+ assertTrue( m_writeable.getValues( m_present ).isEmpty( ) );
+ m_writeable.addValue( m_present, "value" );
+ assertContentsEqual( list( "value" ), m_writeable.getValues(
m_present ) );
+
+ // most options shouldn't appear due to adding values
+ assertFalse( m_writeable.hasOption( m_present ) );
+
+ final Argument arg = ArgumentTest.buildHostArgument( );
+
+ assertFalse( m_writeable.hasOption( arg ) );
+ assertTrue( m_writeable.getValues( arg ).isEmpty( ) );
+ m_writeable.addValue( arg, "value" );
+ assertContentsEqual( list( "value" ), m_writeable.getValues( arg ) );
+
+ // Arguments should force the option present
+ assertTrue( m_writeable.hasOption( arg ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testAddSwitch( )
+ {
+ assertFalse( m_writeable.hasOption( m_present ) );
+ assertNull( m_writeable.getSwitch( m_present ) );
+ m_writeable.addSwitch( m_present, true );
+ assertEquals( Boolean.TRUE, m_writeable.getSwitch( m_present ) );
+ assertTrue( m_writeable.hasOption( m_present ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testAddProperty( )
+ {
+ assertNull( m_writeable.getProperty( "present" ) );
+ m_writeable.addProperty( "present", "present value" );
+ assertEquals( "present value", m_writeable.getProperty( "present" )
);
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/CommandLineDefaultsTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/CommandLineDefaultsTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/CommandLineDefaultsTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,250 +1,333 @@
-/**
- * Copyright 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 net.dpml.cli;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.SwitchBuilder;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-
-/**
- * Tests the interaction of command line values and defaults supplied in
different ways.
- *
- * Tests marked _Parsed involve values parsed from a command line.
- *
- * Tests marked _Method involve defaults supplied in the query method.
- *
- * Tests marked _Option involce defaults specified in the model.
- *
- * @author Rob Oxspring
- */
-public class CommandLineDefaultsTest extends TestCase {
-
- /*
- * utils to grab the default from the method
- */
-
- private Object methodSwitch(WriteableCommandLine cl, Option o, Boolean
bool) {
- return cl.getSwitch(o, bool);
- }
-
- private Object methodSwitchNull(WriteableCommandLine cl, Option o) {
- return methodSwitch(cl, o, null);
- }
-
- private Object methodSwitchOff(WriteableCommandLine cl, Option o) {
- return methodSwitch(cl, o, Boolean.FALSE);
- }
-
- private Object methodSwitchOn(WriteableCommandLine cl, Option o) {
- return methodSwitch(cl, o, Boolean.TRUE);
- }
-
- private Object methodValueMissing(WriteableCommandLine cl, Option o) {
- return cl.getValue(o);
- }
-
- private Object methodValuePresent(WriteableCommandLine cl, Option o) {
- return cl.getValue(o, "method");
- }
-
- /*
- * utils to grab the default from the option model
- */
-
- private Option optionSwitch(Boolean bool) {
- return new SwitchBuilder().withName("switch").withSwitchDefault(bool)
- .create();
- }
-
- private Option optionSwitchNull() {
- return optionSwitch(null);
- }
-
- private Option optionSwitchOff() {
- return optionSwitch(Boolean.FALSE);
- }
-
- private Option optionSwitchOn() {
- return optionSwitch(Boolean.TRUE);
- }
-
- private Option optionValueMissing() {
- return new ArgumentBuilder().create();
- }
-
- private Option optionValuePresent() {
- return new ArgumentBuilder().withDefaults(
- Arrays.asList(new String[] { "option" })).create();
- }
-
- /*
- * utils to grab the input from the command line
- */
-
- private WriteableCommandLine parsedSwitch(Option o, Boolean bool) {
- final List args;
- if (bool == null) {
- args = Collections.EMPTY_LIST;
- } else {
- args = Collections
- .singletonList(String.valueOf(bool).toLowerCase());
- }
- WriteableCommandLine cl = new WriteableCommandLineImpl(o, args);
- o.defaults(cl);
- if (bool != null) {
- cl.addSwitch(o, bool.booleanValue());
- }
- return cl;
- }
-
- private WriteableCommandLine parsedSwitchNull(Option o) {
- return parsedSwitch(o, null);
- }
-
- private WriteableCommandLine parsedSwitchOn(Option o) {
- return parsedSwitch(o, Boolean.TRUE);
- }
-
- private WriteableCommandLine parsedValueMissing(Option o) {
- WriteableCommandLine cl = new WriteableCommandLineImpl(o,
- Collections.EMPTY_LIST);
- o.defaults(cl);
- return cl;
- }
-
- private WriteableCommandLine parsedValuePresent(Option o) {
- WriteableCommandLine cl = new WriteableCommandLineImpl(o, Arrays
- .asList(new String[] { "parsed" }));
- o.defaults(cl);
- cl.addValue(o, "parsed");
- return cl;
- }
-
- /*
- * tests
- */
-
- public void testSwitch_Method() {
- final Option o = optionSwitchNull();
- final WriteableCommandLine cl = parsedSwitchNull(o);
- final Object v = methodSwitchOn(cl, o);
- assertEquals(Boolean.TRUE, v);
- }
-
- public void testSwitch_Method_Option() {
- final Option o = optionSwitchOff();
- final WriteableCommandLine cl = parsedSwitchNull(o);
- final Object v = methodSwitchOn(cl, o);
- assertEquals(Boolean.TRUE, v);
- }
-
- public void testSwitch_Option() {
- final Option o = optionSwitchOn();
- final WriteableCommandLine cl = parsedSwitchNull(o);
- final Object v = methodSwitchNull(cl, o);
- assertEquals(Boolean.TRUE, v);
- }
-
- public void testSwitch_Parsed() {
- final Option o = optionSwitchNull();
- final WriteableCommandLine cl = parsedSwitchOn(o);
- final Object v = methodSwitchNull(cl, o);
- assertEquals(Boolean.TRUE, v);
- }
-
- public void testSwitch_Parsed_Method() {
- final Option o = optionSwitchOff();
- final WriteableCommandLine cl = parsedSwitchOn(o);
- final Object v = methodSwitchNull(cl, o);
- assertEquals(Boolean.TRUE, v);
- }
-
- public void testSwitch_Parsed_Method_Option() {
- final Option o = optionSwitchOff();
- final WriteableCommandLine cl = parsedSwitchOn(o);
- final Object v = methodSwitchOff(cl, o);
- assertEquals(Boolean.TRUE, v);
- }
-
- public void testSwitch_Parsed_Option() {
- final Option o = optionSwitchOff();
- final WriteableCommandLine cl = parsedSwitchOn(o);
- final Object v = methodSwitchNull(cl, o);
- assertEquals(Boolean.TRUE, v);
- }
-
- public void testValues() {
- final Option o = optionValueMissing();
- final WriteableCommandLine cl = parsedValueMissing(o);
- final Object v = methodValueMissing(cl, o);
- assertNull(v);
- }
-
- public void testValues_Method() {
- final Option o = optionValueMissing();
- final WriteableCommandLine cl = parsedValueMissing(o);
- final Object v = methodValuePresent(cl, o);
- assertEquals("method", v);
- }
-
- public void testValues_Method_Option() {
- final Option o = optionValuePresent();
- final WriteableCommandLine cl = parsedValueMissing(o);
- final Object v = methodValuePresent(cl, o);
- assertEquals("method", v);
- }
-
- public void testValues_Option() {
- final Option o = optionValuePresent();
- final WriteableCommandLine cl = parsedValueMissing(o);
- final Object v = methodValueMissing(cl, o);
- assertEquals("option", v);
- }
-
- public void testValues_Parsed() {
- final Option o = optionValueMissing();
- final WriteableCommandLine cl = parsedValuePresent(o);
- final Object v = methodValueMissing(cl, o);
- assertEquals("parsed", v);
- }
-
- public void testValues_Parsed_Method() {
- final Option o = optionValueMissing();
- final WriteableCommandLine cl = parsedValuePresent(o);
- final Object v = methodValuePresent(cl, o);
- assertEquals("parsed", v);
- }
-
- public void testValues_Parsed_Method_Option() {
- final Option o = optionValuePresent();
- final WriteableCommandLine cl = parsedValuePresent(o);
- final Object v = methodValuePresent(cl, o);
- assertEquals("parsed", v);
- }
-
- public void testValues_Parsed_Option() {
- final Option o = optionValuePresent();
- final WriteableCommandLine cl = parsedValuePresent(o);
- final Object v = methodValueMissing(cl, o);
- assertEquals("parsed", v);
- }
-}
\ No newline at end of file
+/**
+ * Copyright 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 net.dpml.cli;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.SwitchBuilder;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Tests the interaction of command line values and defaults supplied in
different ways.
+ *
+ * Tests marked _Parsed involve values parsed from a command line.
+ *
+ * Tests marked _Method involve defaults supplied in the query method.
+ *
+ * Tests marked _Option involce defaults specified in the model.
+ *
+ * @author Rob Oxspring
+ */
+public class CommandLineDefaultsTest extends TestCase
+{
+ /*
+ * utils to grab the default from the method
+ */
+ private Object methodSwitch( WriteableCommandLine cl, Option o, Boolean
bool )
+ {
+ return cl.getSwitch( o, bool );
+ }
+
+ private Object methodSwitchNull( WriteableCommandLine cl, Option o )
+ {
+ return methodSwitch( cl, o, null );
+ }
+
+ private Object methodSwitchOff( WriteableCommandLine cl, Option o )
+ {
+ return methodSwitch( cl, o, Boolean.FALSE );
+ }
+
+ private Object methodSwitchOn( WriteableCommandLine cl, Option o )
+ {
+ return methodSwitch( cl, o, Boolean.TRUE );
+ }
+
+ private Object methodValueMissing( WriteableCommandLine cl, Option o )
+ {
+ return cl.getValue( o );
+ }
+
+ private Object methodValuePresent( WriteableCommandLine cl, Option o )
+ {
+ return cl.getValue( o, "method" );
+ }
+
+ /*
+ * utils to grab the default from the option model
+ */
+ private Option optionSwitch( Boolean bool )
+ {
+ return new SwitchBuilder( ).withName( "switch" ).withSwitchDefault(
bool )
+ .create( );
+ }
+
+ private Option optionSwitchNull( )
+ {
+ return optionSwitch( null );
+ }
+
+ private Option optionSwitchOff( )
+ {
+ return optionSwitch( Boolean.FALSE );
+ }
+
+ private Option optionSwitchOn( )
+ {
+ return optionSwitch( Boolean.TRUE );
+ }
+
+ private Option optionValueMissing( )
+ {
+ return new ArgumentBuilder( ).create( );
+ }
+
+ private Option optionValuePresent( )
+ {
+ return new ArgumentBuilder( ).withDefaults( Arrays.asList(
+ new String[]{"option"} ) ).create( );
+ }
+
+ /*
+ * utils to grab the input from the command line
+ */
+ private WriteableCommandLine parsedSwitch( Option o, Boolean bool )
+ {
+ final List args;
+
+ if( bool == null )
+ {
+ args = Collections.EMPTY_LIST;
+ }
+ else
+ {
+ args = Collections.singletonList( String.valueOf( bool )
+ .toLowerCase( ) );
+ }
+
+ WriteableCommandLine cl = new WriteableCommandLineImpl( o, args );
+ o.defaults( cl );
+
+ if( bool != null )
+ {
+ cl.addSwitch( o, bool.booleanValue( ) );
+ }
+
+ return cl;
+ }
+
+ private WriteableCommandLine parsedSwitchNull( Option o )
+ {
+ return parsedSwitch( o, null );
+ }
+
+ private WriteableCommandLine parsedSwitchOn( Option o )
+ {
+ return parsedSwitch( o, Boolean.TRUE );
+ }
+
+ private WriteableCommandLine parsedValueMissing( Option o )
+ {
+ WriteableCommandLine cl = new WriteableCommandLineImpl( o,
+ Collections.EMPTY_LIST );
+ o.defaults( cl );
+
+ return cl;
+ }
+
+ private WriteableCommandLine parsedValuePresent( Option o )
+ {
+ WriteableCommandLine cl = new WriteableCommandLineImpl( o,
+ Arrays.asList( new String[]{"parsed"} ) );
+ o.defaults( cl );
+ cl.addValue( o, "parsed" );
+
+ return cl;
+ }
+
+ /*
+ * tests
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitch_Method( )
+ {
+ final Option o = optionSwitchNull( );
+ final WriteableCommandLine cl = parsedSwitchNull( o );
+ final Object v = methodSwitchOn( cl, o );
+ assertEquals( Boolean.TRUE, v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitch_Method_Option( )
+ {
+ final Option o = optionSwitchOff( );
+ final WriteableCommandLine cl = parsedSwitchNull( o );
+ final Object v = methodSwitchOn( cl, o );
+ assertEquals( Boolean.TRUE, v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitch_Option( )
+ {
+ final Option o = optionSwitchOn( );
+ final WriteableCommandLine cl = parsedSwitchNull( o );
+ final Object v = methodSwitchNull( cl, o );
+ assertEquals( Boolean.TRUE, v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitch_Parsed( )
+ {
+ final Option o = optionSwitchNull( );
+ final WriteableCommandLine cl = parsedSwitchOn( o );
+ final Object v = methodSwitchNull( cl, o );
+ assertEquals( Boolean.TRUE, v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitch_Parsed_Method( )
+ {
+ final Option o = optionSwitchOff( );
+ final WriteableCommandLine cl = parsedSwitchOn( o );
+ final Object v = methodSwitchNull( cl, o );
+ assertEquals( Boolean.TRUE, v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitch_Parsed_Method_Option( )
+ {
+ final Option o = optionSwitchOff( );
+ final WriteableCommandLine cl = parsedSwitchOn( o );
+ final Object v = methodSwitchOff( cl, o );
+ assertEquals( Boolean.TRUE, v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitch_Parsed_Option( )
+ {
+ final Option o = optionSwitchOff( );
+ final WriteableCommandLine cl = parsedSwitchOn( o );
+ final Object v = methodSwitchNull( cl, o );
+ assertEquals( Boolean.TRUE, v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValues( )
+ {
+ final Option o = optionValueMissing( );
+ final WriteableCommandLine cl = parsedValueMissing( o );
+ final Object v = methodValueMissing( cl, o );
+ assertNull( v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValues_Method( )
+ {
+ final Option o = optionValueMissing( );
+ final WriteableCommandLine cl = parsedValueMissing( o );
+ final Object v = methodValuePresent( cl, o );
+ assertEquals( "method", v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValues_Method_Option( )
+ {
+ final Option o = optionValuePresent( );
+ final WriteableCommandLine cl = parsedValueMissing( o );
+ final Object v = methodValuePresent( cl, o );
+ assertEquals( "method", v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValues_Option( )
+ {
+ final Option o = optionValuePresent( );
+ final WriteableCommandLine cl = parsedValueMissing( o );
+ final Object v = methodValueMissing( cl, o );
+ assertEquals( "option", v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValues_Parsed( )
+ {
+ final Option o = optionValueMissing( );
+ final WriteableCommandLine cl = parsedValuePresent( o );
+ final Object v = methodValueMissing( cl, o );
+ assertEquals( "parsed", v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValues_Parsed_Method( )
+ {
+ final Option o = optionValueMissing( );
+ final WriteableCommandLine cl = parsedValuePresent( o );
+ final Object v = methodValuePresent( cl, o );
+ assertEquals( "parsed", v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValues_Parsed_Method_Option( )
+ {
+ final Option o = optionValuePresent( );
+ final WriteableCommandLine cl = parsedValuePresent( o );
+ final Object v = methodValuePresent( cl, o );
+ assertEquals( "parsed", v );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValues_Parsed_Option( )
+ {
+ final Option o = optionValuePresent( );
+ final WriteableCommandLine cl = parsedValuePresent( o );
+ final Object v = methodValueMissing( cl, o );
+ assertEquals( "parsed", v );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/DocumentationTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/DocumentationTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/DocumentationTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,452 +1,371 @@
-/**
- * Copyright 2003-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 net.dpml.cli;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-import net.dpml.cli.option.DefaultOption;
-import net.dpml.cli.option.PropertyOption;
-import net.dpml.cli.util.HelpFormatter;
-
-/**
- * @author Rob
- *
- * To change the template for this generated type comment go to Window -
- * Preferences - Java - Code Generation - Code and Comments
- */
-public class DocumentationTest extends TestCase {
-
- public void testBasicUsage() throws IOException, OptionException {
- HelpFormatter helpFormatter = new HelpFormatter();
- //ignore all printed
- helpFormatter.setPrintWriter(new PrintWriter(new StringWriter()));
-
- /*
- * --version -? -h --help -log file -s|-q|-v|-d Bursting
File/Num/Date
- * validation Switches Commands Auto help Auto exception help
- *
- */
- DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- Option version =
- obuilder
- .withLongName("version")
- .withDescription("Displays version information and then
exits")
- .create();
-
- Option help =
- obuilder
- .withShortName("h")
- .withShortName("?")
- .withLongName("help")
- .withDescription("Displays help on usage and then exits")
- .create();
-
- ArgumentBuilder abuilder = new ArgumentBuilder();
- Argument logFile =
- abuilder
- .withDescription("The log file to write to")
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create();
- Option log =
- obuilder
- .withArgument(logFile)
- .withShortName("log")
- .withDescription("Log progress information to a file")
- .create();
-
- GroupBuilder gbuilder = new GroupBuilder();
- Group outputQuality =
- gbuilder
- .withName("quality")
- .withDescription("Controls the quality of console output")
- .withMaximum(1)
- .withOption(
- obuilder
- .withShortName("s")
- .withDescription("Silent")
- .create())
- .withOption(
- obuilder
- .withShortName("q")
- .withDescription("Quiet")
- .create())
- .withOption(
- obuilder
- .withShortName("n")
- .withDescription("Normal")
- .create())
- .withOption(
- obuilder
- .withShortName("v")
- .withDescription("Verbose")
- .create())
- .withOption(
- obuilder
- .withShortName("d")
- .withDescription("Debug")
- .create())
- .create();
-
- Group options =
- new GroupBuilder()
- .withName("options")
- .withOption(version)
- .withOption(help)
- .withOption(log)
- .withOption(outputQuality)
- .create();
-
- final String[] args = new String[] { "--bad-option" };
-
- Parser parser = new Parser();
- parser.setHelpFormatter(helpFormatter);
- parser.setGroup(options);
- parser.setHelpOption(help);
- CommandLine commandLine = parser.parseAndHelp(args);
- if (commandLine != null) {
- if (commandLine.hasOption(version)) {
- System.out.println("MyApp ver 1.0");
- return;
- }
- if (commandLine.hasOption("-log")) {
- String filename = (String)commandLine.getValue("-log");
- //...
- }
- }
-
- try {
- commandLine = parser.parse(args);
- fail("Unexpected Option!");
- }
- catch (OptionException uoe) {
- assertEquals(
- "Unexpected --bad-option while processing options",
- uoe.getMessage());
- }
- }
-
- public void testManualIntroduction() {
-
- DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- ArgumentBuilder aBuilder = new ArgumentBuilder();
- GroupBuilder gBuilder = new GroupBuilder();
-
- DefaultOption xmlOption =
- oBuilder
- .withLongName("xml")
- .withDescription("Output using xml format")
- .create();
-
- Argument pathArgument =
- aBuilder
- .withName("path")
- .withMinimum(1)
- .withMaximum(1)
- .create();
-
- Group outputChildren =
- gBuilder
- .withOption(xmlOption)
- .create();
-
- Option outputOption =
- oBuilder
- .withLongName("output")
- .withDescription("Outputs to a file")
- .withArgument(pathArgument)
- .withChildren(outputChildren)
- .create();
-
- ///////////////////////////////////////////////////
-
- try {
- Group options = outputChildren;
- HelpFormatter hf = new HelpFormatter();
-
- Parser p = new Parser();
- p.setGroup(options);
- p.setHelpFormatter(hf);
- p.setHelpTrigger("--help");
- CommandLine cl = p.parseAndHelp(new String[]{});
- if(cl==null) {
- System.exit(-1);
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- //////////////////////////////////////////////////
-
- CommandLine cl = new WriteableCommandLineImpl(outputChildren,new
ArrayList());
-
- // if we have --output option
- if(cl.hasOption("--output")) {
- // grab the path
- String path = (String)cl.getValue("--output");
- // grab the format
- boolean xml = cl.hasOption("--xml");
- // configure the application's output
- configureOutput(path,xml);
- }
-
-
-
-
- }
-
- private void configureOutput(String path, boolean xml) {
- // TODO Auto-generated method stub
-
- }
-
- public void testExampleAnt() throws IOException, OptionException {
- // Apache Ant version 1.6.1 compiled on February 12 2004
-
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
-
- Option help =
- obuilder
- .withShortName("help")
- .withShortName("h")
- .withDescription("print this message")
- .create();
- Option projecthelp =
- obuilder
- .withShortName("projecthelp")
- .withShortName("p")
- .withDescription("print project help information")
- .create();
- Option version =
- obuilder
- .withShortName("version")
- .withDescription("print the version information and exit")
- .create();
- Option diagnostics =
- obuilder
- .withShortName("diagnostics")
- .withDescription("print information that might be helpful to
diagnose or report problems.")
- .create();
- Option quiet =
- obuilder
- .withShortName("quiet")
- .withShortName("q")
- .withDescription("be extra quiet")
- .create();
- Option verbose =
- obuilder
- .withShortName("verbose")
- .withShortName("v")
- .withDescription("be extra verbose")
- .create();
- Option debug =
- obuilder
- .withShortName("debug")
- .withShortName("d")
- .withDescription("print debugging information")
- .create();
- Option emacs =
- obuilder
- .withShortName("emacs")
- .withShortName("e")
- .withDescription("produce logging information without
adornments")
- .create();
- Option lib =
- obuilder
- .withShortName("lib")
- .withDescription("specifies a path to search for jars and
classes")
- .withArgument(
- abuilder
- .withName("path")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
- Option logfile =
- obuilder
- .withShortName("logfile")
- .withShortName("l")
- .withDescription("use given file for log")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
- Option logger =
- obuilder
- .withShortName("logger")
- .withDescription("the class which is to perform logging")
- .withArgument(
- abuilder
- .withName("classname")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
- Option listener =
- obuilder
- .withShortName("listener")
- .withDescription("add an instance of class as a project
listener")
- .withArgument(
- abuilder
- .withName("classname")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
- Option noinput =
- obuilder
- .withShortName("noinput")
- .withDescription("do not allow interactive input")
- .create();
- Option buildfile =
- obuilder
- .withShortName("buildfile")
- .withShortName("file")
- .withShortName("f")
- .withDescription("use given buildfile")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
- Option property = new PropertyOption();
- Option propertyfile =
- obuilder
- .withShortName("propertyfile")
- .withDescription("load all properties from file with -D
properties taking precedence")
- .withArgument(
- abuilder
- .withName("name")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
- Option inputhandler =
- obuilder
- .withShortName("inputhandler")
- .withDescription("the class which will handle input
requests")
- .withArgument(
- abuilder
- .withName("class")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
- Option find =
- obuilder
- .withShortName("find")
- .withShortName("s")
- .withDescription("search for buildfile towards the root of
the filesystem and use it")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
- Option targets = abuilder.withName("target").create();
-
- Group options =
- gbuilder
- .withName("options")
- .withOption(help)
- .withOption(projecthelp)
- .withOption(version)
- .withOption(diagnostics)
- .withOption(quiet)
- .withOption(verbose)
- .withOption(debug)
- .withOption(emacs)
- .withOption(lib)
- .withOption(logfile)
- .withOption(logger)
- .withOption(listener)
- .withOption(noinput)
- .withOption(buildfile)
- .withOption(property)
- .withOption(propertyfile)
- .withOption(inputhandler)
- .withOption(find)
- .withOption(targets)
- .create();
-
- /////////////////////////////////////
- String[] args = new String[]{};
-
- Parser parser = new Parser();
- parser.setGroup(options);
- CommandLine cl = parser.parse(args);
-
- if(cl.hasOption(help)) {
- //displayHelp();
- return;
- }
- if(cl.hasOption("-version")) {
- //displayVersion();
- return;
- }
- if(cl.hasOption(logfile)) {
- String file = (String)cl.getValue(logfile);
- //setLogFile();
- }
- List targetList = cl.getValues(targets);
- for (Iterator i = targetList.iterator(); i.hasNext();) {
- String target = (String) i.next();
- //doTarget(target);
- }
-
- /////////////////////////////////////
-
- HelpFormatter hf = new HelpFormatter();
- hf.setShellCommand("ant");
- hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);
- hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
-
hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
-
-
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
-
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
-
hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
-
-
hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
-
- hf.setGroup(options);
- // redirect printed stuff to a string
- hf.setPrintWriter(new PrintWriter(new StringWriter()));
- hf.print();
-
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+import net.dpml.cli.option.DefaultOption;
+import net.dpml.cli.option.PropertyOption;
+import net.dpml.cli.util.HelpFormatter;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Rob
+ *
+ * To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Generation - Code and Comments
+ */
+public class DocumentationTest extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testBasicUsage( ) throws IOException, OptionException
+ {
+ HelpFormatter helpFormatter = new HelpFormatter( );
+ //ignore all printed
+ helpFormatter.setPrintWriter( new PrintWriter( new StringWriter( )
) );
+
+ /*
+ * --version -? -h --help -log file -s|-q|-v|-d Bursting
File/Num/Date
+ * validation Switches Commands Auto help Auto exception help
+ *
+ */
+ DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ Option version = obuilder.withLongName( "version" )
+ .withDescription( "Displays version
information and then exits" )
+ .create( );
+
+ Option help = obuilder.withShortName( "h" ).withShortName( "?" )
+ .withLongName( "help" )
+ .withDescription( "Displays help on usage and
then exits" )
+ .create( );
+
+ ArgumentBuilder abuilder = new ArgumentBuilder( );
+ Argument logFile = abuilder.withDescription( "The log file to write
to" )
+ .withName( "file" ).withMinimum( 1 )
+ .withMaximum( 1 ).create( );
+ Option log = obuilder.withArgument( logFile ).withShortName( "log" )
+ .withDescription( "Log progress information to
a file" )
+ .create( );
+
+ GroupBuilder gbuilder = new GroupBuilder( );
+ Group outputQuality = gbuilder.withName( "quality" )
+ .withDescription( "Controls the
quality of console output" )
+ .withMaximum( 1 )
+ .withOption( obuilder.withShortName(
"s" )
+ .withDescription(
"Silent" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
"q" )
+ .withDescription(
"Quiet" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
"n" )
+ .withDescription(
"Normal" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
"v" )
+ .withDescription(
"Verbose" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
"d" )
+ .withDescription(
"Debug" )
+ .create( )
).create( );
+
+ Group options = new GroupBuilder( ).withName( "options" )
+ .withOption( version )
+ .withOption( help ).withOption(
log )
+ .withOption( outputQuality
).create( );
+
+ final String[] args = new String[]{"--bad-option"};
+
+ Parser parser = new Parser( );
+ parser.setHelpFormatter( helpFormatter );
+ parser.setGroup( options );
+ parser.setHelpOption( help );
+
+ CommandLine commandLine = parser.parseAndHelp( args );
+
+ if( commandLine != null )
+ {
+ if( commandLine.hasOption( version ) )
+ {
+ System.out.println( "MyApp ver 1.0" );
+
+ return;
+ }
+
+ if( commandLine.hasOption( "-log" ) )
+ {
+ String filename = (String) commandLine.getValue( "-log" );
+
+ //...
+ }
+ }
+
+ try
+ {
+ commandLine = parser.parse( args );
+ fail( "Unexpected Option!" );
+ }
+ catch( OptionException uoe )
+ {
+ assertEquals( "Unexpected --bad-option while processing options",
+ uoe.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testManualIntroduction( )
+ {
+ DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ ArgumentBuilder aBuilder = new ArgumentBuilder( );
+ GroupBuilder gBuilder = new GroupBuilder( );
+
+ DefaultOption xmlOption = oBuilder.withLongName( "xml" )
+ .withDescription( "Output using
xml format" )
+ .create( );
+
+ Argument pathArgument = aBuilder.withName( "path" ).withMinimum( 1 )
+ .withMaximum( 1 ).create( );
+
+ Group outputChildren = gBuilder.withOption( xmlOption ).create( );
+
+ Option outputOption = oBuilder.withLongName( "output" )
+ .withDescription( "Outputs to a file" )
+ .withArgument( pathArgument )
+ .withChildren( outputChildren
).create( );
+
+ ///////////////////////////////////////////////////
+ try
+ {
+ Group options = outputChildren;
+ HelpFormatter hf = new HelpFormatter( );
+
+ Parser p = new Parser( );
+ p.setGroup( options );
+ p.setHelpFormatter( hf );
+ p.setHelpTrigger( "--help" );
+
+ CommandLine cl = p.parseAndHelp( new String[]{} );
+
+ if( cl == null )
+ {
+ System.exit( -1 );
+ }
+ }
+ catch( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace( );
+ }
+
+ //////////////////////////////////////////////////
+ CommandLine cl = new WriteableCommandLineImpl( outputChildren,
+ new ArrayList( ) );
+
+ // if we have --output option
+ if( cl.hasOption( "--output" ) )
+ {
+ // grab the path
+ String path = (String) cl.getValue( "--output" );
+
+ // grab the format
+ boolean xml = cl.hasOption( "--xml" );
+ // configure the application's output
+ configureOutput( path, xml );
+ }
+ }
+
+ private void configureOutput( String path, boolean xml )
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testExampleAnt( ) throws IOException, OptionException
+ {
+ // Apache Ant version 1.6.1 compiled on February 12 2004
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ final ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+
+ Option help = obuilder.withShortName( "help" ).withShortName( "h" )
+ .withDescription( "print this message"
).create( );
+ Option projecthelp = obuilder.withShortName( "projecthelp" )
+ .withShortName( "p" )
+ .withDescription( "print project help
information" )
+ .create( );
+ Option version = obuilder.withShortName( "version" )
+ .withDescription( "print the version
information and exit" )
+ .create( );
+ Option diagnostics = obuilder.withShortName( "diagnostics" )
+ .withDescription( "print information
that might be helpful to diagnose or report problems." )
+ .create( );
+ Option quiet = obuilder.withShortName( "quiet" ).withShortName( "q" )
+ .withDescription( "be extra quiet" ).create(
);
+ Option verbose = obuilder.withShortName( "verbose" ).withShortName(
"v" )
+ .withDescription( "be extra verbose"
).create( );
+ Option debug = obuilder.withShortName( "debug" ).withShortName( "d" )
+ .withDescription( "print debugging
information" )
+ .create( );
+ Option emacs = obuilder.withShortName( "emacs" ).withShortName( "e" )
+ .withDescription( "produce logging
information without adornments" )
+ .create( );
+ Option lib = obuilder.withShortName( "lib" )
+ .withDescription( "specifies a path to search
for jars and classes" )
+ .withArgument( abuilder.withName( "path" )
+ .withMinimum( 1 )
+ .withMaximum( 1
).create( ) )
+ .create( );
+ Option logfile = obuilder.withShortName( "logfile" ).withShortName(
"l" )
+ .withDescription( "use given file for log" )
+ .withArgument( abuilder.withName( "file" )
+ .withMinimum( 1 )
+ .withMaximum( 1 )
+ .create( )
).create( );
+ Option logger = obuilder.withShortName( "logger" )
+ .withDescription( "the class which is to
perform logging" )
+ .withArgument( abuilder.withName(
"classname" )
+ .withMinimum( 1 )
+ .withMaximum( 1
).create( ) )
+ .create( );
+ Option listener = obuilder.withShortName( "listener" )
+ .withDescription( "add an instance of
class as a project listener" )
+ .withArgument( abuilder.withName(
"classname" )
+ .withMinimum( 1 )
+ .withMaximum( 1 )
+ .create( )
).create( );
+ Option noinput = obuilder.withShortName( "noinput" )
+ .withDescription( "do not allow interactive
input" )
+ .create( );
+ Option buildfile = obuilder.withShortName( "buildfile" )
+ .withShortName( "file" ).withShortName(
"f" )
+ .withDescription( "use given buildfile" )
+ .withArgument( abuilder.withName( "file" )
+ .withMinimum( 1 )
+ .withMaximum( 1 )
+ .create( )
).create( );
+ Option property = new PropertyOption( );
+ Option propertyfile = obuilder.withShortName( "propertyfile" )
+ .withDescription( "load all properties
from file with -D properties taking precedence" )
+ .withArgument( abuilder.withName(
"name" )
+ .withMinimum( 1
)
+ .withMaximum( 1
)
+ .create( ) )
+ .create( );
+ Option inputhandler = obuilder.withShortName( "inputhandler" )
+ .withDescription( "the class which
will handle input requests" )
+ .withArgument( abuilder.withName(
"class" )
+ .withMinimum( 1
)
+ .withMaximum( 1
)
+ .create( ) )
+ .create( );
+ Option find = obuilder.withShortName( "find" ).withShortName( "s" )
+ .withDescription( "search for buildfile
towards the root of the filesystem and use it" )
+ .withArgument( abuilder.withName( "file" )
+ .withMinimum( 1 )
+ .withMaximum( 1
).create( ) )
+ .create( );
+ Option targets = abuilder.withName( "target" ).create( );
+
+ Group options = gbuilder.withName( "options" ).withOption( help )
+ .withOption( projecthelp ).withOption(
version )
+ .withOption( diagnostics ).withOption( quiet
)
+ .withOption( verbose ).withOption( debug )
+ .withOption( emacs ).withOption( lib )
+ .withOption( logfile ).withOption( logger )
+ .withOption( listener ).withOption( noinput )
+ .withOption( buildfile ).withOption(
property )
+ .withOption( propertyfile )
+ .withOption( inputhandler ).withOption( find
)
+ .withOption( targets ).create( );
+
+ /////////////////////////////////////
+ String[] args = new String[]{};
+
+ Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ CommandLine cl = parser.parse( args );
+
+ if( cl.hasOption( help ) )
+ {
+ //displayHelp();
+ return;
+ }
+
+ if( cl.hasOption( "-version" ) )
+ {
+ //displayVersion();
+ return;
+ }
+
+ if( cl.hasOption( logfile ) )
+ {
+ String file = (String) cl.getValue( logfile );
+
+ //setLogFile();
+ }
+
+ List targetList = cl.getValues( targets );
+
+ for( Iterator i = targetList.iterator( ); i.hasNext( ); )
+ {
+ String target = (String) i.next( );
+
+ //doTarget(target);
+ }
+
+ /////////////////////////////////////
+ HelpFormatter hf = new HelpFormatter( );
+ hf.setShellCommand( "ant" );
+ hf.getFullUsageSettings( ).add( DisplaySetting.DISPLAY_GROUP_NAME );
+ hf.getFullUsageSettings( ).add(
DisplaySetting.DISPLAY_GROUP_ARGUMENT );
+ hf.getFullUsageSettings( ).remove(
DisplaySetting.DISPLAY_GROUP_EXPANDED );
+
+ hf.getLineUsageSettings( ).add(
DisplaySetting.DISPLAY_PROPERTY_OPTION );
+ hf.getLineUsageSettings( ).add(
DisplaySetting.DISPLAY_PARENT_ARGUMENT );
+ hf.getLineUsageSettings( )
+ .add( DisplaySetting.DISPLAY_ARGUMENT_BRACKETED );
+
+ hf.getDisplaySettings( ).remove(
DisplaySetting.DISPLAY_GROUP_ARGUMENT );
+
+ hf.setGroup( options );
+ // redirect printed stuff to a string
+ hf.setPrintWriter( new PrintWriter( new StringWriter( ) ) );
+ hf.print( );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/PrecedenceTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/PrecedenceTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/PrecedenceTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,415 +1,498 @@
-/**
- * Copyright 2003-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 net.dpml.cli;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-
-/**
- * @author Rob Oxspring
- *
- * To change the template for this generated type comment go to Window -
- * Preferences - Java - Code Generation - Code and Comments
- */
-public class PrecedenceTest extends TestCase {
- private final String[] args = new String[] { "-file" };
-
- public void testSimple() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
-
- final Group options =
- new GroupBuilder()
- .withOption(oBuilder.withShortName("file").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-file" }, cl);
- }
-
- public void testArgument() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- final Group options =
- new GroupBuilder()
- .withOption(
- oBuilder
- .withShortName("f")
- .withArgument(aBuilder.create())
- .create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f" }, cl);
- }
-
- public void testBurst() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final Group options =
- gBuilder
- .withOption(oBuilder.withShortName("f").create())
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
- }
-
- public void testChildren() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
-
- final Group children =
- gBuilder
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
- final Group options =
- gBuilder
- .withOption(
- oBuilder
- .withShortName("f")
- .withChildren(children)
- .create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
- }
-
- public void XtestSimpleVsArgument() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- final Group options =
- gBuilder
- .withOption(oBuilder.withShortName("file").create())
- .withOption(
- oBuilder
- .withShortName("f")
- .withArgument(aBuilder.create())
- .create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f" }, cl);
- }
-
- public void XtestSimpleVsBurst() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final Group options =
- gBuilder
- .withOption(oBuilder.withShortName("file").create())
- .withOption(oBuilder.withShortName("f").create())
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
- }
-
- public void XtestSimpleVsChildren() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
-
- final Group children =
- gBuilder
- .withOption(
- oBuilder.withShortName("i").withLongName("ci").create())
- .withOption(
- oBuilder.withShortName("l").withLongName("cl").create())
- .withOption(
- oBuilder.withShortName("e").withLongName("ce").create())
- .create();
-
- final Group options =
- gBuilder
- .withOption(oBuilder.withShortName("file").create())
- .withOption(
- oBuilder
- .withShortName("f")
- .withChildren(children)
- .create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(
- new String[] { "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce" },
- cl);
- }
-
- public void testArgumentVsBurst() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- final Group options =
- gBuilder
- .withOption(
- oBuilder
- .withShortName("f")
- .withArgument(aBuilder.create())
- .create())
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f" }, cl);
- }
-
- public void testArgumentVsChildren() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- final Group children =
- gBuilder
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
- final Group options =
- gBuilder
- .withOption(
- oBuilder
- .withShortName("f")
- .withChildren(children)
- .withArgument(aBuilder.create())
- .create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f" }, cl);
- }
-
- public void testBurstVsChildren() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
-
- final Group children =
- gBuilder
- .withOption(
- oBuilder.withShortName("i").withLongName("ci").create())
- .withOption(
- oBuilder.withShortName("l").withLongName("cl").create())
- .withOption(
- oBuilder.withShortName("e").withLongName("ce").create())
- .create();
-
- final Group options =
- gBuilder
- .withOption(
- oBuilder
- .withShortName("f")
- .withChildren(children)
- .create())
- .withOption(
- oBuilder.withShortName("i").withLongName("bi").create())
- .withOption(
- oBuilder.withShortName("l").withLongName("bl").create())
- .withOption(
- oBuilder.withShortName("e").withLongName("be").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(
- new String[] { "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce" },
- cl);
- }
-
- public void XtestSimpleVsArgumentVsBurst() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- final Group options =
- gBuilder
- .withOption(oBuilder.withShortName("file").create())
- .withOption(
- oBuilder
- .withShortName("f")
- .withArgument(aBuilder.create())
- .create())
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f" }, cl);
- }
-
- public void XtestSimpleVsArgumentVsChildren() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- final Group children =
- gBuilder
- .withOption(
- oBuilder.withShortName("i").withLongName("ci").create())
- .withOption(
- oBuilder.withShortName("l").withLongName("cl").create())
- .withOption(
- oBuilder.withShortName("e").withLongName("ce").create())
- .create();
-
- final Group options =
- gBuilder
- .withOption(oBuilder.withShortName("file").create())
- .withOption(
- oBuilder
- .withShortName("f")
- .withChildren(children)
- .withArgument(aBuilder.create())
- .create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f" }, cl);
- }
-
- public void XtestSimpleVsBurstVsChildren() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
-
- final Group children =
- gBuilder
- .withOption(
- oBuilder.withShortName("i").withLongName("ci").create())
- .withOption(
- oBuilder.withShortName("l").withLongName("cl").create())
- .withOption(
- oBuilder.withShortName("e").withLongName("ce").create())
- .create();
-
- final Group options =
- gBuilder
- .withOption(oBuilder.withShortName("file").create())
- .withOption(
- oBuilder
- .withShortName("f")
- .withChildren(children)
- .create())
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
- }
-
- public void testArgumentVsBurstVsChildren() throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- final Group children =
- gBuilder
- .withOption(
- oBuilder.withShortName("i").withLongName("ci").create())
- .withOption(
- oBuilder.withShortName("l").withLongName("cl").create())
- .withOption(
- oBuilder.withShortName("e").withLongName("ce").create())
- .create();
-
- final Group options =
- gBuilder
- .withOption(
- oBuilder
- .withShortName("f")
- .withChildren(children)
- .withArgument(aBuilder.create())
- .create())
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f" }, cl);
- }
-
- public void XtestSimpleVsArgumentVsBurstVsChildren()
- throws OptionException {
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
- final GroupBuilder gBuilder = new GroupBuilder();
- final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- final Group children =
- gBuilder
- .withOption(
- oBuilder.withShortName("i").withLongName("ci").create())
- .withOption(
- oBuilder.withShortName("l").withLongName("cl").create())
- .withOption(
- oBuilder.withShortName("e").withLongName("ce").create())
- .create();
-
- final Group options =
- gBuilder
- .withOption(oBuilder.withShortName("file").create())
- .withOption(
- oBuilder
- .withShortName("f")
- .withChildren(children)
- .withArgument(aBuilder.create())
- .create())
- .withOption(oBuilder.withShortName("i").create())
- .withOption(oBuilder.withShortName("l").create())
- .withOption(oBuilder.withShortName("e").create())
- .create();
-
- final CommandLine cl = buildCommandLine(options, args);
- assertEquals(new String[] { "-f" }, cl);
- }
-
- public CommandLine buildCommandLine(final Group group, final String[]
arguments)
- throws OptionException {
- Parser p = new Parser();
- p.setGroup(group);
- return p.parse(arguments);
- }
-
- public void assertEquals(final String options[], final CommandLine line)
{
- final List expected = Arrays.asList(options);
- final Set actual = line.getOptionTriggers();
-
- assertTrue(expected.containsAll(actual));
- assertTrue(actual.containsAll(expected));
- }
-
-}
+/**
+ * Copyright 2003-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 net.dpml.cli;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Rob Oxspring
+ *
+ * To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Generation - Code and Comments
+ */
+public class PrecedenceTest extends TestCase
+{
+ private final String[] args = new String[]{"-file"};
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testSimple( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+
+ final Group options = new GroupBuilder( ).withOption(
oBuilder.withShortName(
+ "file" ).create( ) ).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-file"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testArgument( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ final Group options = new GroupBuilder( ).withOption(
oBuilder.withShortName(
+ "f" ).withArgument( aBuilder.create( ) ).create( ) )
+ .create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testBurst( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
"f" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f", "-i", "-l", "-e"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testChildren( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+
+ final Group children = gBuilder.withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( ) )
+ .create( );
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
"f" )
+ .withChildren(
children )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f", "-i", "-l", "-e"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void XtestSimpleVsArgument( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
+ "file" ).create( ) )
+ .withOption( oBuilder.withShortName(
"f" )
+ .withArgument(
aBuilder.create( ) )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void XtestSimpleVsBurst( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
+ "file" ).create( ) )
+ .withOption( oBuilder.withShortName(
"f" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f", "-i", "-l", "-e"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void XtestSimpleVsChildren( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+
+ final Group children = gBuilder.withOption( oBuilder.withShortName(
"i" )
+ .withLongName(
"ci" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .withLongName(
"cl" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .withLongName(
"ce" )
+ .create( ) )
+ .create( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
+ "file" ).create( ) )
+ .withOption( oBuilder.withShortName(
"f" )
+ .withChildren(
children )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]
+ {
+ "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce"
+ }, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testArgumentVsBurst( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
"f" )
+ .withArgument(
aBuilder.create( ) )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testArgumentVsChildren( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ final Group children = gBuilder.withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( ) )
+ .create( );
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
"f" )
+ .withChildren(
children )
+ .withArgument(
aBuilder.create( ) )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testBurstVsChildren( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+
+ final Group children = gBuilder.withOption( oBuilder.withShortName(
"i" )
+ .withLongName(
"ci" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .withLongName(
"cl" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .withLongName(
"ce" )
+ .create( ) )
+ .create( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
"f" )
+ .withChildren(
children )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"i" )
+ .withLongName(
"bi" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .withLongName(
"bl" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .withLongName(
"be" )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]
+ {
+ "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce"
+ }, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void XtestSimpleVsArgumentVsBurst( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
+ "file" ).create( ) )
+ .withOption( oBuilder.withShortName(
"f" )
+ .withArgument(
aBuilder.create( ) )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void XtestSimpleVsArgumentVsChildren( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ final Group children = gBuilder.withOption( oBuilder.withShortName(
"i" )
+ .withLongName(
"ci" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .withLongName(
"cl" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .withLongName(
"ce" )
+ .create( ) )
+ .create( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
+ "file" ).create( ) )
+ .withOption( oBuilder.withShortName(
"f" )
+ .withChildren(
children )
+ .withArgument(
aBuilder.create( ) )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void XtestSimpleVsBurstVsChildren( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+
+ final Group children = gBuilder.withOption( oBuilder.withShortName(
"i" )
+ .withLongName(
"ci" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .withLongName(
"cl" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .withLongName(
"ce" )
+ .create( ) )
+ .create( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
+ "file" ).create( ) )
+ .withOption( oBuilder.withShortName(
"f" )
+ .withChildren(
children )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f", "-i", "-l", "-e"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testArgumentVsBurstVsChildren( ) throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ final Group children = gBuilder.withOption( oBuilder.withShortName(
"i" )
+ .withLongName(
"ci" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .withLongName(
"cl" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .withLongName(
"ce" )
+ .create( ) )
+ .create( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
"f" )
+ .withChildren(
children )
+ .withArgument(
aBuilder.create( ) )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void XtestSimpleVsArgumentVsBurstVsChildren( )
+ throws OptionException
+ {
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ final Group children = gBuilder.withOption( oBuilder.withShortName(
"i" )
+ .withLongName(
"ci" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .withLongName(
"cl" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .withLongName(
"ce" )
+ .create( ) )
+ .create( );
+
+ final Group options = gBuilder.withOption( oBuilder.withShortName(
+ "file" ).create( ) )
+ .withOption( oBuilder.withShortName(
"f" )
+ .withChildren(
children )
+ .withArgument(
aBuilder.create( ) )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"i" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"l" )
+ .create( ) )
+ .withOption( oBuilder.withShortName(
"e" )
+ .create( )
).create( );
+
+ final CommandLine cl = buildCommandLine( options, args );
+ assertEquals( new String[]{"-f"}, cl );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param group DOCUMENT ME!
+ * @param arguments DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public CommandLine buildCommandLine( final Group group,
+ final String[] arguments ) throws OptionException
+ {
+ Parser p = new Parser( );
+ p.setGroup( group );
+
+ return p.parse( arguments );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param options DOCUMENT ME!
+ * @param line DOCUMENT ME!
+ */
+ public void assertEquals( final String[] options, final CommandLine line
)
+ {
+ final List expected = Arrays.asList( options );
+ final Set actual = line.getOptionTriggers( );
+ assertTrue( expected.containsAll( actual ) );
+ assertTrue( actual.containsAll( expected ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/application/AntTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/application/AntTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/application/AntTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,197 +1,154 @@
-/**
- * Copyright 2003-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 net.dpml.cli.application;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.Group;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-import net.dpml.cli.option.PropertyOption;
-
-//TODO Build up AntTest like CpTest
-public class AntTest extends TestCase {
- public void testAnt() throws OptionException {
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
-
- final Group options =
- gbuilder
- .withName("ant")
- .withOption(
- obuilder
- .withShortName("help")
- .withDescription("print this message")
- .create())
- .withOption(
- obuilder
- .withShortName("projecthelp")
- .withDescription("print project help information")
- .create())
- .withOption(
- obuilder
- .withShortName("version")
- .withDescription("print the version information and
exit")
- .create())
- .withOption(
- obuilder
- .withShortName("diagnostics")
- .withDescription("print information that might be
helpful to diagnose or report problems.")
- .create())
- .withOption(
- obuilder
- .withShortName("quiet")
- .withShortName("q")
- .withDescription("be extra quiet")
- .create())
- .withOption(
- obuilder
- .withShortName("verbose")
- .withShortName("v")
- .withDescription("be extra verbose")
- .create())
- .withOption(
- obuilder
- .withShortName("debug")
- .withDescription("print debugging information")
- .create())
- .withOption(
- obuilder
- .withShortName("emacs")
- .withDescription("produce logging information
without adornments")
- .create())
- .withOption(
- obuilder
- .withShortName("logfile")
- .withShortName("l")
- .withDescription("use given file for log")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("logger")
- .withDescription("the class which is to perform
logging")
- .withArgument(
- abuilder
- .withName("classname")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("listener")
- .withDescription("add an instance of class as a
project listener")
- .withArgument(
- abuilder
- .withName("classname")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("buildfile")
- .withShortName("file")
- .withShortName("f")
- .withDescription("use given buildfile")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(PropertyOption.INSTANCE)
- .withOption(
- obuilder
- .withShortName("propertyfile")
- .withDescription("load all properties from file with
-D properties taking precedence")
- .withArgument(
- abuilder
- .withName("name")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("inputhandler")
- .withDescription("the class which will handle input
requests")
- .withArgument(
- abuilder
- .withName("class")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(
- obuilder
- .withShortName("find")
- .withDescription("search for buildfile towards the
root of the filesystem and use it")
- .withArgument(
- abuilder
- .withName("file")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create())
- .withOption(abuilder.withName("target").create())
- .create();
-
- Parser parser = new Parser();
- parser.setGroup(options);
- CommandLine line =
- parser.parse(
- new String[] {
- "-buildfile",
- "mybuild.xml",
- "-Dproperty=value",
- "-Dproperty1=value1",
- "-projecthelp",
- "compile",
- "docs" });
-
- // check properties
- assertEquals(2, line.getProperties().size());
- assertEquals("value", line.getProperty("property"));
- assertEquals("value1", line.getProperty("property1"));
-
- // check single values
- assertEquals("mybuild.xml", line.getValue("-buildfile"));
- assertTrue(line.hasOption("-projecthelp"));
- assertFalse(line.hasOption("-help"));
-
- assertTrue(line.hasOption("target"));
- final List targets = new ArrayList();
- targets.add("compile");
- targets.add("docs");
- assertEquals(targets, line.getValues("target"));
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.application;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.CommandLine;
+import net.dpml.cli.Group;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+import net.dpml.cli.option.PropertyOption;
+
+import java.util.ArrayList;
+import java.util.List;
+
+//TODO Build up AntTest like CpTest
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class AntTest extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testAnt( ) throws OptionException
+ {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ final ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+
+ final Group options = gbuilder.withName( "ant" )
+ .withOption( obuilder.withShortName(
+ "help" ).withDescription( "print this message" ).create(
) )
+ .withOption( obuilder.withShortName(
+ "projecthelp" )
+ .withDescription(
"print project help information" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "version" )
+ .withDescription(
"print the version information and exit" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "diagnostics" )
+ .withDescription(
"print information that might be helpful to diagnose or report problems." )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "quiet" ).withShortName( "q" )
+ .withDescription(
"be extra quiet" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "verbose" ).withShortName( "v" )
+ .withDescription(
"be extra verbose" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "debug" ).withDescription( "print debugging information"
)
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "emacs" )
+ .withDescription(
"produce logging information without adornments" )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "logfile" ).withShortName( "l" )
+ .withDescription(
"use given file for log" )
+ .withArgument(
abuilder.withName(
+ "file" ).withMinimum( 1 ).withMaximum( 1 ).create(
) )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "logger" )
+ .withDescription(
"the class which is to perform logging" )
+ .withArgument(
abuilder.withName(
+ "classname" ).withMinimum( 1 ).withMaximum( 1
).create( ) )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "listener" )
+ .withDescription(
"add an instance of class as a project listener" )
+ .withArgument(
abuilder.withName(
+ "classname" ).withMinimum( 1 ).withMaximum( 1
).create( ) )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "buildfile" ).withShortName( "file" ).withShortName( "f"
)
+ .withDescription(
"use given buildfile" )
+ .withArgument(
abuilder.withName(
+ "file" ).withMinimum( 1 ).withMaximum( 1 ).create(
) )
+ .create( ) )
+ .withOption( PropertyOption.INSTANCE )
+ .withOption( obuilder.withShortName(
+ "propertyfile" )
+ .withDescription(
"load all properties from file with -D properties taking precedence" )
+ .withArgument(
abuilder.withName(
+ "name" ).withMinimum( 1 ).withMaximum( 1 ).create(
) )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "inputhandler" )
+ .withDescription(
"the class which will handle input requests" )
+ .withArgument(
abuilder.withName(
+ "class" ).withMinimum( 1 ).withMaximum( 1 ).create(
) )
+ .create( ) )
+ .withOption( obuilder.withShortName(
+ "find" )
+ .withDescription(
"search for buildfile towards the root of the filesystem and use it" )
+ .withArgument(
abuilder.withName(
+ "file" ).withMinimum( 1 ).withMaximum( 1 ).create(
) )
+ .create( ) )
+ .withOption( abuilder.withName(
"target" )
+ .create( )
).create( );
+
+ Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ CommandLine line = parser.parse( new String[]
+ {
+ "-buildfile", "mybuild.xml", "-Dproperty=value",
+ "-Dproperty1=value1", "-projecthelp", "compile", "docs"
+ } );
+
+ // check properties
+ assertEquals( 2, line.getProperties( ).size( ) );
+ assertEquals( "value", line.getProperty( "property" ) );
+ assertEquals( "value1", line.getProperty( "property1" ) );
+
+ // check single values
+ assertEquals( "mybuild.xml", line.getValue( "-buildfile" ) );
+ assertTrue( line.hasOption( "-projecthelp" ) );
+ assertFalse( line.hasOption( "-help" ) );
+
+ assertTrue( line.hasOption( "target" ) );
+
+ final List targets = new ArrayList( );
+ targets.add( "compile" );
+ targets.add( "docs" );
+ assertEquals( targets, line.getValues( "target" ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/application/CpTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/application/CpTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/application/CpTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,470 +1,397 @@
-/**
- * Copyright 2003-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 net.dpml.cli.application;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import net.dpml.cli.Argument;
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-import net.dpml.cli.option.ArgumentImpl;
-import net.dpml.cli.option.SourceDestArgument;
-import net.dpml.cli.util.HelpFormatter;
-
-/**
- * <p>Test the <code>cp</code> command. Duplicated Option types are not
- * tested e.g. -a and -d are the same Option type.</p>
- *
- * <p>The following is the man output for 'cp'. See
- * http://www.rt.com/man/cp.1.html.</p>
- *
- * <pre>
- * CP(1) FSF CP(1)
- *
- * NAME cp - copy files and directories
- *
- * SYNOPSIS cp [OPTION]... SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY
- *
- * DESCRIPTION Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
- *
- * -a, --archive same as -dpR
- *
- * -b, --backup make backup before removal
- *
- * -d, --no-dereference preserve links
- *
- * -f, --force remove existing destinations, never prompt
- *
- * -i, --interactive prompt before overwrite
- *
- * -l, --link link files instead of copying
- *
- * -p, --preserve preserve file attributes if possible
- *
- * -P, --parents append source path to DIRECTORY
- * -r copy recursively, non-directories as files
- *
- * --sparse=WHEN control creation of sparse files
- *
- * -R, --recursive copy directories recursively
- *
- * -s, --symbolic-link make symbolic links instead of copying
- *
- * -S, --suffix=SUFFIX override the usual backup suffix
- *
- * -u, --update copy only when the SOURCE file is newer than the
destination file or when the destination file is missing
- *
- * -v, --verbose explain what is being done
- *
- * -V, --version-control=WORD override the usual version control
- *
- * -x, --one-file-system stay on this file system
- *
- * --help display this help and exit
- *
- * --version output version information and exit
- *
- * By default, sparse SOURCE files are detected by a crude heuristic and
the corresponding DEST file is made sparse as well. That is the behavior
selected by --sparse=auto. Specify --sparse=always to create a sparse DEST
file when- ever the SOURCE file contains a long enough sequence of zero
bytes. Use --sparse=never to inhibit creation of sparse files.
- *
- * The backup suffix is ~, unless set with SIMPLE_BACKUP_SUF- FIX. The
version control may be set with VERSION_CONTROL, values are:
- * t, numbered make numbered backups
- *
- * nil, existing numbered if numbered backups exist, simple other- wise
- *
- * never, simple always make simple backups
- *
- * As a special case, cp makes a backup of SOURCE when the force and backup
options are given and SOURCE and DEST are the same name for an existing,
regular file. * </pre>
- * </pre>
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public class CpTest extends TestCase {
-
- /** Option Builder */
- private static final DefaultOptionBuilder oBuilder =
- new DefaultOptionBuilder();
-
- /** Argument Builder */
- private static final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- /** Group Builder */
- private static final GroupBuilder gBuilder = new GroupBuilder();
-
- private Group options;
-
- public static Test suite() {
- return new TestSuite(CpTest.class);
- }
-
- private ArgumentImpl source;
- private ArgumentImpl dest;
- private Argument targets;
-
- private Option archive;
- private Option backup;
- private Option noDereference;
- private Option force;
- private Option interactive;
- private Option link;
- private Option preserve;
- private Option parents;
- private Option recursive1;
- private Option sparse;
- private Option recursive2;
- private Option symbolicLink;
- private Option suffix;
- private Option update;
- private Option verbose;
- private Option versionControl;
- private Option oneFileSystem;
- private Option help;
- private Option version;
-
- public void setUp() {
- source =
-
(ArgumentImpl)aBuilder.withName("SOURCE").withMinimum(1).create();
- dest =
- (ArgumentImpl)aBuilder
- .withName("DEST")
- .withMinimum(1)
- .withMaximum(1)
- .create();
- targets = new SourceDestArgument(source, dest);
-
- archive =
- oBuilder
- .withShortName("a")
- .withLongName("archive")
- .withDescription("same as -dpR")
- .create();
-
- backup =
- oBuilder
- .withShortName("b")
- .withLongName("backup")
- .withDescription("make backup before removal")
- .create();
-
- noDereference =
- oBuilder
- .withShortName("d")
- .withLongName("no-dereference")
- .withDescription("preserve links")
- .create();
-
- force =
- oBuilder
- .withShortName("f")
- .withLongName("force")
- .withDescription("remove existing destinations, never
prompt")
- .create();
-
- interactive =
- oBuilder
- .withShortName("i")
- .withLongName("interactive")
- .withDescription("prompt before overwrite")
- .create();
-
- link =
- oBuilder
- .withShortName("l")
- .withLongName("link")
- .withDescription("link files instead of copying")
- .create();
-
- preserve =
- oBuilder
- .withShortName("p")
- .withLongName("preserve")
- .withDescription("preserve file attributes if possible")
- .create();
-
- parents =
- oBuilder
- .withShortName("P")
- .withLongName("parents")
- .withDescription("append source path to DIRECTORY")
- .create();
-
- recursive1 =
- oBuilder
- .withShortName("r")
- .withDescription("copy recursively, non-directories as
files")
- .create();
-
- sparse =
- oBuilder
- .withLongName("sparse")
- .withDescription("control creation of sparse files")
- .withArgument(
- aBuilder
- .withName("WHEN")
- .withMinimum(1)
- .withMaximum(1)
- .withInitialSeparator('=')
- .create())
- .create();
-
- recursive2 =
- oBuilder
- .withShortName("R")
- .withLongName("recursive")
- .withDescription("copy directories recursively")
- .create();
-
- symbolicLink =
- oBuilder
- .withShortName("s")
- .withLongName("symbolic-link")
- .withDescription("make symbolic links instead of copying")
- .create();
-
- suffix =
- oBuilder
- .withShortName("S")
- .withLongName("suffix")
- .withDescription("override the usual backup suffix")
- .withArgument(
- aBuilder
- .withName("SUFFIX")
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
-
- update =
- oBuilder
- .withShortName("u")
- .withLongName("update")
- .withDescription("copy only when the SOURCE file is newer
than the destination file or when the destination file is missing")
- .create();
-
- verbose =
- oBuilder
- .withShortName("v")
- .withLongName("verbose")
- .withDescription("explain what is being done")
- .create();
-
- versionControl =
- oBuilder
- .withShortName("V")
- .withLongName("version-contol")
- .withDescription("explain what is being done")
- .withArgument(
- aBuilder
- .withName("WORD")
- .withInitialSeparator('=')
- .withMinimum(1)
- .withMaximum(1)
- .create())
- .create();
-
- oneFileSystem =
- oBuilder
- .withShortName("x")
- .withLongName("one-file-system")
- .withDescription("stay on this file system")
- .create();
-
- help =
- oBuilder
- .withLongName("help")
- .withDescription("display this help and exit")
- .create();
-
- version =
- oBuilder
- .withLongName("version")
- .withDescription("output version information and exit")
- .create();
-
- options =
- gBuilder
- .withOption(archive)
- .withOption(backup)
- .withOption(noDereference)
- .withOption(force)
- .withOption(interactive)
- .withOption(link)
- .withOption(preserve)
- .withOption(parents)
- .withOption(recursive1)
- .withOption(sparse)
- .withOption(recursive2)
- .withOption(symbolicLink)
- .withOption(suffix)
- .withOption(update)
- .withOption(verbose)
- .withOption(versionControl)
- .withOption(oneFileSystem)
- .withOption(help)
- .withOption(version)
- .withOption(targets)
- .withName("OPTIONS")
- .create();
- }
-
- public void testNoSource() {
- Parser parser = new Parser();
- parser.setGroup(options);
- try {
- parser.parse(new String[0]);
- }
- catch (OptionException mve) {
- assertEquals(
- "Missing value(s) SOURCE [SOURCE ...]",
- mve.getMessage());
- }
- }
-
- public void testOneSource() throws OptionException {
- final String[] args = new String[] { "source1", "dest1" };
- final Parser parser = new Parser();
- parser.setGroup(options);
- final CommandLine commandLine = parser.parse(args);
-
- assertTrue(commandLine.getValues(source).contains("source1"));
- assertEquals(1, commandLine.getValues(source).size());
- assertTrue(commandLine.getValues(dest).contains("dest1"));
- assertEquals(1, commandLine.getValues(dest).size());
- }
-
- public void testMultiSource() throws OptionException {
- final String[] args =
- new String[] { "source1", "source2", "source3", "dest1" };
- final Parser parser = new Parser();
- parser.setGroup(options);
- final CommandLine commandLine = parser.parse(args);
-
- assertTrue(commandLine.getValues(source).contains("source1"));
- assertTrue(commandLine.getValues(source).contains("source2"));
- assertTrue(commandLine.getValues(source).contains("source3"));
- assertEquals(3, commandLine.getValues(source).size());
-
- assertTrue(commandLine.getValues(dest).contains("dest1"));
- assertEquals(1, commandLine.getValues(dest).size());
- }
-
- public void testHelp() throws IOException {
- final StringWriter out = new StringWriter();
- final HelpFormatter helpFormatter = new HelpFormatter();
- helpFormatter.setGroup(options);
- helpFormatter.setPrintWriter(new PrintWriter(out));
- helpFormatter.print();
-
- final BufferedReader in =
- new BufferedReader(new StringReader(out.toString()));
- assertEquals(
- "Usage:
",
- in.readLine());
- assertEquals(
- " [-a -b -d -f -i -l -p -P -r --sparse <WHEN> -R -s -S <SUFFIX>
-u -v -V <WORD> ",
- in.readLine());
- assertEquals(
- "-x --help --version] <SOURCE1> [<SOURCE2> ...] <DEST>
",
- in.readLine());
- assertEquals(
- "OPTIONS
",
- in.readLine());
- assertEquals(
- " -a (--archive) same as -dpR
",
- in.readLine());
- assertEquals(
- " -b (--backup) make backup before removal
",
- in.readLine());
- assertEquals(
- " -d (--no-dereference) preserve links
",
- in.readLine());
- assertEquals(
- " -f (--force) remove existing destinations,
never prompt ",
- in.readLine());
- assertEquals(
- " -i (--interactive) prompt before overwrite
",
- in.readLine());
- assertEquals(
- " -l (--link) link files instead of copying
",
- in.readLine());
- assertEquals(
- " -p (--preserve) preserve file attributes if
possible ",
- in.readLine());
- assertEquals(
- " -P (--parents) append source path to DIRECTORY
",
- in.readLine());
- assertEquals(
- " -r copy recursively,
non-directories as files ",
- in.readLine());
- assertEquals(
- " --sparse WHEN control creation of sparse
files ",
- in.readLine());
- assertEquals(
- " -R (--recursive) copy directories recursively
",
- in.readLine());
- assertEquals(
- " -s (--symbolic-link) make symbolic links instead of
copying ",
- in.readLine());
- assertEquals(
- " -S (--suffix) SUFFIX override the usual backup
suffix ",
- in.readLine());
- assertEquals(
- " -u (--update) copy only when the SOURCE file
is newer than ",
- in.readLine());
- assertEquals(
- " the destination file or when
the destination ",
- in.readLine());
- assertEquals(
- " file is missing
",
- in.readLine());
- assertEquals(
- " -v (--verbose) explain what is being done
",
- in.readLine());
- assertEquals(
- " -V (--version-contol) WORD explain what is being done
",
- in.readLine());
- assertEquals(
- " -x (--one-file-system) stay on this file system
",
- in.readLine());
- assertEquals(
- " --help display this help and exit
",
- in.readLine());
- assertEquals(
- " --version output version information and
exit ",
- in.readLine());
- assertEquals(
- " SOURCE [SOURCE ...]
",
- in.readLine());
- assertEquals(
- " DEST
",
- in.readLine());
- assertNull(in.readLine());
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.application;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import net.dpml.cli.Argument;
+import net.dpml.cli.CommandLine;
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+import net.dpml.cli.option.ArgumentImpl;
+import net.dpml.cli.option.SourceDestArgument;
+import net.dpml.cli.util.HelpFormatter;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+/**
+ * <p>Test the <code>cp</code> command. Duplicated Option types are not
+ * tested e.g. -a and -d are the same Option type.</p>
+ *
+ * <p>The following is the man output for 'cp'. See
+ * http://www.rt.com/man/cp.1.html.</p>
+ *
+ * <pre>
+ * CP(1) FSF CP(1)
+ *
+ * NAME cp - copy files and directories
+ *
+ * SYNOPSIS cp [OPTION]... SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY
+ *
+ * DESCRIPTION Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
+ *
+ * -a, --archive same as -dpR
+ *
+ * -b, --backup make backup before removal
+ *
+ * -d, --no-dereference preserve links
+ *
+ * -f, --force remove existing destinations, never prompt
+ *
+ * -i, --interactive prompt before overwrite
+ *
+ * -l, --link link files instead of copying
+ *
+ * -p, --preserve preserve file attributes if possible
+ *
+ * -P, --parents append source path to DIRECTORY
+ * -r copy recursively, non-directories as files
+ *
+ * --sparse=WHEN control creation of sparse files
+ *
+ * -R, --recursive copy directories recursively
+ *
+ * -s, --symbolic-link make symbolic links instead of copying
+ *
+ * -S, --suffix=SUFFIX override the usual backup suffix
+ *
+ * -u, --update copy only when the SOURCE file is newer than the
destination file or when the destination file is missing
+ *
+ * -v, --verbose explain what is being done
+ *
+ * -V, --version-control=WORD override the usual version control
+ *
+ * -x, --one-file-system stay on this file system
+ *
+ * --help display this help and exit
+ *
+ * --version output version information and exit
+ *
+ * By default, sparse SOURCE files are detected by a crude heuristic and
the corresponding DEST file is made sparse as well. That is the behavior
selected by --sparse=auto. Specify --sparse=always to create a sparse DEST
file when- ever the SOURCE file contains a long enough sequence of zero
bytes. Use --sparse=never to inhibit creation of sparse files.
+ *
+ * The backup suffix is ~, unless set with SIMPLE_BACKUP_SUF- FIX. The
version control may be set with VERSION_CONTROL, values are:
+ * t, numbered make numbered backups
+ *
+ * nil, existing numbered if numbered backups exist, simple other- wise
+ *
+ * never, simple always make simple backups
+ *
+ * As a special case, cp makes a backup of SOURCE when the force and backup
options are given and SOURCE and DEST are the same name for an existing,
regular file. * </pre>
+ * </pre>
+ *
+ * @author Rob Oxspring
+ * @author John Keyes
+ */
+public class CpTest extends TestCase
+{
+ /** Option Builder */
+ private static final DefaultOptionBuilder oBuilder = new
DefaultOptionBuilder( );
+
+ /** Argument Builder */
+ private static final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ /** Group Builder */
+ private static final GroupBuilder gBuilder = new GroupBuilder( );
+ private Group options;
+ private ArgumentImpl source;
+ private ArgumentImpl dest;
+ private Argument targets;
+ private Option archive;
+ private Option backup;
+ private Option noDereference;
+ private Option force;
+ private Option interactive;
+ private Option link;
+ private Option preserve;
+ private Option parents;
+ private Option recursive1;
+ private Option sparse;
+ private Option recursive2;
+ private Option symbolicLink;
+ private Option suffix;
+ private Option update;
+ private Option verbose;
+ private Option versionControl;
+ private Option oneFileSystem;
+ private Option help;
+ private Option version;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Test suite( )
+ {
+ return new TestSuite( CpTest.class );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void setUp( )
+ {
+ source = (ArgumentImpl) aBuilder.withName( "SOURCE" ).withMinimum( 1
)
+ .create( );
+ dest = (ArgumentImpl) aBuilder.withName( "DEST" ).withMinimum( 1 )
+ .withMaximum( 1 ).create( );
+ targets = new SourceDestArgument( source, dest );
+
+ archive = oBuilder.withShortName( "a" ).withLongName( "archive" )
+ .withDescription( "same as -dpR" ).create( );
+
+ backup = oBuilder.withShortName( "b" ).withLongName( "backup" )
+ .withDescription( "make backup before removal" )
+ .create( );
+
+ noDereference = oBuilder.withShortName( "d" )
+ .withLongName( "no-dereference" )
+ .withDescription( "preserve links" ).create(
);
+
+ force = oBuilder.withShortName( "f" ).withLongName( "force" )
+ .withDescription( "remove existing destinations,
never prompt" )
+ .create( );
+
+ interactive = oBuilder.withShortName( "i" ).withLongName(
"interactive" )
+ .withDescription( "prompt before overwrite" )
+ .create( );
+
+ link = oBuilder.withShortName( "l" ).withLongName( "link" )
+ .withDescription( "link files instead of copying" )
+ .create( );
+
+ preserve = oBuilder.withShortName( "p" ).withLongName( "preserve" )
+ .withDescription( "preserve file attributes if
possible" )
+ .create( );
+
+ parents = oBuilder.withShortName( "P" ).withLongName( "parents" )
+ .withDescription( "append source path to
DIRECTORY" )
+ .create( );
+
+ recursive1 = oBuilder.withShortName( "r" )
+ .withDescription( "copy recursively,
non-directories as files" )
+ .create( );
+
+ sparse = oBuilder.withLongName( "sparse" )
+ .withDescription( "control creation of sparse
files" )
+ .withArgument( aBuilder.withName( "WHEN" )
+ .withMinimum( 1
).withMaximum( 1 )
+ .withInitialSeparator( '=' )
+ .create( ) ).create( );
+
+ recursive2 = oBuilder.withShortName( "R" ).withLongName( "recursive"
)
+ .withDescription( "copy directories
recursively" )
+ .create( );
+
+ symbolicLink = oBuilder.withShortName( "s" )
+ .withLongName( "symbolic-link" )
+ .withDescription( "make symbolic links
instead of copying" )
+ .create( );
+
+ suffix = oBuilder.withShortName( "S" ).withLongName( "suffix" )
+ .withDescription( "override the usual backup
suffix" )
+ .withArgument( aBuilder.withName( "SUFFIX" )
+ .withMinimum( 1
).withMaximum( 1 )
+ .create( ) ).create( );
+
+ update = oBuilder.withShortName( "u" ).withLongName( "update" )
+ .withDescription( "copy only when the SOURCE file
is newer than the destination file or when the destination file is missing" )
+ .create( );
+
+ verbose = oBuilder.withShortName( "v" ).withLongName( "verbose" )
+ .withDescription( "explain what is being done" )
+ .create( );
+
+ versionControl = oBuilder.withShortName( "V" )
+ .withLongName( "version-contol" )
+ .withDescription( "explain what is being
done" )
+ .withArgument( aBuilder.withName( "WORD" )
+
.withInitialSeparator( '=' )
+ .withMinimum( 1 )
+ .withMaximum( 1 )
+ .create( )
).create( );
+
+ oneFileSystem = oBuilder.withShortName( "x" )
+ .withLongName( "one-file-system" )
+ .withDescription( "stay on this file system"
)
+ .create( );
+
+ help = oBuilder.withLongName( "help" )
+ .withDescription( "display this help and exit"
).create( );
+
+ version = oBuilder.withLongName( "version" )
+ .withDescription( "output version information and
exit" )
+ .create( );
+
+ options = gBuilder.withOption( archive ).withOption( backup )
+ .withOption( noDereference ).withOption( force )
+ .withOption( interactive ).withOption( link )
+ .withOption( preserve ).withOption( parents )
+ .withOption( recursive1 ).withOption( sparse )
+ .withOption( recursive2 ).withOption( symbolicLink
)
+ .withOption( suffix ).withOption( update )
+ .withOption( verbose ).withOption( versionControl )
+ .withOption( oneFileSystem ).withOption( help )
+ .withOption( version ).withOption( targets )
+ .withName( "OPTIONS" ).create( );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNoSource( )
+ {
+ Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ try
+ {
+ parser.parse( new String[0] );
+ }
+ catch( OptionException mve )
+ {
+ assertEquals( "Missing value(s) SOURCE [SOURCE ...]",
+ mve.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testOneSource( ) throws OptionException
+ {
+ final String[] args = new String[]{"source1", "dest1"};
+ final Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ final CommandLine commandLine = parser.parse( args );
+
+ assertTrue( commandLine.getValues( source ).contains( "source1" ) );
+ assertEquals( 1, commandLine.getValues( source ).size( ) );
+ assertTrue( commandLine.getValues( dest ).contains( "dest1" ) );
+ assertEquals( 1, commandLine.getValues( dest ).size( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testMultiSource( ) throws OptionException
+ {
+ final String[] args = new String[]
+ {
+ "source1", "source2", "source3", "dest1"
+ };
+ final Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ final CommandLine commandLine = parser.parse( args );
+
+ assertTrue( commandLine.getValues( source ).contains( "source1" ) );
+ assertTrue( commandLine.getValues( source ).contains( "source2" ) );
+ assertTrue( commandLine.getValues( source ).contains( "source3" ) );
+ assertEquals( 3, commandLine.getValues( source ).size( ) );
+
+ assertTrue( commandLine.getValues( dest ).contains( "dest1" ) );
+ assertEquals( 1, commandLine.getValues( dest ).size( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testHelp( ) throws IOException
+ {
+ final StringWriter out = new StringWriter( );
+ final HelpFormatter helpFormatter = new HelpFormatter( );
+ helpFormatter.setGroup( options );
+ helpFormatter.setPrintWriter( new PrintWriter( out ) );
+ helpFormatter.print( );
+
+ final BufferedReader in = new BufferedReader( new StringReader(
+ out.toString( ) ) );
+ assertEquals( "Usage:
",
+ in.readLine( ) );
+ assertEquals( " [-a -b -d -f -i -l -p -P -r --sparse <WHEN> -R -s -S
<SUFFIX> -u -v -V <WORD> ",
+ in.readLine( ) );
+ assertEquals( "-x --help --version] <SOURCE1> [<SOURCE2> ...] <DEST>
",
+ in.readLine( ) );
+ assertEquals( "OPTIONS
",
+ in.readLine( ) );
+ assertEquals( " -a (--archive) same as -dpR
",
+ in.readLine( ) );
+ assertEquals( " -b (--backup) make backup before
removal ",
+ in.readLine( ) );
+ assertEquals( " -d (--no-dereference) preserve links
",
+ in.readLine( ) );
+ assertEquals( " -f (--force) remove existing
destinations, never prompt ",
+ in.readLine( ) );
+ assertEquals( " -i (--interactive) prompt before
overwrite ",
+ in.readLine( ) );
+ assertEquals( " -l (--link) link files instead of
copying ",
+ in.readLine( ) );
+ assertEquals( " -p (--preserve) preserve file
attributes if possible ",
+ in.readLine( ) );
+ assertEquals( " -P (--parents) append source path to
DIRECTORY ",
+ in.readLine( ) );
+ assertEquals( " -r copy recursively,
non-directories as files ",
+ in.readLine( ) );
+ assertEquals( " --sparse WHEN control creation of
sparse files ",
+ in.readLine( ) );
+ assertEquals( " -R (--recursive) copy directories
recursively ",
+ in.readLine( ) );
+ assertEquals( " -s (--symbolic-link) make symbolic links
instead of copying ",
+ in.readLine( ) );
+ assertEquals( " -S (--suffix) SUFFIX override the usual
backup suffix ",
+ in.readLine( ) );
+ assertEquals( " -u (--update) copy only when the
SOURCE file is newer than ",
+ in.readLine( ) );
+ assertEquals( " the destination file
or when the destination ",
+ in.readLine( ) );
+ assertEquals( " file is missing
",
+ in.readLine( ) );
+ assertEquals( " -v (--verbose) explain what is being
done ",
+ in.readLine( ) );
+ assertEquals( " -V (--version-contol) WORD explain what is being
done ",
+ in.readLine( ) );
+ assertEquals( " -x (--one-file-system) stay on this file
system ",
+ in.readLine( ) );
+ assertEquals( " --help display this help and
exit ",
+ in.readLine( ) );
+ assertEquals( " --version output version
information and exit ",
+ in.readLine( ) );
+ assertEquals( " SOURCE [SOURCE ...]
",
+ in.readLine( ) );
+ assertEquals( " DEST
",
+ in.readLine( ) );
+ assertNull( in.readLine( ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/application/CvsTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/application/CvsTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/application/CvsTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,311 +1,235 @@
-/**
- * Copyright 2003-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 net.dpml.cli.application;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.Group;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.CommandBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.option.ArgumentTest;
-
-//TODO Build up CvsTest like CpTest
-public class CvsTest extends TestCase {
- public void testCVS() {
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final CommandBuilder cbuilder = new CommandBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
-
- final Group commands =
- gbuilder
- .withName("commands")
- .withOption(
- cbuilder
- .withName("add")
- .withName("ad")
- .withName("new")
- .withDescription("Add a new file/directory to the
repository")
- .create())
- .withOption(
- cbuilder
- .withName("admin")
- .withName("adm")
- .withName("rcs")
- .withDescription("Administration front end for rcs")
- .create())
- .withOption(
- cbuilder
- .withName("annotate")
- .withName("ann")
- .withDescription("Show last revision where each line
was modified")
- .create())
- .withOption(
- cbuilder
- .withName("checkout")
- .withName("co")
- .withName("get")
- .withDescription("Checkout sources for editing")
- .create())
- .withOption(
- cbuilder
- .withName("commit")
- .withName("ci")
- .withName("com")
- .withDescription("Check files into the repository")
- .create())
- .withOption(
- cbuilder
- .withName("diff")
- .withName("di")
- .withName("dif")
- .withDescription("Show differences between
revisions")
- .create())
- .withOption(
- cbuilder
- .withName("edit")
- .withDescription("Get ready to edit a watched file")
- .create())
- .withOption(
- cbuilder
- .withName("editors")
- .withDescription("See who is editing a watched file")
- .create())
- .withOption(
- cbuilder
- .withName("export")
- .withName("exp")
- .withName("ex")
- .withDescription("Export sources from CVS, similar
to checkout")
- .create())
- .withOption(
- cbuilder
- .withName("history")
- .withName("hi")
- .withName("his")
- .withDescription("Show repository access history")
- .create())
- .withOption(
- cbuilder
- .withName("import")
- .withName("im")
- .withName("imp")
- .withDescription("Import sources into CVS, using
vendor branches")
- .create())
- .withOption(
- cbuilder
- .withName("init")
- .withDescription("Create a CVS repository if it
doesn't exist")
- .create())
- .withOption(
- cbuilder
- .withName("log")
- .withName("lo")
- .withName("rlog")
- .withDescription("Print out history information for
files")
- .create())
- .withOption(
- cbuilder
- .withName("login")
- .withName("logon")
- .withName("lgn")
- .withDescription("Prompt for password for
authenticating server")
- .create())
- .withOption(
- cbuilder
- .withName("logout")
- .withDescription("Removes entry in .cvspass for
remote repository")
- .create())
- .withOption(
- cbuilder
- .withName("rdiff")
- .withName("patch")
- .withName("pa")
- .withDescription("Create 'patch' format diffs
between releases")
- .create())
- .withOption(
- cbuilder
- .withName("release")
- .withName("re")
- .withName("rel")
- .withDescription("Indicate that a Module is no
longer in use")
- .create())
- .withOption(
- cbuilder
- .withName("remove")
- .withName("rm")
- .withName("delete")
- .withDescription("Remove an entry from the
repository")
- .create())
- .withOption(
- cbuilder
- .withName("rtag")
- .withName("rt")
- .withName("rfreeze")
- .withDescription("Add a symbolic tag to a module")
- .create())
- .withOption(
- cbuilder
- .withName("status")
- .withName("st")
- .withName("stat")
- .withDescription("Display status information on
checked out files")
- .create())
- .withOption(
- cbuilder
- .withName("tag")
- .withName("ta")
- .withName("freeze")
- .withDescription("Add a symbolic tag to checked out
version of files")
- .create())
- .withOption(
- cbuilder
- .withName("unedit")
- .withDescription("Undo an edit command")
- .create())
- .withOption(
- cbuilder
- .withName("update")
- .withName("up")
- .withName("upd")
- .withDescription("Bring work tree in sync with
repository")
- .create())
- .withOption(
- cbuilder
- .withName("watch")
- .withDescription("Set watches")
- .create())
- .withOption(
- cbuilder
- .withName("watchers")
- .withDescription("See who is watching a file")
- .create())
- .withOption(
- cbuilder
- .withName("version")
- .withName("ve")
- .withName("ver")
- .withDescription("????")
- .create())
- .withOption(ArgumentTest.buildTargetsArgument())
- .create();
-
- final Group cvsOptions =
- new GroupBuilder()
- .withName("cvs-options")
- .withOption(
- obuilder
- .withShortName("H")
- .withDescription("Displays usage information for
command.")
- .create())
- .withOption(
- obuilder
- .withShortName("Q")
- .withDescription("Cause CVS to be really quiet.")
- .create())
- .withOption(
- obuilder
- .withShortName("q")
- .withDescription("Cause CVS to be somewhat quiet.")
- .create())
- .withOption(
- obuilder
- .withShortName("r")
- .withDescription("Make checked-out files read-only.")
- .create())
- .withOption(
- obuilder
- .withShortName("w")
- .withDescription("Make checked-out files read-write
(default).")
- .create())
- .withOption(
- obuilder
- .withShortName("l")
- .withDescription("Turn history logging off.")
- .create())
- .withOption(
- obuilder
- .withShortName("n")
- .withDescription("Do not execute anything that will
change the disk.")
- .create())
- .withOption(
- obuilder
- .withShortName("t")
- .withDescription("Show trace of program execution --
try with -n.")
- .create())
- .withOption(
- obuilder
- .withShortName("v")
- .withDescription("CVS version and copyright.")
- .create())
- .withOption(
- obuilder
- .withLongName("crlf")
- .withDescription("Use the Dos line feed for text
files (default).")
- .create())
- .withOption(
- obuilder
- .withLongName("lf")
- .withDescription("Use the Unix line feed for text
files.")
- .create())
- .withOption(
- obuilder
- .withShortName("T")
- .withDescription("Use 'tmpdir' for temporary files.")
- .withArgument(abuilder.withName("tmpdir").create())
- .create())
- .withOption(
- obuilder
- .withShortName("e")
- .withDescription("Use 'editor' for editing log
information.")
- .withArgument(abuilder.withName("editor").create())
- .create())
- .withOption(
- obuilder
- .withShortName("d")
- .withDescription("Overrides $CVSROOT as the root of
the CVS tree.")
- .withArgument(abuilder.withName("CVS_root").create())
- .create())
- .withOption(
- obuilder
- .withShortName("f")
- .withDescription("Do not use the ~/.cvsrc file.")
- .create())
- .withOption(
- obuilder
- .withShortName("z")
- .withDescription("Use compression level '#' for net
traffic.")
- .withArgument(abuilder.withName("#").create())
- .create())
- .withOption(
- obuilder
- .withShortName("a")
- .withDescription("Authenticate all net traffic.")
- .create())
- .withOption(
- obuilder
- .withShortName("s")
- .withDescription("Set CVS user variable.")
- .withArgument(abuilder.withName("VAR=VAL").create())
- .create())
- .withOption(commands)
- .create();
-
- assertNotNull(cvsOptions);
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.application;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.Group;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.CommandBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.option.ArgumentTest;
+
+//TODO Build up CvsTest like CpTest
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class CvsTest extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCVS( )
+ {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ final ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final CommandBuilder cbuilder = new CommandBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+
+ final Group commands = gbuilder.withName( "commands" )
+ .withOption( cbuilder.withName( "add"
)
+ .withName( "ad" )
+ .withName( "new"
)
+
.withDescription( "Add a new file/directory to the repository" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"admin" )
+ .withName( "adm"
)
+ .withName( "rcs"
)
+
.withDescription( "Administration front end for rcs" )
+ .create( ) )
+ .withOption( cbuilder.withName(
+ "annotate" ).withName( "ann" )
+
.withDescription( "Show last revision where each line was modified" )
+ .create( ) )
+ .withOption( cbuilder.withName(
+ "checkout" ).withName( "co" ).withName( "get" )
+
.withDescription( "Checkout sources for editing" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"commit" )
+ .withName( "ci" )
+ .withName( "com"
)
+
.withDescription( "Check files into the repository" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"diff" )
+ .withName( "di" )
+ .withName( "dif"
)
+
.withDescription( "Show differences between revisions" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"edit" )
+
.withDescription( "Get ready to edit a watched file" )
+ .create( ) )
+ .withOption( cbuilder.withName(
+ "editors" )
+
.withDescription( "See who is editing a watched file" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"export" )
+ .withName( "exp"
)
+ .withName( "ex" )
+
.withDescription( "Export sources from CVS, similar to checkout" )
+ .create( ) )
+ .withOption( cbuilder.withName(
+ "history" ).withName( "hi" ).withName( "his" )
+
.withDescription( "Show repository access history" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"import" )
+ .withName( "im" )
+ .withName( "imp"
)
+
.withDescription( "Import sources into CVS, using vendor branches" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"init" )
+
.withDescription( "Create a CVS repository if it doesn't exist" )
+ .create( ) )
+ .withOption( cbuilder.withName( "log"
)
+ .withName( "lo" )
+ .withName(
"rlog" )
+
.withDescription( "Print out history information for files" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"login" )
+ .withName(
"logon" )
+ .withName( "lgn"
)
+
.withDescription( "Prompt for password for authenticating server" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"logout" )
+
.withDescription( "Removes entry in .cvspass for remote repository" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"rdiff" )
+ .withName(
"patch" )
+ .withName( "pa" )
+
.withDescription( "Create 'patch' format diffs between releases" )
+ .create( ) )
+ .withOption( cbuilder.withName(
+ "release" ).withName( "re" ).withName( "rel" )
+
.withDescription( "Indicate that a Module is no longer in use" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"remove" )
+ .withName( "rm" )
+ .withName(
"delete" )
+
.withDescription( "Remove an entry from the repository" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"rtag" )
+ .withName( "rt" )
+ .withName(
"rfreeze" )
+
.withDescription( "Add a symbolic tag to a module" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"status" )
+ .withName( "st" )
+ .withName(
"stat" )
+
.withDescription( "Display status information on checked out files" )
+ .create( ) )
+ .withOption( cbuilder.withName( "tag"
)
+ .withName( "ta" )
+ .withName(
"freeze" )
+
.withDescription( "Add a symbolic tag to checked out version of files" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"unedit" )
+
.withDescription( "Undo an edit command" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"update" )
+ .withName( "up" )
+ .withName( "upd"
)
+
.withDescription( "Bring work tree in sync with repository" )
+ .create( ) )
+ .withOption( cbuilder.withName(
"watch" )
+
.withDescription( "Set watches" )
+ .create( ) )
+ .withOption( cbuilder.withName(
+ "watchers" ).withDescription( "See who is watching a
file" )
+ .create( ) )
+ .withOption( cbuilder.withName(
+ "version" ).withName( "ve" ).withName( "ver" )
+
.withDescription( "????" )
+ .create( ) )
+ .withOption(
ArgumentTest.buildTargetsArgument( ) )
+ .create( );
+
+ final Group cvsOptions = new GroupBuilder( ).withName(
"cvs-options" )
+ .withOption(
obuilder.withShortName(
+ "H" )
+
.withDescription( "Displays usage information for command." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "Q" ).withDescription( "Cause CVS to be really quiet." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "q" ).withDescription( "Cause CVS to be somewhat quiet."
)
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "r" ).withDescription( "Make checked-out files
read-only." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "w" )
+
.withDescription( "Make checked-out files read-write (default)." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "l" ).withDescription( "Turn history logging off."
).create( ) )
+ .withOption(
obuilder.withShortName(
+ "n" )
+
.withDescription( "Do not execute anything that will change the disk." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "t" )
+
.withDescription( "Show trace of program execution -- try with -n." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "v" ).withDescription( "CVS version and copyright." )
+
.create( ) )
+ .withOption(
obuilder.withLongName(
+ "crlf" )
+
.withDescription( "Use the Dos line feed for text files (default)." )
+
.create( ) )
+ .withOption(
obuilder.withLongName(
+ "lf" )
+
.withDescription( "Use the Unix line feed for text files." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "T" ).withDescription( "Use 'tmpdir' for temporary
files." )
+
.withArgument( abuilder.withName(
+ "tmpdir" ).create( ) ).create( ) )
+ .withOption(
obuilder.withShortName(
+ "e" )
+
.withDescription( "Use 'editor' for editing log information." )
+
.withArgument( abuilder.withName(
+ "editor" ).create( ) ).create( ) )
+ .withOption(
obuilder.withShortName(
+ "d" )
+
.withDescription( "Overrides $CVSROOT as the root of the CVS tree." )
+
.withArgument( abuilder.withName(
+ "CVS_root" ).create( ) ).create( ) )
+ .withOption(
obuilder.withShortName(
+ "f" ).withDescription( "Do not use the ~/.cvsrc file." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "z" )
+
.withDescription( "Use compression level '#' for net traffic." )
+
.withArgument( abuilder.withName(
+ "#" ).create( ) ).create( ) )
+ .withOption(
obuilder.withShortName(
+ "a" ).withDescription( "Authenticate all net traffic." )
+
.create( ) )
+ .withOption(
obuilder.withShortName(
+ "s" ).withDescription( "Set CVS user variable." )
+
.withArgument( abuilder.withName(
+ "VAR=VAL" ).create( ) ).create( ) )
+ .withOption( commands )
+ .create( );
+
+ assertNotNull( cvsOptions );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/application/LsTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/application/LsTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/application/LsTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,223 +1,222 @@
-/**
- * Copyright 2003-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 net.dpml.cli.application;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-import net.dpml.cli.validation.EnumValidator;
-
-/**
- * <p>Test the <code>ls</code> command. Duplicated Option types are not
- * tested e.g. -a and -d are the same Option type.</p>
- *
- * <p>The following is the man output for 'ls'. See
- * http://www.rt.com/man/ls.1.html.</p>
- *
- * <pre>
- * LS(1) FSF LS(1)
- *
- * NAME ls - list directory contents
- *
- * SYNOPSIS ls [OPTION]... [FILE]...
- *
- * DESCRIPTION List information about the FILEs (the current directory by
default). Sort entries alphabetically if none of -cftuSUX nor --sort.
- *
- * -a, --all do not hide entries starting with .
- *
- * -A, --almost-all do not list implied . and ..
- *
- * -b, --escape print octal escapes for nongraphic characters
- *
- * --block-size=SIZE use SIZE-byte blocks
- *
- * -B, --ignore-backups do not list implied entries ending with ~ -c sort
by change time; with -l: show ctime -C list entries by columns
- *
- * --color[=WHEN] control whether color is used to distinguish file types.
WHEN may be `never', `always', or `auto'
- *
- * -d, --directory list directory entries instead of contents
- *
- * -D, --dired generate output designed for Emacs' dired mode -f do not
sort, enable -aU, disable -lst
- *
- * -F, --classify append indicator (one of /=@|*) to entries
- *
- * --format=WORD across -x, commas -m, horizontal -x, long -l, sin-
gle-column -1, verbose -l, vertical -C
- *
- * --full-time list both full date and full time -g (ignored)
- *
- * -G, --no-group inhibit display of group information
- *
- * -h, --human-readable print sizes in human readable format (e.g., 1K 234M
2G)
- *
- * -H, --si likewise, but use powers of 1000 not 1024
- *
- * --indicator-style=WORD append indicator with style WORD to entry names:
none (default), classify (-F), file-type (-p)
- *
- * -i, --inode print index number of each file
- *
- * -I, --ignore=PATTERN do not list implied entries matching shell PATTERN
- *
- * -k, --kilobytes like --block-size=1024 -l use a long listing format
- *
- * -L, --dereference list entries pointed to by symbolic links -m fill
width with a comma separated list of entries
- *
- * -n, --numeric-uid-gid list numeric UIDs and GIDs instead of names
- *
- * -N, --literal print raw entry names (don't treat e.g. control characters
specially) -o use long listing format without group info
- *
- * -p, --file-type append indicator (one of /=@|) to entries
- *
- * -q, --hide-control-chars print ? instead of non graphic characters
- *
- * --show-control-chars show non graphic characters as-is (default)
- *
- * -Q, --quote-name enclose entry names in double quotes
- *
- * --quoting-style=WORD use quoting style WORD for entry names: literal,
shell, shell-always, c, escape
- *
- * -r, --reverse reverse order while sorting
- *
- * -R, --recursive list subdirectories recursively
- *
- * -s, --size print size of each file, in blocks -S sort by file size
- *
- * --sort=WORD extension -X, none -U, size -S, time -t, version -v status
-c, time -t, atime -u, access -u, use -u
- *
- * --time=WORD show time as WORD instead of modification time: atime,
access, use, ctime or status; use specified time as sort key if --sort=time
-t sort by modification time
- *
- * -T, --tabsize=COLS assume tab stops at each COLS instead of 8 -u sort by
last access time; with -l: show atime -U do not sort; list entries in
directory order -v sort by version
- *
- * -w, --width=COLS assume screen width instead of current value -x list
entries by lines instead of by columns -X sort alphabetically by entry
extension -1 list one file per line
- *
- * --help display this help and exit
- *
- * --version output version information and exit
- *
- * By default, color is not used to distinguish types of files. That is
equivalent to using --color=none. Using the --color option without the
optional WHEN argument is equivalent to using --color=always. With
--color=auto, color codes are output only if standard output is con- nected
to a terminal (tty).
- * </pre>
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public class LsTest extends TestCase {
-
- /** Option Builder */
- private static final DefaultOptionBuilder oBuilder =
- new DefaultOptionBuilder();
-
- /** Argument Builder */
- private static final ArgumentBuilder aBuilder = new ArgumentBuilder();
-
- /** Group Builder */
- private static final GroupBuilder gBuilder = new GroupBuilder();
-
- private static Group options;
-
- public static Test suite() {
- return new TestSuite(LsTest.class);
- }
-
- /**
- * Required ctor.
- *
- * @param name
- * the name of the TestCase
- */
- public LsTest(final String name) {
- super(name);
- }
-
- public void setUp() {
- if (LsTest.options == null) {
- final Option a =
- oBuilder
- .withShortName("a")
- .withLongName("all")
- .withDescription("do not hide entries starting with .")
- .create();
-
- final Option blockSize =
- oBuilder
- .withLongName("block-size")
- .withRequired(false)
- .withDescription("use SIZE-byte blocks")
- .withArgument(
- aBuilder
- .withMaximum(1)
- .withMinimum(1)
- .withInitialSeparator('=')
- .create())
- .create();
-
- final Option c =
- oBuilder
- .withShortName("c")
- .withRequired(false)
- .withDescription("with -lt: sort by, and show, ctime
(time of last modification of file status information) with -l:show ctime and
sort by name otherwise: sort by ctime")
- .create();
-
- final Set colors = new HashSet();
- colors.add("never");
- colors.add("always");
- colors.add("auto");
- final Option color =
- oBuilder
- .withLongName("color")
- .withRequired(false)
- .withDescription("control whether color is used to
distinguish file types. WHEN may be `never', `always', or `auto'")
- .withArgument(
- aBuilder
- .withMaximum(1)
- .withMinimum(1)
- .withInitialSeparator('=')
- .withValidator(new EnumValidator(colors))
- .create())
- .create();
-
- LsTest.options =
- gBuilder
- .withOption(a)
- .withOption(blockSize)
- .withOption(c)
- .withOption(color)
- .create();
- }
- }
-
- public void testLs() throws OptionException {
- // create the command line parser
- Parser parser = new Parser();
- parser.setGroup(options);
- CommandLine line =
- parser.parse(new String[] { "--block-size=10", "--color=never"
});
-
- assertTrue(line.hasOption("--block-size"));
- assertEquals(line.getValue("--block-size"), "10");
- assertFalse(line.hasOption("--ignore-backups"));
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.application;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import net.dpml.cli.CommandLine;
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+import net.dpml.cli.validation.EnumValidator;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * <p>Test the <code>ls</code> command. Duplicated Option types are not
+ * tested e.g. -a and -d are the same Option type.</p>
+ *
+ * <p>The following is the man output for 'ls'. See
+ * http://www.rt.com/man/ls.1.html.</p>
+ *
+ * <pre>
+ * LS(1) FSF LS(1)
+ *
+ * NAME ls - list directory contents
+ *
+ * SYNOPSIS ls [OPTION]... [FILE]...
+ *
+ * DESCRIPTION List information about the FILEs (the current directory by
default). Sort entries alphabetically if none of -cftuSUX nor --sort.
+ *
+ * -a, --all do not hide entries starting with .
+ *
+ * -A, --almost-all do not list implied . and ..
+ *
+ * -b, --escape print octal escapes for nongraphic characters
+ *
+ * --block-size=SIZE use SIZE-byte blocks
+ *
+ * -B, --ignore-backups do not list implied entries ending with ~ -c sort
by change time; with -l: show ctime -C list entries by columns
+ *
+ * --color[=WHEN] control whether color is used to distinguish file types.
WHEN may be `never', `always', or `auto'
+ *
+ * -d, --directory list directory entries instead of contents
+ *
+ * -D, --dired generate output designed for Emacs' dired mode -f do not
sort, enable -aU, disable -lst
+ *
+ * -F, --classify append indicator (one of /=@|*) to entries
+ *
+ * --format=WORD across -x, commas -m, horizontal -x, long -l, sin-
gle-column -1, verbose -l, vertical -C
+ *
+ * --full-time list both full date and full time -g (ignored)
+ *
+ * -G, --no-group inhibit display of group information
+ *
+ * -h, --human-readable print sizes in human readable format (e.g., 1K 234M
2G)
+ *
+ * -H, --si likewise, but use powers of 1000 not 1024
+ *
+ * --indicator-style=WORD append indicator with style WORD to entry names:
none (default), classify (-F), file-type (-p)
+ *
+ * -i, --inode print index number of each file
+ *
+ * -I, --ignore=PATTERN do not list implied entries matching shell PATTERN
+ *
+ * -k, --kilobytes like --block-size=1024 -l use a long listing format
+ *
+ * -L, --dereference list entries pointed to by symbolic links -m fill
width with a comma separated list of entries
+ *
+ * -n, --numeric-uid-gid list numeric UIDs and GIDs instead of names
+ *
+ * -N, --literal print raw entry names (don't treat e.g. control characters
specially) -o use long listing format without group info
+ *
+ * -p, --file-type append indicator (one of /=@|) to entries
+ *
+ * -q, --hide-control-chars print ? instead of non graphic characters
+ *
+ * --show-control-chars show non graphic characters as-is (default)
+ *
+ * -Q, --quote-name enclose entry names in double quotes
+ *
+ * --quoting-style=WORD use quoting style WORD for entry names: literal,
shell, shell-always, c, escape
+ *
+ * -r, --reverse reverse order while sorting
+ *
+ * -R, --recursive list subdirectories recursively
+ *
+ * -s, --size print size of each file, in blocks -S sort by file size
+ *
+ * --sort=WORD extension -X, none -U, size -S, time -t, version -v status
-c, time -t, atime -u, access -u, use -u
+ *
+ * --time=WORD show time as WORD instead of modification time: atime,
access, use, ctime or status; use specified time as sort key if --sort=time
-t sort by modification time
+ *
+ * -T, --tabsize=COLS assume tab stops at each COLS instead of 8 -u sort by
last access time; with -l: show atime -U do not sort; list entries in
directory order -v sort by version
+ *
+ * -w, --width=COLS assume screen width instead of current value -x list
entries by lines instead of by columns -X sort alphabetically by entry
extension -1 list one file per line
+ *
+ * --help display this help and exit
+ *
+ * --version output version information and exit
+ *
+ * By default, color is not used to distinguish types of files. That is
equivalent to using --color=none. Using the --color option without the
optional WHEN argument is equivalent to using --color=always. With
--color=auto, color codes are output only if standard output is con- nected
to a terminal (tty).
+ * </pre>
+ *
+ * @author Rob Oxspring
+ * @author John Keyes
+ */
+public class LsTest extends TestCase
+{
+ /** Option Builder */
+ private static final DefaultOptionBuilder oBuilder = new
DefaultOptionBuilder( );
+
+ /** Argument Builder */
+ private static final ArgumentBuilder aBuilder = new ArgumentBuilder( );
+
+ /** Group Builder */
+ private static final GroupBuilder gBuilder = new GroupBuilder( );
+ private static Group options;
+
+ /**
+ * Required ctor.
+ *
+ * @param name
+ * the name of the TestCase
+ */
+ public LsTest( final String name )
+ {
+ super( name );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Test suite( )
+ {
+ return new TestSuite( LsTest.class );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void setUp( )
+ {
+ if( LsTest.options == null )
+ {
+ final Option a = oBuilder.withShortName( "a" ).withLongName(
"all" )
+ .withDescription( "do not hide entries
starting with ." )
+ .create( );
+
+ final Option blockSize = oBuilder.withLongName( "block-size" )
+ .withRequired( false )
+ .withDescription( "use
SIZE-byte blocks" )
+ .withArgument(
aBuilder.withMaximum(
+ 1 ).withMinimum( 1 ).withInitialSeparator( '='
).create( ) )
+ .create( );
+
+ final Option c = oBuilder.withShortName( "c" ).withRequired(
false )
+ .withDescription( "with -lt: sort by,
and show, ctime (time of last modification of file status information) with
-l:show ctime and sort by name otherwise: sort by ctime" )
+ .create( );
+
+ final Set colors = new HashSet( );
+ colors.add( "never" );
+ colors.add( "always" );
+ colors.add( "auto" );
+
+ final Option color = oBuilder.withLongName( "color" )
+ .withRequired( false )
+ .withDescription( "control whether
color is used to distinguish file types. WHEN may be `never', `always', or
`auto'" )
+ .withArgument(
aBuilder.withMaximum( 1 )
+
.withMinimum( 1 )
+
.withInitialSeparator( '=' )
+
.withValidator( new EnumValidator(
+ colors ) ).create( ) ).create( );
+
+ LsTest.options = gBuilder.withOption( a ).withOption( blockSize )
+ .withOption( c ).withOption( color )
+ .create( );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testLs( ) throws OptionException
+ {
+ // create the command line parser
+ Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ CommandLine line = parser.parse( new String[]
+ {
+ "--block-size=10", "--color=never"
+ } );
+
+ assertTrue( line.hasOption( "--block-size" ) );
+ assertEquals( line.getValue( "--block-size" ), "10" );
+ assertFalse( line.hasOption( "--ignore-backups" ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug13886Test.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug13886Test.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug13886Test.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,88 +1,101 @@
-/**
- * Copyright 2003-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 net.dpml.cli.bug;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-
-/**
- * @author John Keyes
- */
-public class Bug13886Test extends TestCase {
-
- public Bug13886Test(final String name) {
- super(name);
- }
-
- public void testMandatoryGroup() throws Exception {
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
-
- final Option a = obuilder.withShortName("a").create();
-
- final Option b = obuilder.withShortName("b").create();
-
- final Group options =
- gbuilder
- .withOption(a)
- .withOption(b)
- .withMaximum(1)
- .withMinimum(1)
- .create();
-
- final Parser parser = new Parser();
- parser.setGroup(options);
-
- try {
- parser.parse(new String[] {
- });
- fail("Expected MissingOptionException not caught");
- }
- catch (final OptionException exp) {
- assertEquals("Missing option -a|-b", exp.getMessage());
- }
-
- try {
- parser.parse(new String[] { "-a" });
- }
- catch (final OptionException exp) {
- fail("Unexpected MissingOptionException caught");
- }
-
- try {
- parser.parse(new String[] { "-b" });
- }
- catch (final OptionException exp) {
- fail("Unexpected MissingOptionException caught");
- }
-
- try {
- parser.parse(new String[] { "-a", "-b" });
- fail("Expected UnexpectedOptionException not caught");
- }
- catch (final OptionException exp) {
- assertEquals(
- "Unexpected -b while processing -a|-b",
- exp.getMessage());
- }
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.bug;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+
+/**
+ * @author John Keyes
+ */
+public class Bug13886Test extends TestCase
+{
+ /**
+ * Creates a new Bug13886Test object.
+ *
+ * @param name DOCUMENT ME!
+ */
+ public Bug13886Test( final String name )
+ {
+ super( name );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testMandatoryGroup( ) throws Exception
+ {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+
+ final Option a = obuilder.withShortName( "a" ).create( );
+
+ final Option b = obuilder.withShortName( "b" ).create( );
+
+ final Group options = gbuilder.withOption( a ).withOption( b )
+ .withMaximum( 1 ).withMinimum( 1
).create( );
+
+ final Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ try
+ {
+ parser.parse( new String[]{} );
+ fail( "Expected MissingOptionException not caught" );
+ }
+ catch( final OptionException exp )
+ {
+ assertEquals( "Missing option -a|-b", exp.getMessage( ) );
+ }
+
+ try
+ {
+ parser.parse( new String[]{"-a"} );
+ }
+ catch( final OptionException exp )
+ {
+ fail( "Unexpected MissingOptionException caught" );
+ }
+
+ try
+ {
+ parser.parse( new String[]{"-b"} );
+ }
+ catch( final OptionException exp )
+ {
+ fail( "Unexpected MissingOptionException caught" );
+ }
+
+ try
+ {
+ parser.parse( new String[]{"-a", "-b"} );
+ fail( "Expected UnexpectedOptionException not caught" );
+ }
+ catch( final OptionException exp )
+ {
+ assertEquals( "Unexpected -b while processing -a|-b",
+ exp.getMessage( ) );
+ }
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug13935Test.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug13935Test.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug13935Test.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,59 +1,71 @@
-/**
- * Copyright 2003-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 net.dpml.cli.bug;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-
-/**
- * @author John Keyes
- */
-public class Bug13935Test extends TestCase {
-
- public Bug13935Test(final String name) {
- super(name);
- }
-
- public void testRequiredGroup() throws Exception {
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
-
- final Option testOption =
- obuilder
- .withShortName("a")
- .withArgument(abuilder.withName("quoted string").create())
- .create();
-
- final Group options = gbuilder.withOption(testOption).create();
-
- final Parser parser = new Parser();
- parser.setGroup(options);
-
- final CommandLine cmdLine =
- parser.parse(new String[] { "-a", "\"two tokens\"" });
-
- assertTrue(cmdLine.hasOption("-a"));
- assertEquals("two tokens", cmdLine.getValue("-a"));
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.bug;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.CommandLine;
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+
+/**
+ * @author John Keyes
+ */
+public class Bug13935Test extends TestCase
+{
+ /**
+ * Creates a new Bug13935Test object.
+ *
+ * @param name DOCUMENT ME!
+ */
+ public Bug13935Test( final String name )
+ {
+ super( name );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testRequiredGroup( ) throws Exception
+ {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ final ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+
+ final Option testOption = obuilder.withShortName( "a" )
+ .withArgument( abuilder.withName(
+ "quoted string" ).create( ) ).create( );
+
+ final Group options = gbuilder.withOption( testOption ).create( );
+
+ final Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ final CommandLine cmdLine = parser.parse( new String[]
+ {
+ "-a", "\"two tokens\""
+ } );
+
+ assertTrue( cmdLine.hasOption( "-a" ) );
+ assertEquals( "two tokens", cmdLine.getValue( "-a" ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug15046Test.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug15046Test.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug15046Test.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,81 +1,84 @@
-/**
- * Copyright 2003-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 net.dpml.cli.bug;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-
-/**
- * @author John Keyes
- */
-public class Bug15046Test extends TestCase {
-
- public Bug15046Test(String name) {
- super(name);
- }
-
- public void testParamNamedAsOption() throws Exception {
- final String[] CLI_ARGS = new String[] { "-z", "c" };
-
- DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- ArgumentBuilder abuilder = new ArgumentBuilder();
-
- Option option =
- obuilder
- .withShortName("z")
- .withLongName("timezone")
- .withDescription("affected option")
- .withArgument(abuilder.withName("timezone").create())
- .create();
-
- GroupBuilder gbuilder = new GroupBuilder();
- Group options =
- gbuilder.withName("bug15046").withOption(option).create();
-
- Parser parser = new Parser();
- parser.setGroup(options);
- CommandLine line = parser.parse(CLI_ARGS);
-
- assertEquals("c", line.getValue("-z"));
-
- Option c =
- obuilder
- .withShortName("c")
- .withLongName("conflict")
- .withDescription("conflicting option")
- .withArgument(abuilder.withName("conflict").create())
- .create();
-
- options =
- gbuilder
- .withName("bug15046")
- .withOption(option)
- .withOption(c)
- .create();
-
- parser.setGroup(options);
- line = parser.parse(CLI_ARGS);
-
- assertEquals("c", line.getValue("-z"));
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.bug;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.CommandLine;
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+
+/**
+ * @author John Keyes
+ */
+public class Bug15046Test extends TestCase
+{
+ /**
+ * Creates a new Bug15046Test object.
+ *
+ * @param name DOCUMENT ME!
+ */
+ public Bug15046Test( String name )
+ {
+ super( name );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testParamNamedAsOption( ) throws Exception
+ {
+ final String[] CLI_ARGS = new String[]{"-z", "c"};
+
+ DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ ArgumentBuilder abuilder = new ArgumentBuilder( );
+
+ Option option = obuilder.withShortName( "z" ).withLongName(
"timezone" )
+ .withDescription( "affected option" )
+ .withArgument( abuilder.withName( "timezone"
)
+ .create( ) ).create(
);
+
+ GroupBuilder gbuilder = new GroupBuilder( );
+ Group options = gbuilder.withName( "bug15046" ).withOption( option )
+ .create( );
+
+ Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ CommandLine line = parser.parse( CLI_ARGS );
+
+ assertEquals( "c", line.getValue( "-z" ) );
+
+ Option c = obuilder.withShortName( "c" ).withLongName( "conflict" )
+ .withDescription( "conflicting option" )
+ .withArgument( abuilder.withName( "conflict" )
+ .create( ) ).create( );
+
+ options = gbuilder.withName( "bug15046" ).withOption( option )
+ .withOption( c ).create( );
+
+ parser.setGroup( options );
+ line = parser.parse( CLI_ARGS );
+
+ assertEquals( "c", line.getValue( "-z" ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug15648Test.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug15648Test.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug15648Test.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,59 +1,71 @@
-/**
- * Copyright 2003-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 net.dpml.cli.bug;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-
-/**
- * @author John Keyes
- */
-public class Bug15648Test extends TestCase {
-
- public Bug15648Test(final String name) {
- super(name);
- }
-
- public void testQuotedArgumentValue() throws Exception {
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
-
- final Option testOption =
- obuilder
- .withShortName("a")
- .withArgument(abuilder.withName("quoted string").create())
- .create();
-
- final Group options = gbuilder.withOption(testOption).create();
-
- final Parser parser = new Parser();
- parser.setGroup(options);
-
- final CommandLine cmdLine =
- parser.parse(new String[] { "-a", "\"two tokens\"" });
-
- assertTrue(cmdLine.hasOption("-a"));
- assertEquals("two tokens", cmdLine.getValue("-a"));
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.bug;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.CommandLine;
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+
+/**
+ * @author John Keyes
+ */
+public class Bug15648Test extends TestCase
+{
+ /**
+ * Creates a new Bug15648Test object.
+ *
+ * @param name DOCUMENT ME!
+ */
+ public Bug15648Test( final String name )
+ {
+ super( name );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testQuotedArgumentValue( ) throws Exception
+ {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ final ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+
+ final Option testOption = obuilder.withShortName( "a" )
+ .withArgument( abuilder.withName(
+ "quoted string" ).create( ) ).create( );
+
+ final Group options = gbuilder.withOption( testOption ).create( );
+
+ final Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ final CommandLine cmdLine = parser.parse( new String[]
+ {
+ "-a", "\"two tokens\""
+ } );
+
+ assertTrue( cmdLine.hasOption( "-a" ) );
+ assertEquals( "two tokens", cmdLine.getValue( "-a" ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug27575Test.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug27575Test.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug27575Test.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,40 +1,51 @@
-/**
- * Copyright 2003-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 net.dpml.cli.bug;
-
-import java.util.Iterator;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.Option;
-import net.dpml.cli.builder.PatternBuilder;
-import net.dpml.cli.option.GroupImpl;
-
-public class Bug27575Test extends TestCase {
-
- public void testRequiredOptions(){
- PatternBuilder builder = new PatternBuilder();
- builder.withPattern("hc!<");
- Option option = builder.create();
- assertTrue(option instanceof GroupImpl);
-
- GroupImpl group = (GroupImpl)option;
- Iterator i = group.getOptions().iterator();
- assertEquals("[-h]",i.next().toString());
- assertEquals("-c <arg>",i.next().toString());
- assertFalse(i.hasNext());
- }
-}
\ No newline at end of file
+/**
+ * Copyright 2003-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 net.dpml.cli.bug;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.Option;
+import net.dpml.cli.builder.PatternBuilder;
+import net.dpml.cli.option.GroupImpl;
+
+import java.util.Iterator;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Bug27575Test extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ */
+ public void testRequiredOptions( )
+ {
+ PatternBuilder builder = new PatternBuilder( );
+ builder.withPattern( "hc!<" );
+
+ Option option = builder.create( );
+ assertTrue( option instanceof GroupImpl );
+
+ GroupImpl group = (GroupImpl) option;
+ Iterator i = group.getOptions( ).iterator( );
+ assertEquals( "[-h]", i.next( ).toString( ) );
+ assertEquals( "-c <arg>", i.next( ).toString( ) );
+ assertFalse( i.hasNext( ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug28005Test.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug28005Test.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug28005Test.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,78 +1,83 @@
-/**
- * Copyright 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 net.dpml.cli.bug;
-
-import net.dpml.cli.Argument;
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.CommandBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-import junit.framework.TestCase;
-
-public class Bug28005Test extends TestCase {
- public void testInfiniteLoop() {
- final DefaultOptionBuilder optionBuilder = new
DefaultOptionBuilder();
- final ArgumentBuilder argumentBuilder = new ArgumentBuilder();
- final GroupBuilder groupBuilder = new GroupBuilder();
- final CommandBuilder commandBuilder = new CommandBuilder();
-
- final Option inputFormatOption =
- optionBuilder
- .withLongName("input-format")
- //.withArgument(argumentBuilder.create())
- .create();
-
- final Argument argument =
- argumentBuilder
- .withName("file")
- .create();
-
- final Group children =
- groupBuilder
- .withName("options")
- .withOption(inputFormatOption)
- .create();
-
- final Option command =
- commandBuilder
- .withName("convert")
- .withChildren(children)
- .withArgument(argument)
- .create();
-
- final Group root =
- groupBuilder
- .withName("commands")
- .withOption(command)
- .create();
-
- final Parser parser = new Parser();
- parser.setGroup(root);
- final String[] args = new String[]{"convert", "test.txt",
- "--input-format", "a"};
-
- try {
- parser.parse(args);
- fail("a isn't valid!!");
- } catch (OptionException e) {
- assertEquals("Unexpected a while processing
commands",e.getMessage());
- }
- }
-}
\ No newline at end of file
+/**
+ * Copyright 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 net.dpml.cli.bug;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.Argument;
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.CommandBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Bug28005Test extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ */
+ public void testInfiniteLoop( )
+ {
+ final DefaultOptionBuilder optionBuilder = new DefaultOptionBuilder(
);
+ final ArgumentBuilder argumentBuilder = new ArgumentBuilder( );
+ final GroupBuilder groupBuilder = new GroupBuilder( );
+ final CommandBuilder commandBuilder = new CommandBuilder( );
+
+ final Option inputFormatOption = optionBuilder.withLongName(
+ "input-format" ).create( );
+
+ final Argument argument = argumentBuilder.withName( "file" ).create(
);
+
+ final Group children = groupBuilder.withName( "options" )
+ .withOption( inputFormatOption )
+ .create( );
+
+ final Option command = commandBuilder.withName( "convert" )
+ .withChildren( children )
+ .withArgument( argument
).create( );
+
+ final Group root = groupBuilder.withName( "commands" )
+ .withOption( command ).create( );
+
+ final Parser parser = new Parser( );
+ parser.setGroup( root );
+
+ final String[] args = new String[]
+ {
+ "convert", "test.txt", "--input-format", "a"
+ };
+
+ try
+ {
+ parser.parse( args );
+ fail( "a isn't valid!!" );
+ }
+ catch( OptionException e )
+ {
+ assertEquals( "Unexpected a while processing commands",
+ e.getMessage( ) );
+ }
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug32533Test.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug32533Test.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/bug/Bug32533Test.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,47 +1,52 @@
-/**
- * Copyright 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 net.dpml.cli.bug;
-
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-
-import junit.framework.TestCase;
-
-/**
- * @author roxspring
- */
-public class Bug32533Test extends TestCase {
-
- public void testBlah() throws OptionException {
-
- Option a1 = new DefaultOptionBuilder().withLongName("a1").create();
- Option b1 = new DefaultOptionBuilder().withLongName("b1").create();
- Option c1 = new DefaultOptionBuilder().withLongName("c1").create();
-
- Group b = new GroupBuilder().withOption(b1).create();
- Group c = new GroupBuilder().withOption(c1).create();
- Group a = new
GroupBuilder().withOption(a1).withOption(b).withOption(c).create();
-
- Parser parser = new Parser();
- parser.setGroup(a);
- parser.parse(new String[]{"--a1","--b1"});
- }
-
-}
+/**
+ * Copyright 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 net.dpml.cli.bug;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+
+/**
+ * @author roxspring
+ */
+public class Bug32533Test extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testBlah( ) throws OptionException
+ {
+ Option a1 = new DefaultOptionBuilder( ).withLongName( "a1"
).create( );
+ Option b1 = new DefaultOptionBuilder( ).withLongName( "b1"
).create( );
+ Option c1 = new DefaultOptionBuilder( ).withLongName( "c1"
).create( );
+
+ Group b = new GroupBuilder( ).withOption( b1 ).create( );
+ Group c = new GroupBuilder( ).withOption( c1 ).create( );
+ Group a = new GroupBuilder( ).withOption( a1 ).withOption( b )
+ .withOption( c ).create( );
+
+ Parser parser = new Parser( );
+ parser.setGroup( a );
+ parser.parse( new String[]{"--a1", "--b1"} );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/bug/BugLoopingOptionLookAlikeTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/bug/BugLoopingOptionLookAlikeTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/bug/BugLoopingOptionLookAlikeTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -27,50 +27,79 @@
import net.dpml.cli.option.SourceDestArgument;

/**
- * The first is a loop in Parser.parse() if I set a non-declared option.
This
- * code goes into a loop in Parser.java method parse this �while� loop runs
+ * The first is a loop in Parser.parse() if I set a non-declared option. This
+ * code goes into a loop in Parser.java method parse this �while� loop runs
* endless
- *
+ *
* @author Steve Alberty
*/
-public class BugLoopingOptionLookAlikeTest extends TestCase {
+public class BugLoopingOptionLookAlikeTest extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ */
+ public void testLoopingOptionLookAlike( )
+ {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder( );
+ final ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+ final Group options = gbuilder.withName( "ant" )
+ .withOption( obuilder.withShortName(
+ "help" ).withDescription( "print this message" ).create(
) )
+ .withOption( obuilder.withShortName(
+ "projecthelp" )
+ .withDescription(
"print project help information" )
+ .create( ) )
+ .withOption( abuilder.withName(
"target" )
+ .create( )
).create( );

- public void testLoopingOptionLookAlike() {
- final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
- final Group options = gbuilder
- .withName("ant")
-
.withOption(obuilder.withShortName("help").withDescription("print this
message").create())
-
.withOption(obuilder.withShortName("projecthelp").withDescription("print
project help information").create())
- .withOption(abuilder.withName("target").create())
- .create();
-
- final Parser parser = new Parser();
- parser.setGroup(options);
- try {
- parser.parse(new String[] { "-abcdef",
- "testfile.txt ", });
- fail("OptionException");
- } catch (OptionException e) {
- assertEquals("Unexpected -abcdef while processing
ant",e.getMessage());
+ final Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ try
+ {
+ parser.parse( new String[]{"-abcdef", "testfile.txt ",} );
+ fail( "OptionException" );
}
+ catch( OptionException e )
+ {
+ assertEquals( "Unexpected -abcdef while processing ant",
+ e.getMessage( ) );
+ }
}
-
- public void testLoopingOptionLookAlike2() {
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
- final Argument inputfile_opt =
abuilder.withName("input").withMinimum(1).withMaximum(1).create();
- final Argument outputfile_opt =
abuilder.withName("output").withMinimum(1).withMaximum(1).create();
- final Argument targets = new SourceDestArgument(inputfile_opt,
outputfile_opt);
- final Group options = gbuilder.withOption(targets).create();
- final Parser parser = new Parser();
- parser.setGroup(options);
- try {
- parser.parse(new String[] { "testfile.txt", "testfile.txt",
"testfile.txt", "testfile.txt" });
- fail("OptionException");
- } catch (OptionException e) {
- assertEquals("Unexpected testfile.txt while processing ",
e.getMessage());
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testLoopingOptionLookAlike2( )
+ {
+ final ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+ final Argument inputfile_opt = abuilder.withName( "input" )
+ .withMinimum( 1
).withMaximum( 1 )
+ .create( );
+ final Argument outputfile_opt = abuilder.withName( "output" )
+ .withMinimum( 1
).withMaximum( 1 )
+ .create( );
+ final Argument targets = new SourceDestArgument( inputfile_opt,
+ outputfile_opt );
+ final Group options = gbuilder.withOption( targets ).create( );
+ final Parser parser = new Parser( );
+ parser.setGroup( options );
+
+ try
+ {
+ parser.parse( new String[]
+ {
+ "testfile.txt", "testfile.txt", "testfile.txt",
+ "testfile.txt"
+ } );
+ fail( "OptionException" );
}
- }
+ catch( OptionException e )
+ {
+ assertEquals( "Unexpected testfile.txt while processing ",
+ e.getMessage( ) );
+ }
+ }
}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/builder/ArgumentBuilderTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/builder/ArgumentBuilderTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/builder/ArgumentBuilderTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -15,237 +15,364 @@
*/
package net.dpml.cli.builder;

-import java.util.ArrayList;
-import java.util.List;
-
import junit.framework.TestCase;

import net.dpml.cli.option.ArgumentImpl;
import net.dpml.cli.resource.ResourceConstants;
import net.dpml.cli.resource.ResourceHelper;
+
//import net.dpml.cli.validation.DateValidator;
import net.dpml.cli.validation.Validator;

-public class ArgumentBuilderTest
- extends TestCase {
- private static final ResourceHelper resources =
ResourceHelper.getResourceHelper();
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class ArgumentBuilderTest extends TestCase
+{
+ private static final ResourceHelper resources =
ResourceHelper.getResourceHelper( );
private ArgumentBuilder argumentBuilder;

/*
* @see TestCase#setUp()
*/
- protected void setUp()
- throws Exception {
- this.argumentBuilder = new ArgumentBuilder();
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ protected void setUp( ) throws Exception
+ {
+ this.argumentBuilder = new ArgumentBuilder( );
}

- public void testConsumeRemaining() {
- this.argumentBuilder.withConsumeRemaining("--");
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testConsumeRemaining( )
+ {
+ this.argumentBuilder.withConsumeRemaining( "--" );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect consume remaining token", "--",
arg.getConsumeRemaining());
+ assertEquals( "incorrect consume remaining token", "--",
+ arg.getConsumeRemaining( ) );
}

- public void testNullConsumeRemaining() {
- try {
- this.argumentBuilder.withConsumeRemaining(null);
- fail("cannot use null consume remaining token");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_CONSUME_REMAINING),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullConsumeRemaining( )
+ {
+ try
+ {
+ this.argumentBuilder.withConsumeRemaining( null );
+ fail( "cannot use null consume remaining token" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+
ResourceConstants.ARGUMENT_BUILDER_NULL_CONSUME_REMAINING ),
+ exp.getMessage( ) );
+ }
}

- public void testEmptyConsumeRemaining() {
- try {
- this.argumentBuilder.withConsumeRemaining("");
- fail("cannot use empty string consume remaining token");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_EMPTY_CONSUME_REMAINING),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testEmptyConsumeRemaining( )
+ {
+ try
+ {
+ this.argumentBuilder.withConsumeRemaining( "" );
+ fail( "cannot use empty string consume remaining token" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+
ResourceConstants.ARGUMENT_BUILDER_EMPTY_CONSUME_REMAINING ),
+ exp.getMessage( ) );
+ }
}

- public void testDefault() {
- this.argumentBuilder.withDefault("defaultString");
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testDefault( )
+ {
+ this.argumentBuilder.withDefault( "defaultString" );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect number of default values", 1,
arg.getDefaultValues().size());
- assertEquals("incorrect default value", "defaultString",
arg.getDefaultValues().get(0));
+ assertEquals( "incorrect number of default values", 1,
+ arg.getDefaultValues( ).size( ) );
+ assertEquals( "incorrect default value", "defaultString",
+ arg.getDefaultValues( ).get( 0 ) );
}

- public void testDefaultX2() {
- this.argumentBuilder.withDefault("defaultString1");
- this.argumentBuilder.withDefault("defaultString2");
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testDefaultX2( )
+ {
+ this.argumentBuilder.withDefault( "defaultString1" );
+ this.argumentBuilder.withDefault( "defaultString2" );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect number of default values", 2,
arg.getDefaultValues().size());
- assertEquals("incorrect default value-1", "defaultString1",
arg.getDefaultValues().get(0));
- assertEquals("incorrect default value-2", "defaultString2",
arg.getDefaultValues().get(1));
+ assertEquals( "incorrect number of default values", 2,
+ arg.getDefaultValues( ).size( ) );
+ assertEquals( "incorrect default value-1", "defaultString1",
+ arg.getDefaultValues( ).get( 0 ) );
+ assertEquals( "incorrect default value-2", "defaultString2",
+ arg.getDefaultValues( ).get( 1 ) );
}

- public void testNullDefault() {
- try {
- this.argumentBuilder.withDefault(null);
- fail("cannot use null default");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULT),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullDefault( )
+ {
+ try
+ {
+ this.argumentBuilder.withDefault( null );
+ fail( "cannot use null default" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+ ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULT ),
+ exp.getMessage( ) );
+ }
}

- public void testDefaults() {
- final List defaults = new ArrayList();
- defaults.add("one");
- defaults.add("two");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testDefaults( )
+ {
+ final List defaults = new ArrayList( );
+ defaults.add( "one" );
+ defaults.add( "two" );

- this.argumentBuilder.withDefaults(defaults);
- this.argumentBuilder.withName("arg");
+ this.argumentBuilder.withDefaults( defaults );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect number of default values", 2,
arg.getDefaultValues().size());
- assertEquals("incorrect default value-1", "one",
arg.getDefaultValues().get(0));
- assertEquals("incorrect default value-2", "two",
arg.getDefaultValues().get(1));
- assertEquals("incorrect default values list", defaults,
arg.getDefaultValues());
-
+ assertEquals( "incorrect number of default values", 2,
+ arg.getDefaultValues( ).size( ) );
+ assertEquals( "incorrect default value-1", "one",
+ arg.getDefaultValues( ).get( 0 ) );
+ assertEquals( "incorrect default value-2", "two",
+ arg.getDefaultValues( ).get( 1 ) );
+ assertEquals( "incorrect default values list", defaults,
+ arg.getDefaultValues( ) );
}

- public void testNullDefaults() {
- try {
- this.argumentBuilder.withDefaults(null);
- fail("cannot use null defaults");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULTS),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullDefaults( )
+ {
+ try
+ {
+ this.argumentBuilder.withDefaults( null );
+ fail( "cannot use null defaults" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+ ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULTS ),
+ exp.getMessage( ) );
+ }
}

- public void testId() {
- this.argumentBuilder.withId(1);
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testId( )
+ {
+ this.argumentBuilder.withId( 1 );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect id", 1, arg.getId());
+ assertEquals( "incorrect id", 1, arg.getId( ) );
}

- public void testInitialSeparator() {
- this.argumentBuilder.withInitialSeparator(',');
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testInitialSeparator( )
+ {
+ this.argumentBuilder.withInitialSeparator( ',' );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect initial separator", ',',
arg.getInitialSeparator());
+ assertEquals( "incorrect initial separator", ',',
+ arg.getInitialSeparator( ) );
}

- public void testMaximum() {
- this.argumentBuilder.withMaximum(1);
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testMaximum( )
+ {
+ this.argumentBuilder.withMaximum( 1 );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect maximum", 1, arg.getMaximum());
+ assertEquals( "incorrect maximum", 1, arg.getMaximum( ) );
}

- public void testNegativeMaximum() {
- try {
- this.argumentBuilder.withMaximum(-1);
- fail("cannot use negative maximum");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MAXIMUM),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNegativeMaximum( )
+ {
+ try
+ {
+ this.argumentBuilder.withMaximum( -1 );
+ fail( "cannot use negative maximum" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+ ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MAXIMUM ),
+ exp.getMessage( ) );
+ }
}

- public void testMinimum() {
- this.argumentBuilder.withMinimum(1);
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testMinimum( )
+ {
+ this.argumentBuilder.withMinimum( 1 );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect maximum", 1, arg.getMinimum());
+ assertEquals( "incorrect maximum", 1, arg.getMinimum( ) );
}

- public void testNegativeMinimum() {
- try {
- this.argumentBuilder.withMinimum(-1);
- fail("cannot use negative minimum");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MINIMUM),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNegativeMinimum( )
+ {
+ try
+ {
+ this.argumentBuilder.withMinimum( -1 );
+ fail( "cannot use negative minimum" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+ ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MINIMUM ),
+ exp.getMessage( ) );
+ }
}

- public void testName() {
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testName( )
+ {
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect preferred name", "arg",
arg.getPreferredName());
+ assertEquals( "incorrect preferred name", "arg",
+ arg.getPreferredName( ) );
}

- public void testNullName() {
- try {
- this.argumentBuilder.withName(null);
- fail("cannot use null name");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_NAME),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullName( )
+ {
+ try
+ {
+ this.argumentBuilder.withName( null );
+ fail( "cannot use null name" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+ ResourceConstants.ARGUMENT_BUILDER_NULL_NAME ),
+ exp.getMessage( ) );
+ }
}

- public void testEmptyName() {
- try {
- this.argumentBuilder.withName("");
- fail("cannot use empty name");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_EMPTY_NAME),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testEmptyName( )
+ {
+ try
+ {
+ this.argumentBuilder.withName( "" );
+ fail( "cannot use empty name" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+ ResourceConstants.ARGUMENT_BUILDER_EMPTY_NAME ),
+ exp.getMessage( ) );
+ }
}

- public void testSubsequentSeparator() {
- this.argumentBuilder.withSubsequentSeparator(':');
- this.argumentBuilder.withName("arg");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSubsequentSeparator( )
+ {
+ this.argumentBuilder.withSubsequentSeparator( ':' );
+ this.argumentBuilder.withName( "arg" );

- ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+ ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create( );

- assertEquals("incorrect subsequent separator", ':',
arg.getSubsequentSeparator());
+ assertEquals( "incorrect subsequent separator", ':',
+ arg.getSubsequentSeparator( ) );
}

//public void testValidator() {
- // Validator validator = DateValidator.getDateInstance();
- // this.argumentBuilder.withValidator(validator);
- // this.argumentBuilder.withName("arg");
- //
- // ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
- //
- // assertEquals("incorrect validator", validator, arg.getValidator());
- //}
-
- public void testNullValidator() {
- try {
- this.argumentBuilder.withValidator(null);
- fail("cannot use null validator");
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_VALIDATOR),
- exp.getMessage());
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullValidator( )
+ {
+ try
+ {
+ this.argumentBuilder.withValidator( null );
+ fail( "cannot use null validator" );
}
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ resources.getMessage(
+ ResourceConstants.ARGUMENT_BUILDER_NULL_VALIDATOR ),
+ exp.getMessage( ) );
+ }
}
}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/builder/DefaultOptionBuilderTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/builder/DefaultOptionBuilderTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/builder/DefaultOptionBuilderTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,199 +1,277 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.builder;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.Argument;
-import net.dpml.cli.Group;
-import net.dpml.cli.option.DefaultOption;
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-public class DefaultOptionBuilderTest
- extends TestCase {
- private static final ResourceHelper resources =
ResourceHelper.getResourceHelper();
- private DefaultOptionBuilder defaultOptionBuilder;
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp()
- throws Exception {
- this.defaultOptionBuilder = new DefaultOptionBuilder();
- }
-
- /*
- * Class to test for void DefaultOptionBuilder(String, String, boolean)
- */
- public void testNew_NullShortPrefix() {
- try {
- new DefaultOptionBuilder(null, null, false);
- fail("null short prefix is not permitted");
- } catch (IllegalArgumentException e) {
-
assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX),
- e.getMessage());
- }
- }
-
- /*
- * Class to test for void DefaultOptionBuilder(String, String, boolean)
- */
- public void testNew_EmptyShortPrefix() {
- try {
- new DefaultOptionBuilder("", null, false);
- fail("empty short prefix is not permitted");
- } catch (IllegalArgumentException e) {
-
assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX),
- e.getMessage());
- }
- }
-
- /*
- * Class to test for void DefaultOptionBuilder(String, String, boolean)
- */
- public void testNew_NullLongPrefix() {
- try {
- new DefaultOptionBuilder("-", null, false);
- fail("null long prefix is not permitted");
- } catch (IllegalArgumentException e) {
-
assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX),
- e.getMessage());
- }
- }
-
- /*
- * Class to test for void DefaultOptionBuilder(String, String, boolean)
- */
- public void testNew_EmptyLongPrefix() {
- try {
- new DefaultOptionBuilder("-", "", false);
- fail("empty long prefix is not permitted");
- } catch (IllegalArgumentException e) {
-
assertEquals(resources.getMessage(ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX),
- e.getMessage());
- }
- }
-
- public void testCreate() {
- try {
- this.defaultOptionBuilder.create();
- fail("options must have a name");
- } catch (IllegalStateException e) {
-
assertEquals(resources.getMessage(ResourceConstants.OPTION_NO_NAME),
e.getMessage());
- }
-
- this.defaultOptionBuilder.withShortName("j");
- this.defaultOptionBuilder.create();
- this.defaultOptionBuilder.withLongName("jkeyes");
- this.defaultOptionBuilder.create();
-
- {
- DefaultOptionBuilder builder = new DefaultOptionBuilder("-",
"--", true);
- builder.withShortName("mx");
- }
- }
-
- public void testName() {
- // withLongName && this.preferred != null
- {
- this.defaultOptionBuilder.withShortName("a");
- this.defaultOptionBuilder.withLongName("apples");
- }
- // withShortName && this.preferred != null
- {
- this.defaultOptionBuilder.withLongName("apples");
- this.defaultOptionBuilder.withShortName("a");
- }
- // withShortName && this.preferred != null
- {
- this.defaultOptionBuilder.withLongName("apples");
- this.defaultOptionBuilder.withShortName("a");
- }
- }
-
- public void testWithDescription() {
- String description = "desc";
- this.defaultOptionBuilder.withShortName("a");
- this.defaultOptionBuilder.withDescription(description);
-
- DefaultOption opt = this.defaultOptionBuilder.create();
- assertEquals("wrong description found", description,
opt.getDescription());
- }
-
- public void testWithRequired() {
- {
- boolean required = false;
- this.defaultOptionBuilder.withShortName("a");
- this.defaultOptionBuilder.withRequired(required);
-
- DefaultOption opt = this.defaultOptionBuilder.create();
- assertEquals("wrong required found", required, opt.isRequired());
- }
-
- {
- boolean required = true;
- this.defaultOptionBuilder.withShortName("a");
- this.defaultOptionBuilder.withRequired(required);
-
- DefaultOption opt = this.defaultOptionBuilder.create();
- assertEquals("wrong required found", required, opt.isRequired());
- }
- }
-
- public void testWithChildren() {
- GroupBuilder gbuilder = new GroupBuilder();
-
- this.defaultOptionBuilder.withShortName("a");
- this.defaultOptionBuilder.withRequired(true);
-
- DefaultOption opt = this.defaultOptionBuilder.create();
-
- Group group =
gbuilder.withName("withchildren").withOption(opt).create();
-
- {
- this.defaultOptionBuilder.withShortName("b");
- this.defaultOptionBuilder.withChildren(group);
-
- DefaultOption option = this.defaultOptionBuilder.create();
- assertEquals("wrong children found", group,
option.getChildren());
- }
- }
-
- public void testWithArgument() {
- ArgumentBuilder abuilder = new ArgumentBuilder();
- abuilder.withName("myarg");
-
- Argument arg = abuilder.create();
-
- this.defaultOptionBuilder.withShortName("a");
- this.defaultOptionBuilder.withRequired(true);
- this.defaultOptionBuilder.withArgument(arg);
-
- DefaultOption opt = this.defaultOptionBuilder.create();
-
- assertEquals("wrong argument found", arg, opt.getArgument());
- }
-
- public void testWithId() {
- this.defaultOptionBuilder.withShortName("a");
- this.defaultOptionBuilder.withId(0);
-
- DefaultOption opt = this.defaultOptionBuilder.create();
-
- assertEquals("wrong id found", 0, opt.getId());
- }
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.builder;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.Argument;
+import net.dpml.cli.Group;
+import net.dpml.cli.option.DefaultOption;
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class DefaultOptionBuilderTest extends TestCase
+{
+ private static final ResourceHelper resources =
ResourceHelper.getResourceHelper( );
+ private DefaultOptionBuilder defaultOptionBuilder;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ protected void setUp( ) throws Exception
+ {
+ this.defaultOptionBuilder = new DefaultOptionBuilder( );
+ }
+
+ /*
+ * Class to test for void DefaultOptionBuilder(String, String, boolean)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNew_NullShortPrefix( )
+ {
+ try
+ {
+ new DefaultOptionBuilder( null, null, false );
+ fail( "null short prefix is not permitted" );
+ }
+ catch( IllegalArgumentException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX ),
+ e.getMessage( ) );
+ }
+ }
+
+ /*
+ * Class to test for void DefaultOptionBuilder(String, String, boolean)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNew_EmptyShortPrefix( )
+ {
+ try
+ {
+ new DefaultOptionBuilder( "", null, false );
+ fail( "empty short prefix is not permitted" );
+ }
+ catch( IllegalArgumentException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.OPTION_ILLEGAL_SHORT_PREFIX ),
+ e.getMessage( ) );
+ }
+ }
+
+ /*
+ * Class to test for void DefaultOptionBuilder(String, String, boolean)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNew_NullLongPrefix( )
+ {
+ try
+ {
+ new DefaultOptionBuilder( "-", null, false );
+ fail( "null long prefix is not permitted" );
+ }
+ catch( IllegalArgumentException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX ),
+ e.getMessage( ) );
+ }
+ }
+
+ /*
+ * Class to test for void DefaultOptionBuilder(String, String, boolean)
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNew_EmptyLongPrefix( )
+ {
+ try
+ {
+ new DefaultOptionBuilder( "-", "", false );
+ fail( "empty long prefix is not permitted" );
+ }
+ catch( IllegalArgumentException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.OPTION_ILLEGAL_LONG_PREFIX ),
+ e.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCreate( )
+ {
+ try
+ {
+ this.defaultOptionBuilder.create( );
+ fail( "options must have a name" );
+ }
+ catch( IllegalStateException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.OPTION_NO_NAME ), e.getMessage( ) );
+ }
+
+ this.defaultOptionBuilder.withShortName( "j" );
+ this.defaultOptionBuilder.create( );
+ this.defaultOptionBuilder.withLongName( "jkeyes" );
+ this.defaultOptionBuilder.create( );
+
+ {
+ DefaultOptionBuilder builder = new DefaultOptionBuilder( "-",
"--",
+ true );
+ builder.withShortName( "mx" );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testName( )
+ {
+ // withLongName && this.preferred != null
+ {
+ this.defaultOptionBuilder.withShortName( "a" );
+ this.defaultOptionBuilder.withLongName( "apples" );
+ }
+ // withShortName && this.preferred != null
+ {
+ this.defaultOptionBuilder.withLongName( "apples" );
+ this.defaultOptionBuilder.withShortName( "a" );
+ }
+ // withShortName && this.preferred != null
+ {
+ this.defaultOptionBuilder.withLongName( "apples" );
+ this.defaultOptionBuilder.withShortName( "a" );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWithDescription( )
+ {
+ String description = "desc";
+ this.defaultOptionBuilder.withShortName( "a" );
+ this.defaultOptionBuilder.withDescription( description );
+
+ DefaultOption opt = this.defaultOptionBuilder.create( );
+ assertEquals( "wrong description found", description,
+ opt.getDescription( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWithRequired( )
+ {
+ {
+ boolean required = false;
+ this.defaultOptionBuilder.withShortName( "a" );
+ this.defaultOptionBuilder.withRequired( required );
+
+ DefaultOption opt = this.defaultOptionBuilder.create( );
+ assertEquals( "wrong required found", required, opt.isRequired(
) );
+ }
+
+ {
+ boolean required = true;
+ this.defaultOptionBuilder.withShortName( "a" );
+ this.defaultOptionBuilder.withRequired( required );
+
+ DefaultOption opt = this.defaultOptionBuilder.create( );
+ assertEquals( "wrong required found", required, opt.isRequired(
) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWithChildren( )
+ {
+ GroupBuilder gbuilder = new GroupBuilder( );
+
+ this.defaultOptionBuilder.withShortName( "a" );
+ this.defaultOptionBuilder.withRequired( true );
+
+ DefaultOption opt = this.defaultOptionBuilder.create( );
+
+ Group group = gbuilder.withName( "withchildren" ).withOption( opt )
+ .create( );
+
+ {
+ this.defaultOptionBuilder.withShortName( "b" );
+ this.defaultOptionBuilder.withChildren( group );
+
+ DefaultOption option = this.defaultOptionBuilder.create( );
+ assertEquals( "wrong children found", group, option.getChildren(
) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWithArgument( )
+ {
+ ArgumentBuilder abuilder = new ArgumentBuilder( );
+ abuilder.withName( "myarg" );
+
+ Argument arg = abuilder.create( );
+
+ this.defaultOptionBuilder.withShortName( "a" );
+ this.defaultOptionBuilder.withRequired( true );
+ this.defaultOptionBuilder.withArgument( arg );
+
+ DefaultOption opt = this.defaultOptionBuilder.create( );
+
+ assertEquals( "wrong argument found", arg, opt.getArgument( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWithId( )
+ {
+ this.defaultOptionBuilder.withShortName( "a" );
+ this.defaultOptionBuilder.withId( 0 );
+
+ DefaultOption opt = this.defaultOptionBuilder.create( );
+
+ assertEquals( "wrong id found", 0, opt.getId( ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/commandline/DefaultingCommandLineTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/commandline/DefaultingCommandLineTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/commandline/DefaultingCommandLineTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,150 +1,183 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.commandline;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Set;
-
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.AbstractCommandLineTestCase;
-import net.dpml.cli.Option;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-
-/**
- * @author Rob Oxspring
- */
-public class DefaultingCommandLineTest
- extends AbstractCommandLineTestCase {
- private CommandLine first;
- private CommandLine second;
- private Option inFirst = new
DefaultOptionBuilder().withLongName("infirst").create();
- private Option inBoth = new
DefaultOptionBuilder().withLongName("inboth").create();
- private Option inSecond = new
DefaultOptionBuilder().withLongName("insecond").create();
-
- /* (non-Javadoc)
- * @see net.dpml.cli.CommandLineTest#createCommandLine()
- */
- protected final CommandLine createCommandLine() {
- final WriteableCommandLine writeable = new
WriteableCommandLineImpl(root, new ArrayList());
- writeable.addOption(present);
- writeable.addProperty("present", "present property");
- writeable.addSwitch(bool, true);
- writeable.addValue(present, "present value");
- writeable.addOption(multiple);
- writeable.addValue(multiple, "value 1");
- writeable.addValue(multiple, "value 2");
- writeable.addValue(multiple, "value 3");
-
- final DefaultingCommandLine defaults = new DefaultingCommandLine();
- defaults.appendCommandLine(writeable);
-
- return defaults;
- }
-
- public void setUp()
- throws Exception {
- super.setUp();
-
- WriteableCommandLine writeable;
-
- writeable = new WriteableCommandLineImpl(root, new ArrayList());
- writeable.addOption(inFirst);
- writeable.addOption(inBoth);
- writeable.addProperty("infirst", "infirst first value");
- writeable.addProperty("inboth", "inboth first value");
- writeable.addSwitch(inFirst, true);
- writeable.addSwitch(inBoth, true);
- writeable.addValue(inFirst, "infirst first value 1");
- writeable.addValue(inFirst, "infirst first value 2");
- writeable.addValue(inBoth, "inboth first value 1");
- writeable.addValue(inBoth, "inboth first value 2");
- first = writeable;
-
- writeable = new WriteableCommandLineImpl(root, new ArrayList());
- writeable.addOption(inSecond);
- writeable.addOption(inBoth);
- writeable.addProperty("insecond", "insecond second value");
- writeable.addProperty("inboth", "inboth second value");
- writeable.addSwitch(inSecond, true);
- writeable.addSwitch(inBoth, true);
- writeable.addValue(inSecond, "insecond second value 1");
- writeable.addValue(inSecond, "insecond second value 2");
- writeable.addValue(inBoth, "inboth second value 1");
- writeable.addValue(inBoth, "inboth second value 2");
- second = writeable;
- }
-
- public final void testAppendCommandLine() {
- final DefaultingCommandLine defaults = new DefaultingCommandLine();
- Iterator i;
-
- i = defaults.commandLines();
- assertFalse(i.hasNext());
-
- defaults.appendCommandLine(first);
- i = defaults.commandLines();
- assertSame(first, i.next());
- assertFalse(i.hasNext());
-
- defaults.appendCommandLine(second);
- i = defaults.commandLines();
- assertSame(first, i.next());
- assertSame(second, i.next());
- assertFalse(i.hasNext());
- }
-
- public final void testInsertCommandLine() {
- final DefaultingCommandLine defaults = new DefaultingCommandLine();
- Iterator i;
-
- i = defaults.commandLines();
- assertFalse(i.hasNext());
-
- defaults.insertCommandLine(0, first);
- i = defaults.commandLines();
- assertSame(first, i.next());
- assertFalse(i.hasNext());
-
- defaults.insertCommandLine(0, second);
- i = defaults.commandLines();
- assertSame(second, i.next());
- assertSame(first, i.next());
- assertFalse(i.hasNext());
- }
-
- public void testTriggers() {
- final DefaultingCommandLine defaults = new DefaultingCommandLine();
- defaults.appendCommandLine(first);
- defaults.appendCommandLine(second);
-
- Set set = defaults.getOptionTriggers();
- Iterator iter = set.iterator();
- assertEquals("wrong # of triggers", 3, set.size());
- assertTrue("cannot find trigger", set.contains("--insecond"));
- assertTrue("cannot find trigger", set.contains("--inboth"));
- assertTrue("cannot find trigger", set.contains("--infirst"));
- }
-
- public void testDefaults() {
- final DefaultingCommandLine defaults = new DefaultingCommandLine();
-
- assertEquals("wrong # of defaults", 0,
defaults.getValues("--insecond").size());
- assertEquals("wrong Set of defaults", Collections.EMPTY_LIST,
defaults.getValues("--insecond", null));
- }
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.commandline;
+
+import net.dpml.cli.AbstractCommandLineTestCase;
+import net.dpml.cli.CommandLine;
+import net.dpml.cli.Option;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @author Rob Oxspring
+ */
+public class DefaultingCommandLineTest extends AbstractCommandLineTestCase
+{
+ private CommandLine first;
+ private CommandLine second;
+ private Option inFirst = new DefaultOptionBuilder( ).withLongName(
+ "infirst" ).create( );
+ private Option inBoth = new DefaultOptionBuilder( ).withLongName(
"inboth" )
+ .create( );
+ private Option inSecond = new DefaultOptionBuilder( ).withLongName(
+ "insecond" ).create( );
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.CommandLineTest#createCommandLine()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected final CommandLine createCommandLine( )
+ {
+ final WriteableCommandLine writeable = new WriteableCommandLineImpl(
m_root,
+ new ArrayList( ) );
+ writeable.addOption( m_present );
+ writeable.addProperty( "present", "present property" );
+ writeable.addSwitch( m_bool, true );
+ writeable.addValue( m_present, "present value" );
+ writeable.addOption( m_multiple );
+ writeable.addValue( m_multiple, "value 1" );
+ writeable.addValue( m_multiple, "value 2" );
+ writeable.addValue( m_multiple, "value 3" );
+
+ final DefaultingCommandLine defaults = new DefaultingCommandLine( );
+ defaults.appendCommandLine( writeable );
+
+ return defaults;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void setUp( ) throws Exception
+ {
+ super.setUp( );
+
+ WriteableCommandLine writeable;
+
+ writeable = new WriteableCommandLineImpl( m_root, new ArrayList( )
);
+ writeable.addOption( inFirst );
+ writeable.addOption( inBoth );
+ writeable.addProperty( "infirst", "infirst first value" );
+ writeable.addProperty( "inboth", "inboth first value" );
+ writeable.addSwitch( inFirst, true );
+ writeable.addSwitch( inBoth, true );
+ writeable.addValue( inFirst, "infirst first value 1" );
+ writeable.addValue( inFirst, "infirst first value 2" );
+ writeable.addValue( inBoth, "inboth first value 1" );
+ writeable.addValue( inBoth, "inboth first value 2" );
+ first = writeable;
+
+ writeable = new WriteableCommandLineImpl( m_root, new ArrayList( )
);
+ writeable.addOption( inSecond );
+ writeable.addOption( inBoth );
+ writeable.addProperty( "insecond", "insecond second value" );
+ writeable.addProperty( "inboth", "inboth second value" );
+ writeable.addSwitch( inSecond, true );
+ writeable.addSwitch( inBoth, true );
+ writeable.addValue( inSecond, "insecond second value 1" );
+ writeable.addValue( inSecond, "insecond second value 2" );
+ writeable.addValue( inBoth, "inboth second value 1" );
+ writeable.addValue( inBoth, "inboth second value 2" );
+ second = writeable;
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testAppendCommandLine( )
+ {
+ final DefaultingCommandLine defaults = new DefaultingCommandLine( );
+ Iterator i;
+
+ i = defaults.commandLines( );
+ assertFalse( i.hasNext( ) );
+
+ defaults.appendCommandLine( first );
+ i = defaults.commandLines( );
+ assertSame( first, i.next( ) );
+ assertFalse( i.hasNext( ) );
+
+ defaults.appendCommandLine( second );
+ i = defaults.commandLines( );
+ assertSame( first, i.next( ) );
+ assertSame( second, i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public final void testInsertCommandLine( )
+ {
+ final DefaultingCommandLine defaults = new DefaultingCommandLine( );
+ Iterator i;
+
+ i = defaults.commandLines( );
+ assertFalse( i.hasNext( ) );
+
+ defaults.insertCommandLine( 0, first );
+ i = defaults.commandLines( );
+ assertSame( first, i.next( ) );
+ assertFalse( i.hasNext( ) );
+
+ defaults.insertCommandLine( 0, second );
+ i = defaults.commandLines( );
+ assertSame( second, i.next( ) );
+ assertSame( first, i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTriggers( )
+ {
+ final DefaultingCommandLine defaults = new DefaultingCommandLine( );
+ defaults.appendCommandLine( first );
+ defaults.appendCommandLine( second );
+
+ Set set = defaults.getOptionTriggers( );
+ Iterator iter = set.iterator( );
+ assertEquals( "wrong # of triggers", 3, set.size( ) );
+ assertTrue( "cannot find trigger", set.contains( "--insecond" ) );
+ assertTrue( "cannot find trigger", set.contains( "--inboth" ) );
+ assertTrue( "cannot find trigger", set.contains( "--infirst" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testDefaults( )
+ {
+ final DefaultingCommandLine defaults = new DefaultingCommandLine( );
+
+ assertEquals( "wrong # of defaults", 0,
+ defaults.getValues( "--insecond" ).size( ) );
+ assertEquals( "wrong Set of defaults", Collections.EMPTY_LIST,
+ defaults.getValues( "--insecond", null ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/commandline/ParserTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/commandline/ParserTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/commandline/ParserTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,10 +1,6 @@
package net.dpml.cli.commandline;

-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
+import junit.framework.TestCase;

import net.dpml.cli.CommandLine;
import net.dpml.cli.Group;
@@ -14,10 +10,20 @@
import net.dpml.cli.option.DefaultOption;
import net.dpml.cli.util.HelpFormatter;

-import junit.framework.TestCase;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;

-public class ParserTest extends TestCase {
-
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class ParserTest extends TestCase
+{
private Parser parser;
private DefaultOption verboseOption;
private DefaultOption helpOption;
@@ -26,102 +32,153 @@
private StringWriter out;
private BufferedReader in;

- public void setUp() {
- parser = new Parser();
-
- final GroupBuilder gBuilder = new GroupBuilder();
- final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
-
- helpOption =
oBuilder.withLongName("help").withShortName("h").create();
- verboseOption =
oBuilder.withLongName("verbose").withShortName("v").create();
- options =
gBuilder.withOption(helpOption).withOption(verboseOption).create();
- parser.setGroup(options);
-
- helpFormatter = new HelpFormatter();
- out = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(out));
- parser.setHelpFormatter(helpFormatter);
+ /**
+ * DOCUMENT ME!
+ */
+ public void setUp( )
+ {
+ parser = new Parser( );
+
+ final GroupBuilder gBuilder = new GroupBuilder( );
+ final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder( );
+
+ helpOption = oBuilder.withLongName( "help" ).withShortName( "h" )
+ .create( );
+ verboseOption = oBuilder.withLongName( "verbose" ).withShortName(
"v" )
+ .create( );
+ options = gBuilder.withOption( helpOption ).withOption(
verboseOption )
+ .create( );
+ parser.setGroup( options );
+
+ helpFormatter = new HelpFormatter( );
+ out = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( out ) );
+ parser.setHelpFormatter( helpFormatter );
}

- public void testParse_Successful() throws OptionException {
- final CommandLine cl = parser.parse(new String[]{"-hv"});
-
- assertTrue(cl.hasOption(helpOption));
- assertTrue(cl.hasOption(verboseOption));
-
- assertEquals("--help --verbose",cl.toString());
-
- final WriteableCommandLineImpl wcli = (WriteableCommandLineImpl)cl;
- assertEquals("[--help, --verbose]",wcli.getNormalised().toString());
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testParse_Successful( ) throws OptionException
+ {
+ final CommandLine cl = parser.parse( new String[]{"-hv"} );
+
+ assertTrue( cl.hasOption( helpOption ) );
+ assertTrue( cl.hasOption( verboseOption ) );
+
+ assertEquals( "--help --verbose", cl.toString( ) );
+
+ final WriteableCommandLineImpl wcli = (WriteableCommandLineImpl) cl;
+ assertEquals( "[--help, --verbose]", wcli.getNormalised(
).toString( ) );
}

- public void testParse_WithUnexpectedOption() {
- try {
- parser.parse(new String[]{"--unexpected"});
- fail("OptionException");
+ /**
+ * DOCUMENT ME!
+ */
+ public void testParse_WithUnexpectedOption( )
+ {
+ try
+ {
+ parser.parse( new String[]{"--unexpected"} );
+ fail( "OptionException" );
}
- catch(OptionException e) {
- assertEquals(options,e.getOption());
+ catch( OptionException e )
+ {
+ assertEquals( options, e.getOption( ) );
//assertEquals("Unexpected --unexpected while processing
--help|--verbose",e.getMessage());
- assertEquals("Unexpected --unexpected while processing --help
--verbose",e.getMessage());
+ assertEquals( "Unexpected --unexpected while processing --help
--verbose",
+ e.getMessage( ) );
}
}

- public void testParseAndHelp_Successful() throws IOException {
- final CommandLine cl = parser.parseAndHelp(new String[]{"-v"});
-
- assertTrue(cl.hasOption(verboseOption));
- assertEquals("",out.getBuffer().toString());
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testParseAndHelp_Successful( ) throws IOException
+ {
+ final CommandLine cl = parser.parseAndHelp( new String[]{"-v"} );
+
+ assertTrue( cl.hasOption( verboseOption ) );
+ assertEquals( "", out.getBuffer( ).toString( ) );
}

- public void testParseAndHelp_ByHelpOption() throws IOException {
- parser.setHelpOption(helpOption);
-
- assertNull(parser.parseAndHelp(new String[]{"-hv"}));
-
- inReader();
- assertInReaderUsage();
- assertInReaderEOF();
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testParseAndHelp_ByHelpOption( ) throws IOException
+ {
+ parser.setHelpOption( helpOption );
+
+ assertNull( parser.parseAndHelp( new String[]{"-hv"} ) );
+
+ inReader( );
+ assertInReaderUsage( );
+ assertInReaderEOF( );
}

- public void testParseAndHelp_ByHelpTrigger() throws IOException {
- parser.setHelpTrigger("--help");
-
- assertNull(parser.parseAndHelp(new String[]{"-hv"}));
-
- inReader();
- assertInReaderUsage();
- assertInReaderEOF();
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testParseAndHelp_ByHelpTrigger( ) throws IOException
+ {
+ parser.setHelpTrigger( "--help" );
+
+ assertNull( parser.parseAndHelp( new String[]{"-hv"} ) );
+
+ inReader( );
+ assertInReaderUsage( );
+ assertInReaderEOF( );
}

- public void testParseAndHelp_WithUnexpectedOption() throws IOException {
- assertNull(parser.parseAndHelp(new String[]{"--unexpected"}));
-
- inReader();
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testParseAndHelp_WithUnexpectedOption( )
+ throws IOException
+ {
+ assertNull( parser.parseAndHelp( new String[]{"--unexpected"} ) );
+
+ inReader( );
//assertInReaderLine("Unexpected --unexpected while processing
--help|--verbose");
- assertInReaderLine("Unexpected --unexpected while processing --help
--verbose");
- assertInReaderUsage();
- assertInReaderEOF();
+ assertInReaderLine(
+ "Unexpected --unexpected while processing --help --verbose" );
+ assertInReaderUsage( );
+ assertInReaderEOF( );
}

- private void assertInReaderUsage() throws IOException {
- assertInReaderLine("Usage:");
- assertInReaderLine("[--help --verbose]");
+ private void assertInReaderUsage( ) throws IOException
+ {
+ assertInReaderLine( "Usage:" );
+ assertInReaderLine( "[--help --verbose]" );
//assertInReaderLine("--help|--verbose");
- assertInReaderLine("--help --verbose");
- assertInReaderLine("--help (-h)");
- assertInReaderLine("--verbose (-v)");
+ assertInReaderLine( "--help --verbose" );
+ assertInReaderLine( "--help (-h)" );
+ assertInReaderLine( "--verbose (-v)" );
}

- private void assertInReaderLine(final String string) throws IOException {
- assertEquals(string,in.readLine().trim());
+ private void assertInReaderLine( final String string )
+ throws IOException
+ {
+ assertEquals( string, in.readLine( ).trim( ) );
}

- private void assertInReaderEOF() throws IOException {
- assertNull(in.readLine());
+ private void assertInReaderEOF( ) throws IOException
+ {
+ assertNull( in.readLine( ) );
}

- private void inReader() {
- in = new BufferedReader(new
StringReader(out.getBuffer().toString()));
+ private void inReader( )
+ {
+ in = new BufferedReader( new StringReader( out.getBuffer(
).toString( ) ) );
}
}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/commandline/PreferencesCommandLineTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/commandline/PreferencesCommandLineTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/commandline/PreferencesCommandLineTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,105 +1,148 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.commandline;
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.prefs.Preferences;
-
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.AbstractCommandLineTestCase;
-
-/**
- * @author Rob Oxspring
- */
-public class PreferencesCommandLineTest extends AbstractCommandLineTestCase {
-
- /* (non-Javadoc)
- * @see net.dpml.cli.CommandLineTest#createCommandLine()
- */
- protected CommandLine createCommandLine() {
- // TODO Auto-generated method stub
- final Preferences props =
Preferences.userNodeForPackage(PreferencesCommandLineTest.class);
- props.put("--present","present value");
- props.put("--alsopresent","");
- props.put("--multiple","value 1|value 2|value 3");
- props.put("--bool","true");
-
- props.put("present","present property");
-
- return new PreferencesCommandLine(root,props,'|');
- }
-
- protected CommandLine createCommandLineNoSep() {
- // TODO Auto-generated method stub
- final Preferences props =
Preferences.userNodeForPackage(PreferencesCommandLineTest.class);
- props.put("--present","present value");
- props.put("--alsopresent","");
- props.put("--multiple","value 1|value 2|value 3");
- props.put("--bool","false");
-
- props.put("present","present property");
-
- return new PreferencesCommandLine(root,props);
- }
-
- public void testPropertyValues() {
- // nothing to test
- CommandLine cmdline = createCommandLine();
-
- assertEquals("wrong value", "present value",
cmdline.getValue("--present"));
- assertEquals("wrong value", "present value",
cmdline.getValue("--alsopresent"));
- assertEquals("wrong # of values", 3,
cmdline.getValues("--multiple").size());
- assertEquals("wrong value 1", "value 1",
cmdline.getValues("--multiple").get(0));
- assertEquals("wrong value 2", "value 2",
cmdline.getValues("--multiple").get(1));
- assertEquals("wrong value 3", "value 3",
cmdline.getValues("--multiple").get(2));
- }
-
- public void testNoSeparator() {
- // nothing to test
- CommandLine cmdline = createCommandLineNoSep();
-
- assertEquals("wrong value", "present value",
cmdline.getValue("--present"));
- assertEquals("wrong value", "present value",
cmdline.getValue("--alsopresent"));
- assertEquals("wrong # of values", 1,
cmdline.getValues("--multiple").size());
- assertEquals("wrong value", "value 1|value 2|value 3",
cmdline.getValue("--multiple"));
- assertFalse("expected a false",
cmdline.getSwitch("--bool").booleanValue());
- }
-
- public void testNullOption() {
- // nothing to test
- CommandLine cmdline = createCommandLine();
-
- assertFalse("should not find null option", cmdline.hasOption((String)
null));
- assertTrue("expected a true",
cmdline.getSwitch("--bool").booleanValue());
- }
-
- public void testPreferenceTriggers() {
- // nothing to test
- CommandLine cmdline = createCommandLine();
-
- Set triggers = cmdline.getOptionTriggers();
- Iterator iter = triggers.iterator();
- assertEquals("wrong # of triggers", 4, triggers.size());
- assertTrue("cannot find trigger", triggers.contains("--bool"));
- assertTrue("cannot find trigger", triggers.contains("--present"));
- assertTrue("cannot find trigger", triggers.contains("--multiple"));
- assertTrue("cannot find trigger",
triggers.contains("--alsopresent"));
-
- assertFalse("should not find null option", cmdline.hasOption((String)
null));
- assertTrue("expected a true",
cmdline.getSwitch("--bool").booleanValue());
- }
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.commandline;
+
+import net.dpml.cli.AbstractCommandLineTestCase;
+import net.dpml.cli.CommandLine;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.prefs.Preferences;
+
+/**
+ * @author Rob Oxspring
+ */
+public class PreferencesCommandLineTest extends AbstractCommandLineTestCase
+{
+ /* (non-Javadoc)
+ * @see net.dpml.cli.CommandLineTest#createCommandLine()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected CommandLine createCommandLine( )
+ {
+ // TODO Auto-generated method stub
+ final Preferences props = Preferences.userNodeForPackage(
PreferencesCommandLineTest.class );
+ props.put( "--present", "present value" );
+ props.put( "--alsopresent", "" );
+ props.put( "--multiple", "value 1|value 2|value 3" );
+ props.put( "--bool", "true" );
+
+ props.put( "present", "present property" );
+
+ return new PreferencesCommandLine( m_root, props, '|' );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected CommandLine createCommandLineNoSep( )
+ {
+ // TODO Auto-generated method stub
+ final Preferences props = Preferences.userNodeForPackage(
PreferencesCommandLineTest.class );
+ props.put( "--present", "present value" );
+ props.put( "--alsopresent", "" );
+ props.put( "--multiple", "value 1|value 2|value 3" );
+ props.put( "--bool", "false" );
+
+ props.put( "present", "present property" );
+
+ return new PreferencesCommandLine( m_root, props );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPropertyValues( )
+ {
+ // nothing to test
+ CommandLine cmdline = createCommandLine( );
+
+ assertEquals( "wrong value", "present value",
+ cmdline.getValue( "--present" ) );
+ assertEquals( "wrong value", "present value",
+ cmdline.getValue( "--alsopresent" ) );
+ assertEquals( "wrong # of values", 3,
+ cmdline.getValues( "--multiple" ).size( ) );
+ assertEquals( "wrong value 1", "value 1",
+ cmdline.getValues( "--multiple" ).get( 0 ) );
+ assertEquals( "wrong value 2", "value 2",
+ cmdline.getValues( "--multiple" ).get( 1 ) );
+ assertEquals( "wrong value 3", "value 3",
+ cmdline.getValues( "--multiple" ).get( 2 ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNoSeparator( )
+ {
+ // nothing to test
+ CommandLine cmdline = createCommandLineNoSep( );
+
+ assertEquals( "wrong value", "present value",
+ cmdline.getValue( "--present" ) );
+ assertEquals( "wrong value", "present value",
+ cmdline.getValue( "--alsopresent" ) );
+ assertEquals( "wrong # of values", 1,
+ cmdline.getValues( "--multiple" ).size( ) );
+ assertEquals( "wrong value", "value 1|value 2|value 3",
+ cmdline.getValue( "--multiple" ) );
+ assertFalse( "expected a false",
+ cmdline.getSwitch( "--bool" ).booleanValue( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullOption( )
+ {
+ // nothing to test
+ CommandLine cmdline = createCommandLine( );
+
+ assertFalse( "should not find null option",
+ cmdline.hasOption( (String) null ) );
+ assertTrue( "expected a true",
+ cmdline.getSwitch( "--bool" ).booleanValue( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPreferenceTriggers( )
+ {
+ // nothing to test
+ CommandLine cmdline = createCommandLine( );
+
+ Set triggers = cmdline.getOptionTriggers( );
+ Iterator iter = triggers.iterator( );
+ assertEquals( "wrong # of triggers", 4, triggers.size( ) );
+ assertTrue( "cannot find trigger", triggers.contains( "--bool" ) );
+ assertTrue( "cannot find trigger", triggers.contains( "--present" )
);
+ assertTrue( "cannot find trigger", triggers.contains( "--multiple" )
);
+ assertTrue( "cannot find trigger", triggers.contains(
"--alsopresent" ) );
+
+ assertFalse( "should not find null option",
+ cmdline.hasOption( (String) null ) );
+ assertTrue( "expected a true",
+ cmdline.getSwitch( "--bool" ).booleanValue( ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/commandline/PropertiesCommandLineTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/commandline/PropertiesCommandLineTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/commandline/PropertiesCommandLineTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,100 +1,144 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.commandline;
-
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.AbstractCommandLineTestCase;
-
-/**
- * @author Rob Oxspring
- */
-public class PropertiesCommandLineTest
- extends AbstractCommandLineTestCase {
- private Properties props = null;
-
- protected CommandLine createCommandLine() {
- props = new Properties();
- props.setProperty("--present", "present value");
- props.setProperty("--alsopresent", "");
- props.setProperty("--multiple", "value 1|value 2|value 3");
- props.setProperty("--bool", "true");
-
- props.setProperty("present", "present property");
- return new PropertiesCommandLine(root, props, '|');
- }
-
- protected CommandLine createCommandLineNoSep() {
- props = new Properties();
- props.setProperty("--present", "present value");
- props.setProperty("--alsopresent", "");
- props.setProperty("--multiple", "value 1|value 2|value 3");
- props.setProperty("--bool", "false");
-
- props.setProperty("present", "present property");
- return new PropertiesCommandLine(root, props);
- }
-
- public void testPropertyValues() {
- // nothing to test
- CommandLine cmdline = createCommandLine();
-
- assertEquals("wrong value", "present value",
cmdline.getValue("--present"));
- assertEquals("wrong value", "present value",
cmdline.getValue("--alsopresent"));
- assertEquals("wrong # of values", 3,
cmdline.getValues("--multiple").size());
- assertEquals("wrong value 1", "value 1",
cmdline.getValues("--multiple").get(0));
- assertEquals("wrong value 2", "value 2",
cmdline.getValues("--multiple").get(1));
- assertEquals("wrong value 3", "value 3",
cmdline.getValues("--multiple").get(2));
- }
-
- public void testNoSeparator() {
- // nothing to test
- CommandLine cmdline = createCommandLineNoSep();
-
- assertEquals("wrong value", "present value",
cmdline.getValue("--present"));
- assertEquals("wrong value", "present value",
cmdline.getValue("--alsopresent"));
- assertEquals("wrong # of values", 1,
cmdline.getValues("--multiple").size());
- assertEquals("wrong value", "value 1|value 2|value 3",
cmdline.getValue("--multiple"));
- assertFalse("expected a false",
cmdline.getSwitch("--bool").booleanValue());
- }
-
- public void testNullOption() {
- // nothing to test
- CommandLine cmdline = createCommandLine();
-
- assertFalse("should not find null option", cmdline.hasOption((String)
null));
- assertTrue("expected a true",
cmdline.getSwitch("--bool").booleanValue());
- }
-
- public void testPropertyTriggers() {
- // nothing to test
- CommandLine cmdline = createCommandLine();
-
- Set triggers = cmdline.getOptionTriggers();
- Iterator iter = triggers.iterator();
- assertEquals("wrong # of triggers", 4, triggers.size());
- assertTrue("cannot find trigger", triggers.contains("--bool"));
- assertTrue("cannot find trigger", triggers.contains("--present"));
- assertTrue("cannot find trigger", triggers.contains("--multiple"));
- assertTrue("cannot find trigger",
triggers.contains("--alsopresent"));
-
- assertFalse("should not find null option", cmdline.hasOption((String)
null));
- assertTrue("expected a true",
cmdline.getSwitch("--bool").booleanValue());
- }
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.commandline;
+
+import net.dpml.cli.AbstractCommandLineTestCase;
+import net.dpml.cli.CommandLine;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * @author Rob Oxspring
+ */
+public class PropertiesCommandLineTest extends AbstractCommandLineTestCase
+{
+ private Properties props = null;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected CommandLine createCommandLine( )
+ {
+ props = new Properties( );
+ props.setProperty( "--present", "present value" );
+ props.setProperty( "--alsopresent", "" );
+ props.setProperty( "--multiple", "value 1|value 2|value 3" );
+ props.setProperty( "--bool", "true" );
+
+ props.setProperty( "present", "present property" );
+
+ return new PropertiesCommandLine( m_root, props, '|' );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected CommandLine createCommandLineNoSep( )
+ {
+ props = new Properties( );
+ props.setProperty( "--present", "present value" );
+ props.setProperty( "--alsopresent", "" );
+ props.setProperty( "--multiple", "value 1|value 2|value 3" );
+ props.setProperty( "--bool", "false" );
+
+ props.setProperty( "present", "present property" );
+
+ return new PropertiesCommandLine( m_root, props );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPropertyValues( )
+ {
+ // nothing to test
+ CommandLine cmdline = createCommandLine( );
+
+ assertEquals( "wrong value", "present value",
+ cmdline.getValue( "--present" ) );
+ assertEquals( "wrong value", "present value",
+ cmdline.getValue( "--alsopresent" ) );
+ assertEquals( "wrong # of values", 3,
+ cmdline.getValues( "--multiple" ).size( ) );
+ assertEquals( "wrong value 1", "value 1",
+ cmdline.getValues( "--multiple" ).get( 0 ) );
+ assertEquals( "wrong value 2", "value 2",
+ cmdline.getValues( "--multiple" ).get( 1 ) );
+ assertEquals( "wrong value 3", "value 3",
+ cmdline.getValues( "--multiple" ).get( 2 ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNoSeparator( )
+ {
+ // nothing to test
+ CommandLine cmdline = createCommandLineNoSep( );
+
+ assertEquals( "wrong value", "present value",
+ cmdline.getValue( "--present" ) );
+ assertEquals( "wrong value", "present value",
+ cmdline.getValue( "--alsopresent" ) );
+ assertEquals( "wrong # of values", 1,
+ cmdline.getValues( "--multiple" ).size( ) );
+ assertEquals( "wrong value", "value 1|value 2|value 3",
+ cmdline.getValue( "--multiple" ) );
+ assertFalse( "expected a false",
+ cmdline.getSwitch( "--bool" ).booleanValue( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullOption( )
+ {
+ // nothing to test
+ CommandLine cmdline = createCommandLine( );
+ assertFalse( "should not find null option",
+ cmdline.hasOption( (String) null ) );
+ assertTrue( "expected a true",
+ cmdline.getSwitch( "--bool" ).booleanValue( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPropertyTriggers( )
+ {
+ // nothing to test
+ CommandLine cmdline = createCommandLine( );
+
+ Set triggers = cmdline.getOptionTriggers( );
+ Iterator iter = triggers.iterator( );
+ assertEquals( "wrong # of triggers", 4, triggers.size( ) );
+ assertTrue( "cannot find trigger", triggers.contains( "--bool" ) );
+ assertTrue( "cannot find trigger", triggers.contains( "--present" )
);
+ assertTrue( "cannot find trigger", triggers.contains( "--multiple" )
);
+ assertTrue( "cannot find trigger", triggers.contains(
"--alsopresent" ) );
+
+ assertFalse( "should not find null option",
+ cmdline.hasOption( (String) null ) );
+ assertTrue( "expected a true",
+ cmdline.getSwitch( "--bool" ).booleanValue( ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/commandline/WriteableCommandLineImplTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/commandline/WriteableCommandLineImplTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/commandline/WriteableCommandLineImplTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,35 +1,52 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.commandline;
-
-import java.util.ArrayList;
-
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.AbstractWriteableCommandLineTestCase;
-
-public class WriteableCommandLineImplTest
- extends AbstractWriteableCommandLineTestCase {
- /* (non-Javadoc)
- * @see
net.dpml.cli.WriteableCommandLineTest#createWriteableCommandLine()
- */
- protected WriteableCommandLine createWriteableCommandLine() {
- return new WriteableCommandLineImpl(root, new ArrayList());
- }
-
- public void testToMakeEclipseSpotTheTestCase() {
- // nothing to test
- }
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.commandline;
+
+import net.dpml.cli.AbstractWriteableCommandLineTestCase;
+import net.dpml.cli.WriteableCommandLine;
+
+import java.util.ArrayList;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class WriteableCommandLineImplTest
+ extends AbstractWriteableCommandLineTestCase
+{
+ /* (non-Javadoc)
+ * @see
net.dpml.cli.WriteableCommandLineTest#createWriteableCommandLine()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ protected WriteableCommandLine createWriteableCommandLine( )
+ {
+ return new WriteableCommandLineImpl( m_root, new ArrayList( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testToMakeEclipseSpotTheTestCase( )
+ {
+ // nothing to test
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractArgumentTestCase.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractArgumentTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractArgumentTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,27 +1,31 @@
-/**
- * Copyright 2003-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 net.dpml.cli.option;
-
-import net.dpml.cli.OptionException;
-
-/**
- * @author Rob Oxspring
- */
-public abstract class AbstractArgumentTestCase extends
AbstractOptionTestCase {
-
- public abstract void testProcessValues() throws OptionException;
-
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.option;
+
+import net.dpml.cli.OptionException;
+
+/**
+ * @author Rob Oxspring
+ */
+public abstract class AbstractArgumentTestCase extends AbstractOptionTestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public abstract void testProcessValues( ) throws OptionException;
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractGroupTestCase.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractGroupTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractGroupTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,30 +1,39 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.option;
-
-import net.dpml.cli.OptionException;
-
-/**
- * @author Rob Oxspring
- */
-public abstract class AbstractGroupTestCase
- extends AbstractOptionTestCase {
- public abstract void testProcessOptions()
- throws OptionException;
-
- public abstract void testProcessAnonymousArguments()
- throws OptionException;
-}
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.option;
+
+import net.dpml.cli.OptionException;
+
+/**
+ * @author Rob Oxspring
+ */
+public abstract class AbstractGroupTestCase extends AbstractOptionTestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public abstract void testProcessOptions( ) throws OptionException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public abstract void testProcessAnonymousArguments( )
+ throws OptionException;
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractOptionTestCase.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractOptionTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractOptionTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,54 +1,95 @@
-/**
- * Copyright 2003-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 net.dpml.cli.option;
-
-import java.util.List;
-
-import net.dpml.cli.AbstractCLITestCase;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-
-/**
- * @author Rob Oxspring
- */
-public abstract class AbstractOptionTestCase extends AbstractCLITestCase {
-
- public static WriteableCommandLine commandLine(
- final Option option,
- final List args) {
- return new WriteableCommandLineImpl(option, args);
- }
-
- public abstract void testTriggers();
-
- public abstract void testPrefixes();
-
- public abstract void testCanProcess();
-
- public abstract void testProcess() throws OptionException;
-
- public abstract void testValidate() throws OptionException;
-
- public abstract void testAppendUsage() throws OptionException;
-
- public abstract void testGetPreferredName();
-
- public abstract void testGetDescription();
-
- public abstract void testHelpLines();
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.option;
+
+import net.dpml.cli.AbstractCLITestCase;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+
+import java.util.List;
+
+/**
+ * @author Rob Oxspring
+ */
+public abstract class AbstractOptionTestCase extends AbstractCLITestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @param option DOCUMENT ME!
+ * @param args DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static WriteableCommandLine commandLine( final Option option,
+ final List args )
+ {
+ return new WriteableCommandLineImpl( option, args );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public abstract void testTriggers( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public abstract void testPrefixes( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public abstract void testCanProcess( );
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public abstract void testProcess( ) throws OptionException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public abstract void testValidate( ) throws OptionException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public abstract void testAppendUsage( ) throws OptionException;
+
+ /**
+ * DOCUMENT ME!
+ */
+ public abstract void testGetPreferredName( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public abstract void testGetDescription( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public abstract void testHelpLines( );
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractParentTestCase.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractParentTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/option/AbstractParentTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,25 +1,31 @@
-/**
- * Copyright 2003-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 net.dpml.cli.option;
-
-import net.dpml.cli.OptionException;
-
-/**
- * @author Rob Oxspring
- */
-public abstract class AbstractParentTestCase extends AbstractOptionTestCase {
- public abstract void testProcessParent() throws OptionException;
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.option;
+
+import net.dpml.cli.OptionException;
+
+/**
+ * @author Rob Oxspring
+ */
+public abstract class AbstractParentTestCase extends AbstractOptionTestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public abstract void testProcessParent( ) throws OptionException;
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/option/ArgumentTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/option/ArgumentTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/option/ArgumentTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,649 +1,794 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.option;
-
-import java.text.ParseException;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import net.dpml.cli.Argument;
-import net.dpml.cli.DisplaySetting;
-import net.dpml.cli.HelpLine;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-//import net.dpml.cli.validation.DateValidator;
-//import net.dpml.cli.validation.DateValidatorTest;
-
-/**
- * @author Rob Oxspring
- */
-public class ArgumentTest
- extends AbstractArgumentTestCase {
- private ResourceHelper resources = ResourceHelper.getResourceHelper();
-
- public static Argument buildUsernameArgument() {
- return new ArgumentImpl("username", "The user to connect as", 1, 1,
'\0', '\0', null,
- ArgumentImpl.DEFAULT_CONSUME_REMAINING,
null, 0);
- }
-
- public static Argument buildHostArgument() {
- return new ArgumentImpl("host", "The host name", 2, 3, '\0', ',',
null, null, null, 0);
- }
-
- public static Argument buildPathArgument() {
- return new ArgumentImpl("path", "The place to look for files", 1,
Integer.MAX_VALUE, '=',
- ';', null,
ArgumentImpl.DEFAULT_CONSUME_REMAINING, null, 0);
- }
-
- //public static Argument buildDateLimitArgument() {
- // return new ArgumentImpl("limit", "the last acceptable date", 0, 1,
'=', '\0',
- // new
DateValidator(DateValidatorTest.YYYY_MM_YY), null, null, 0);
- //}
-
- public static Argument buildTargetsArgument() {
- return new ArgumentImpl("target", "The targets ant should build", 0,
Integer.MAX_VALUE,
- '\0', ',', null, null, null, 0);
- }
-
- public static Argument buildSizeArgument() {
- List defaults = new ArrayList();
- defaults.add("10");
-
- return new ArgumentImpl("size", "The number of units", 1, 1, '\0',
'\0', null,
- ArgumentImpl.DEFAULT_CONSUME_REMAINING,
defaults, 0);
- }
-
- public static Argument buildBoundsArgument() {
- List defaults = new ArrayList();
- defaults.add("5");
- defaults.add("10");
-
- return new ArgumentImpl("size", "The number of units", 2, 2, '\0',
'\0', null,
- ArgumentImpl.DEFAULT_CONSUME_REMAINING,
defaults, 0);
- }
-
- public void testNew() {
- //try {
- // new ArgumentImpl("limit", "the last acceptable date", 10, 5,
'=', '\0',
- // new
DateValidator(DateValidatorTest.YYYY_MM_YY), null, null, 0);
- //} catch (IllegalArgumentException e) {
- //
assertEquals(resources.getMessage("Argument.minimum.exceeds.maximum"),
e.getMessage());
- //}
-
- //{
- // ArgumentImpl arg =
- // new ArgumentImpl(null, "the last acceptable date", 5, 5,
'=', '\0',
- // new
DateValidator(DateValidatorTest.YYYY_MM_YY), null, null, 0);
- // assertEquals("wrong arg name", "arg", arg.getPreferredName());
- //}
-
- //{
- // List defaults = new ArrayList();
- //
- // try {
- // new ArgumentImpl(null, "the last acceptable date", 1, 1,
'=', '\0',
- // new
DateValidator(DateValidatorTest.YYYY_MM_YY), null, defaults, 0);
- // } catch (IllegalArgumentException exp) {
- //
assertEquals(resources.getMessage("Argument.too.few.defaults"),
exp.getMessage());
- // }
- //}
-
- //try {
- // List defaults = new ArrayList();
- // defaults.add("1");
- // defaults.add("2");
- //
- // new ArgumentImpl(null, "the last acceptable date", 1, 1, '=',
'\0',
- // new
DateValidator(DateValidatorTest.YYYY_MM_YY), null, defaults, 0);
- //} catch (IllegalArgumentException exp) {
- //
assertEquals(resources.getMessage("Argument.too.many.defaults"),
exp.getMessage());
- //}
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.ArgumentTestCase#testProcessValues()
- */
- public void testProcessValues()
- throws OptionException {
- final Argument option = buildUsernameArgument();
- final List args = list("rob");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processValues(commandLine, iterator, option);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("username"));
- assertEquals("rob", commandLine.getValue(option));
- }
-
- public void testProcessValues_BoundaryQuotes()
- throws OptionException {
- final Argument option = buildUsernameArgument();
- final List args = list("\"rob\"");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processValues(commandLine, iterator, option);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("username"));
- assertEquals("rob", commandLine.getValue(option));
- }
-
- public void testProcessValues_SpareValues()
- throws OptionException {
- final Argument option = buildUsernameArgument();
- final List args = list("rob", "secret");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processValues(commandLine, iterator, option);
-
- assertTrue(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("username"));
- assertEquals("rob", commandLine.getValue(option));
- }
-
- public void testProcessValues_Optional() {
- final Argument option = buildTargetsArgument();
- final List args = list();
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- try {
- option.processValues(commandLine, iterator, option);
- } catch (final OptionException mve) {
- assertEquals(option, mve.getOption());
- assertEquals("Missing value(s) target [target ...]",
mve.getMessage());
- }
-
- assertFalse(iterator.hasNext());
- assertFalse(commandLine.hasOption(option));
- assertFalse(commandLine.hasOption("username"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- public void testProcessValues_Multiple()
- throws OptionException {
- final Argument option = buildTargetsArgument();
- final List args = list("compile", "test", "docs");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processValues(commandLine, iterator, option);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("target"));
- assertFalse(commandLine.getValues(option).isEmpty());
- assertListContentsEqual(args, commandLine.getValues(option));
- }
-
- public void testProcessValues_Contracted()
- throws OptionException {
- final Argument option = buildTargetsArgument();
- final List args = list("compile,test,javadoc", "checkstyle,jdepend");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processValues(commandLine, iterator, option);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("target"));
- assertListContentsEqual(list("compile", "test", "javadoc",
"checkstyle", "jdepend"),
- commandLine.getValues(option));
- }
-
- public void testProcessValues_ContractedTooFew() {
- final Argument option = buildHostArgument();
- final List args = list("box1");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- try {
- option.processValues(commandLine, iterator, option);
- option.validate(commandLine);
- fail("Expected MissingValueException");
- } catch (OptionException mve) {
- assertSame(option, mve.getOption());
- }
- }
-
- public void testProcessValues_ContractedTooMany() {
- final Argument option = buildHostArgument();
- final List args = list("box1,box2,box3,box4");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- try {
- option.processValues(commandLine, iterator, option);
- option.validate(commandLine);
- fail("Expected MissingValueException");
- } catch (OptionException mve) {
- assertSame(option, mve.getOption());
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testCanProcess()
- */
- public void testCanProcess() {
- final Argument option = buildTargetsArgument();
- assertTrue(option.canProcess(new WriteableCommandLineImpl(option,
null), "any value"));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testPrefixes()
- */
- public void testPrefixes() {
- final Argument option = buildTargetsArgument();
- assertTrue(option.getPrefixes().isEmpty());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testProcess()
- */
- public void testProcess()
- throws OptionException {
- final Argument option = buildPathArgument();
- final List args = list("-path=/lib;/usr/lib;/usr/local/lib");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("path"));
- assertListContentsEqual(list("-path=/lib", "/usr/lib",
"/usr/local/lib"),
- commandLine.getValues(option));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testTriggers()
- */
- public void testTriggers() {
- final Argument option = buildTargetsArgument();
- assertTrue(option.getTriggers().isEmpty());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testValidate()
- */
- public void testValidate()
- throws OptionException {
- final Argument option = buildUsernameArgument();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- commandLine.addValue(option, "rob");
-
- option.validate(commandLine);
- }
-
- public void testValidate_Minimum() {
- final Argument option = buildUsernameArgument();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- try {
- option.validate(commandLine);
- fail("UnexpectedValue");
- } catch (OptionException mve) {
- assertEquals(option, mve.getOption());
- }
- }
-
- public void testRequired() {
- {
- final Argument arg = buildBoundsArgument();
-
- assertTrue("not required", arg.isRequired());
- }
-
- {
- final Argument arg = buildTargetsArgument();
-
- assertFalse("should not be required", arg.isRequired());
- }
- }
-
- public void testValidate_Maximum() {
- final Argument option = buildUsernameArgument();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- commandLine.addValue(option, "rob");
- commandLine.addValue(option, "oxspring");
-
- try {
- option.validate(commandLine);
- fail("UnexpectedValue");
- } catch (OptionException uve) {
- assertEquals(option, uve.getOption());
- }
- }
-
- /*
- public void testValidate_Validator()
- throws OptionException, ParseException {
- final Argument option = buildDateLimitArgument();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- commandLine.addValue(option, "2004-01-01");
-
- option.validate(commandLine, option);
- assertContentsEqual(Arrays.asList(new Object[] {
-
DateValidatorTest.YYYY_MM_YY.parse("2004-01-01")
- }), commandLine.getValues(option));
- }
- */
-
- /*
- public void testValidate_ValidatorInvalidDate()
- throws OptionException, ParseException {
- final Argument option = buildDateLimitArgument();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- commandLine.addValue(option, "12-12-2004");
-
- try {
- option.validate(commandLine, option);
- } catch (OptionException exp) {
- OptionException e =
- new OptionException(option,
ResourceConstants.ARGUMENT_UNEXPECTED_VALUE,
- "12-12-2004");
- assertEquals("wrong exception message", e.getMessage(),
exp.getMessage());
- }
- }
- */
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testAppendUsage()
- */
- public void testAppendUsage() {
- final Option option = buildUsernameArgument();
- final StringBuffer buffer = new StringBuffer();
- option.appendUsage(buffer, DisplaySetting.ALL, null);
-
- assertEquals("<username>", buffer.toString());
- }
-
- public void testAppendUsage_Infinite() {
- final Option option = buildTargetsArgument();
- final StringBuffer buffer = new StringBuffer();
- option.appendUsage(buffer, DisplaySetting.ALL, null);
-
- assertEquals("[<target1> [<target2> ...]]", buffer.toString());
- }
-
- public void testAppendUsage_InfiniteNoOptional() {
- final Option option = buildTargetsArgument();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_OPTIONAL);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("<target1> [<target2> ...]", buffer.toString());
- }
-
- public void testAppendUsage_InfiniteNoNumbering() {
- final Option option = buildTargetsArgument();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_ARGUMENT_NUMBERED);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("[<target> [<target> ...]]", buffer.toString());
- }
-
- public void testAppendUsage_Minimum() {
- final Option option = buildHostArgument();
- final StringBuffer buffer = new StringBuffer();
- option.appendUsage(buffer, DisplaySetting.ALL, null);
-
- assertEquals("<host1> <host2> [<host3>]", buffer.toString());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
- */
- public void testGetPreferredName() {
- final Option option = buildPathArgument();
- assertEquals("path", option.getPreferredName());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetDescription()
- */
- public void testGetDescription() {
- final Option option = buildHostArgument();
- assertEquals("The host name", option.getDescription());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines() {
- final Option option = buildHostArgument();
- final List lines = option.helpLines(0, DisplaySetting.ALL, null);
- final Iterator i = lines.iterator();
-
- final HelpLine line1 = (HelpLine) i.next();
- assertEquals(0, line1.getIndent());
- assertEquals(option, line1.getOption());
-
- assertFalse(i.hasNext());
- }
-
- public void testCanProcess_ConsumeRemaining() {
- final Option option = buildUsernameArgument();
-
- assertTrue(option.canProcess(new WriteableCommandLineImpl(option,
null), "--"));
- }
-
- public void testProcess_ConsumeRemaining()
- throws OptionException {
- final Option option = buildPathArgument();
- final List args = list("options", "--", "--ignored", "-Dprop=val");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- option.process(commandLine, iterator);
-
- final List values = commandLine.getValues(option);
- assertTrue(values.contains("options"));
- assertTrue(values.contains("--ignored"));
- assertTrue(values.contains("-Dprop=val"));
- assertEquals(3, values.size());
- assertFalse(iterator.hasNext());
- }
-
- public void testProcess_ConsumeNothing() {
- final Option option = buildPathArgument();
- final List args = list("--");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- try {
- option.process(commandLine, iterator);
- option.validate(commandLine);
- fail("Missing Value!");
- } catch (OptionException mve) {
- assertEquals(option, mve.getOption());
- assertEquals("Missing value(s) path [path ...]",
mve.getMessage());
- }
-
- assertTrue(commandLine.getValues(option).isEmpty());
- assertFalse(iterator.hasNext());
- }
-
- // public void testProcess_DefinedDefaultValue() throws
OptionException {
- // final Option size = buildSizeArgument();
- // final List args = list();
- // final WriteableCommandLine commandLine = commandLine(size,
args);
- // final ListIterator iterator = args.listIterator();
- //
- // size.process(commandLine, iterator);
- //
- // assertEquals("10", commandLine.getValue(size));
- // }
- //
- // public void testProcess_DefinedDefaultValues() throws
OptionException {
- // final Option bounds = buildBoundsArgument();
- // final List args = list();
- // final WriteableCommandLine commandLine = commandLine(bounds,
args);
- // final ListIterator iterator = args.listIterator();
- //
- // bounds.process(commandLine, iterator);
- //
- // List values = new ArrayList();
- // values.add("5");
- // values.add("10");
- // assertEquals(values, commandLine.getValues(bounds));
- // }
- public void testProcess_InterrogatedDefaultValue()
- throws OptionException {
- final Option size = buildSizeArgument();
- final List args = list();
- final WriteableCommandLine commandLine = commandLine(size, args);
- final ListIterator iterator = args.listIterator();
-
- size.process(commandLine, iterator);
-
- assertEquals(new Integer(20), commandLine.getValue(size, new
Integer(20)));
- }
-
- public void testTooFewDefaults() {
- List defaults = new ArrayList();
- defaults.add("5");
-
- try {
- new ArgumentImpl("size", "The number of units", 2, 2, '\0',
'\0', null,
- ArgumentImpl.DEFAULT_CONSUME_REMAINING,
defaults, 0);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.ARGUMENT_TOO_FEW_DEFAULTS),
- exp.getMessage());
- }
- }
-
- public void testTooManyDefaults() {
- List defaults = new ArrayList();
- defaults.add("5");
- defaults.add("10");
- defaults.add("15");
-
- try {
- new ArgumentImpl("size", "The number of units", 2, 2, '\0',
'\0', null,
- ArgumentImpl.DEFAULT_CONSUME_REMAINING,
defaults, 0);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.ARGUMENT_TOO_MANY_DEFAULTS),
- exp.getMessage());
- }
- }
-
- public void testProcess_InterrogatedDefaultValues()
- throws OptionException {
- final Option bounds = buildBoundsArgument();
- final List args = list();
- final WriteableCommandLine commandLine = commandLine(bounds, args);
- final ListIterator iterator = args.listIterator();
-
- bounds.process(commandLine, iterator);
-
- // test with values
- List values = new ArrayList();
- values.add("50");
- values.add("100");
- assertEquals(values, commandLine.getValues(bounds, values));
-
- // test without values
- assertEquals(Collections.EMPTY_LIST, commandLine.getValues(bounds,
null));
- }
-
- public void testProcess_StripBoundaryQuotes()
- throws OptionException {
- final Option bounds = buildBoundsArgument();
- final List args = list();
- final WriteableCommandLine commandLine = commandLine(bounds, args);
- final ListIterator iterator = args.listIterator();
-
- bounds.process(commandLine, iterator);
-
- List values = new ArrayList();
- values.add("50\"");
- values.add("\"100");
- assertEquals(values, commandLine.getValues(bounds, values));
- }
-
- public void testSourceDestArgument() {
- final ArgumentBuilder abuilder = new ArgumentBuilder();
- final GroupBuilder gbuilder = new GroupBuilder();
- final Argument inputfiles =
-
abuilder.withName("input").withMinimum(0).withMaximum(0).create();
- final Argument bad_outputfile =
-
abuilder.withName("output").withMinimum(1).withMaximum(2).create();
-
- try {
- final Argument targets = new SourceDestArgument(inputfiles,
bad_outputfile);
- } catch (final IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SOURCE_DEST_MUST_ENFORCE_VALUES),
- exp.getMessage());
- }
-
- final Argument outputfile =
-
abuilder.withName("output").withMinimum(1).withMaximum(1).create();
-
- final Argument targets = new SourceDestArgument(inputfiles,
outputfile);
- final StringBuffer buffer = new StringBuffer("test content");
- targets.appendUsage(buffer, Collections.EMPTY_SET, null);
-
- assertTrue("buffer not added", buffer.toString().startsWith("test
content"));
- assertFalse("space added", buffer.charAt(12) == ' ');
- }
-}
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.option;
+
+import net.dpml.cli.Argument;
+import net.dpml.cli.DisplaySetting;
+import net.dpml.cli.HelpLine;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.text.ParseException;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+//import net.dpml.cli.validation.DateValidator;
+//import net.dpml.cli.validation.DateValidatorTest;
+
+/**
+ * @author Rob Oxspring
+ */
+public class ArgumentTest extends AbstractArgumentTestCase
+{
+ private ResourceHelper resources = ResourceHelper.getResourceHelper( );
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Argument buildUsernameArgument( )
+ {
+ return new ArgumentImpl( "username", "The user to connect as", 1, 1,
+ '\0', '\0', null, ArgumentImpl.DEFAULT_CONSUME_REMAINING, null,
0 );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Argument buildHostArgument( )
+ {
+ return new ArgumentImpl( "host", "The host name", 2, 3, '\0', ',',
+ null, null, null, 0 );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Argument buildPathArgument( )
+ {
+ return new ArgumentImpl( "path", "The place to look for files", 1,
+ Integer.MAX_VALUE, '=', ';', null,
+ ArgumentImpl.DEFAULT_CONSUME_REMAINING, null, 0 );
+ }
+
+ //public static Argument buildDateLimitArgument() {
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Argument buildTargetsArgument( )
+ {
+ return new ArgumentImpl( "target", "The targets ant should build", 0,
+ Integer.MAX_VALUE, '\0', ',', null, null, null, 0 );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Argument buildSizeArgument( )
+ {
+ List defaults = new ArrayList( );
+ defaults.add( "10" );
+
+ return new ArgumentImpl( "size", "The number of units", 1, 1, '\0',
+ '\0', null, ArgumentImpl.DEFAULT_CONSUME_REMAINING, defaults, 0
);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Argument buildBoundsArgument( )
+ {
+ List defaults = new ArrayList( );
+ defaults.add( "5" );
+ defaults.add( "10" );
+
+ return new ArgumentImpl( "size", "The number of units", 2, 2, '\0',
+ '\0', null, ArgumentImpl.DEFAULT_CONSUME_REMAINING, defaults, 0
);
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNew( )
+ {
+ //try {
+ // new ArgumentImpl("limit", "the last acceptable date", 10, 5,
'=', '\0',
+ // new
DateValidator(DateValidatorTest.YYYY_MM_YY), null, null, 0);
+ //} catch (IllegalArgumentException e) {
+ //
assertEquals(resources.getMessage("Argument.minimum.exceeds.maximum"),
e.getMessage());
+ //}
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.ArgumentTestCase#testProcessValues()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessValues( ) throws OptionException
+ {
+ final Argument option = buildUsernameArgument( );
+ final List args = list( "rob" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processValues( commandLine, iterator, option );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "username" ) );
+ assertEquals( "rob", commandLine.getValue( option ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessValues_BoundaryQuotes( ) throws OptionException
+ {
+ final Argument option = buildUsernameArgument( );
+ final List args = list( "\"rob\"" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processValues( commandLine, iterator, option );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "username" ) );
+ assertEquals( "rob", commandLine.getValue( option ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessValues_SpareValues( ) throws OptionException
+ {
+ final Argument option = buildUsernameArgument( );
+ final List args = list( "rob", "secret" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processValues( commandLine, iterator, option );
+
+ assertTrue( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "username" ) );
+ assertEquals( "rob", commandLine.getValue( option ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testProcessValues_Optional( )
+ {
+ final Argument option = buildTargetsArgument( );
+ final List args = list( );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ try
+ {
+ option.processValues( commandLine, iterator, option );
+ }
+ catch( final OptionException mve )
+ {
+ assertEquals( option, mve.getOption( ) );
+ assertEquals( "Missing value(s) target [target ...]",
+ mve.getMessage( ) );
+ }
+
+ assertFalse( iterator.hasNext( ) );
+ assertFalse( commandLine.hasOption( option ) );
+ assertFalse( commandLine.hasOption( "username" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessValues_Multiple( ) throws OptionException
+ {
+ final Argument option = buildTargetsArgument( );
+ final List args = list( "compile", "test", "docs" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processValues( commandLine, iterator, option );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "target" ) );
+ assertFalse( commandLine.getValues( option ).isEmpty( ) );
+ assertListContentsEqual( args, commandLine.getValues( option ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessValues_Contracted( ) throws OptionException
+ {
+ final Argument option = buildTargetsArgument( );
+ final List args = list( "compile,test,javadoc", "checkstyle,jdepend"
);
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processValues( commandLine, iterator, option );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "target" ) );
+ assertListContentsEqual( list( "compile", "test", "javadoc",
+ "checkstyle", "jdepend" ), commandLine.getValues( option ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testProcessValues_ContractedTooFew( )
+ {
+ final Argument option = buildHostArgument( );
+ final List args = list( "box1" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ try
+ {
+ option.processValues( commandLine, iterator, option );
+ option.validate( commandLine );
+ fail( "Expected MissingValueException" );
+ }
+ catch( OptionException mve )
+ {
+ assertSame( option, mve.getOption( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testProcessValues_ContractedTooMany( )
+ {
+ final Argument option = buildHostArgument( );
+ final List args = list( "box1,box2,box3,box4" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ try
+ {
+ option.processValues( commandLine, iterator, option );
+ option.validate( commandLine );
+ fail( "Expected MissingValueException" );
+ }
+ catch( OptionException mve )
+ {
+ assertSame( option, mve.getOption( ) );
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testCanProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess( )
+ {
+ final Argument option = buildTargetsArgument( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "any value" )
);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testPrefixes()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPrefixes( )
+ {
+ final Argument option = buildTargetsArgument( );
+ assertTrue( option.getPrefixes( ).isEmpty( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess( ) throws OptionException
+ {
+ final Argument option = buildPathArgument( );
+ final List args = list( "-path=/lib;/usr/lib;/usr/local/lib" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "path" ) );
+ assertListContentsEqual( list( "-path=/lib", "/usr/lib",
+ "/usr/local/lib" ), commandLine.getValues( option ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testTriggers()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTriggers( )
+ {
+ final Argument option = buildTargetsArgument( );
+ assertTrue( option.getTriggers( ).isEmpty( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testValidate()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testValidate( ) throws OptionException
+ {
+ final Argument option = buildUsernameArgument( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ commandLine.addValue( option, "rob" );
+
+ option.validate( commandLine );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_Minimum( )
+ {
+ final Argument option = buildUsernameArgument( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "UnexpectedValue" );
+ }
+ catch( OptionException mve )
+ {
+ assertEquals( option, mve.getOption( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testRequired( )
+ {
+ {
+ final Argument arg = buildBoundsArgument( );
+
+ assertTrue( "not required", arg.isRequired( ) );
+ }
+
+ {
+ final Argument arg = buildTargetsArgument( );
+
+ assertFalse( "should not be required", arg.isRequired( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_Maximum( )
+ {
+ final Argument option = buildUsernameArgument( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ commandLine.addValue( option, "rob" );
+ commandLine.addValue( option, "oxspring" );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "UnexpectedValue" );
+ }
+ catch( OptionException uve )
+ {
+ assertEquals( option, uve.getOption( ) );
+ }
+ }
+
+ /*
+ public void testValidate_Validator()
+ throws OptionException, ParseException {
+ final Argument option = buildDateLimitArgument();
+ final WriteableCommandLine commandLine = commandLine(option,
list());
+
+ commandLine.addValue(option, "2004-01-01");
+
+ option.validate(commandLine, option);
+ assertContentsEqual(Arrays.asList(new Object[] {
+
DateValidatorTest.YYYY_MM_YY.parse("2004-01-01")
+ }),
commandLine.getValues(option));
+ }
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage( )
+ {
+ final Option option = buildUsernameArgument( );
+ final StringBuffer buffer = new StringBuffer( );
+ option.appendUsage( buffer, DisplaySetting.ALL, null );
+
+ assertEquals( "<username>", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_Infinite( )
+ {
+ final Option option = buildTargetsArgument( );
+ final StringBuffer buffer = new StringBuffer( );
+ option.appendUsage( buffer, DisplaySetting.ALL, null );
+
+ assertEquals( "[<target1> [<target2> ...]]", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_InfiniteNoOptional( )
+ {
+ final Option option = buildTargetsArgument( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_OPTIONAL );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "<target1> [<target2> ...]", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_InfiniteNoNumbering( )
+ {
+ final Option option = buildTargetsArgument( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_ARGUMENT_NUMBERED );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "[<target> [<target> ...]]", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_Minimum( )
+ {
+ final Option option = buildHostArgument( );
+ final StringBuffer buffer = new StringBuffer( );
+ option.appendUsage( buffer, DisplaySetting.ALL, null );
+
+ assertEquals( "<host1> <host2> [<host3>]", buffer.toString( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetPreferredName( )
+ {
+ final Option option = buildPathArgument( );
+ assertEquals( "path", option.getPreferredName( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetDescription()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetDescription( )
+ {
+ final Option option = buildHostArgument( );
+ assertEquals( "The host name", option.getDescription( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines( )
+ {
+ final Option option = buildHostArgument( );
+ final List lines = option.helpLines( 0, DisplaySetting.ALL, null );
+ final Iterator i = lines.iterator( );
+
+ final HelpLine line1 = (HelpLine) i.next( );
+ assertEquals( 0, line1.getIndent( ) );
+ assertEquals( option, line1.getOption( ) );
+
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_ConsumeRemaining( )
+ {
+ final Option option = buildUsernameArgument( );
+
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "--" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_ConsumeRemaining( ) throws OptionException
+ {
+ final Option option = buildPathArgument( );
+ final List args = list( "options", "--", "--ignored", "-Dprop=val" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ option.process( commandLine, iterator );
+
+ final List values = commandLine.getValues( option );
+ assertTrue( values.contains( "options" ) );
+ assertTrue( values.contains( "--ignored" ) );
+ assertTrue( values.contains( "-Dprop=val" ) );
+ assertEquals( 3, values.size( ) );
+ assertFalse( iterator.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testProcess_ConsumeNothing( )
+ {
+ final Option option = buildPathArgument( );
+ final List args = list( "--" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ try
+ {
+ option.process( commandLine, iterator );
+ option.validate( commandLine );
+ fail( "Missing Value!" );
+ }
+ catch( OptionException mve )
+ {
+ assertEquals( option, mve.getOption( ) );
+ assertEquals( "Missing value(s) path [path ...]",
mve.getMessage( ) );
+ }
+
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ assertFalse( iterator.hasNext( ) );
+ }
+
+ // public void testProcess_DefinedDefaultValue() throws
OptionException {
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_InterrogatedDefaultValue( )
+ throws OptionException
+ {
+ final Option size = buildSizeArgument( );
+ final List args = list( );
+ final WriteableCommandLine commandLine = commandLine( size, args );
+ final ListIterator iterator = args.listIterator( );
+
+ size.process( commandLine, iterator );
+
+ assertEquals( new Integer( 20 ),
+ commandLine.getValue( size, new Integer( 20 ) ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTooFewDefaults( )
+ {
+ List defaults = new ArrayList( );
+ defaults.add( "5" );
+
+ try
+ {
+ new ArgumentImpl( "size", "The number of units", 2, 2, '\0',
'\0',
+ null, ArgumentImpl.DEFAULT_CONSUME_REMAINING, defaults, 0 );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.ARGUMENT_TOO_FEW_DEFAULTS ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTooManyDefaults( )
+ {
+ List defaults = new ArrayList( );
+ defaults.add( "5" );
+ defaults.add( "10" );
+ defaults.add( "15" );
+
+ try
+ {
+ new ArgumentImpl( "size", "The number of units", 2, 2, '\0',
'\0',
+ null, ArgumentImpl.DEFAULT_CONSUME_REMAINING, defaults, 0 );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.ARGUMENT_TOO_MANY_DEFAULTS ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_InterrogatedDefaultValues( )
+ throws OptionException
+ {
+ final Option bounds = buildBoundsArgument( );
+ final List args = list( );
+ final WriteableCommandLine commandLine = commandLine( bounds, args );
+ final ListIterator iterator = args.listIterator( );
+
+ bounds.process( commandLine, iterator );
+
+ // test with values
+ List values = new ArrayList( );
+ values.add( "50" );
+ values.add( "100" );
+ assertEquals( values, commandLine.getValues( bounds, values ) );
+
+ // test without values
+ assertEquals( Collections.EMPTY_LIST,
+ commandLine.getValues( bounds, null ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_StripBoundaryQuotes( ) throws OptionException
+ {
+ final Option bounds = buildBoundsArgument( );
+ final List args = list( );
+ final WriteableCommandLine commandLine = commandLine( bounds, args );
+ final ListIterator iterator = args.listIterator( );
+
+ bounds.process( commandLine, iterator );
+
+ List values = new ArrayList( );
+ values.add( "50\"" );
+ values.add( "\"100" );
+ assertEquals( values, commandLine.getValues( bounds, values ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSourceDestArgument( )
+ {
+ final ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final GroupBuilder gbuilder = new GroupBuilder( );
+ final Argument inputfiles = abuilder.withName( "input"
).withMinimum( 0 )
+ .withMaximum( 0 ).create( );
+ final Argument bad_outputfile = abuilder.withName( "output" )
+ .withMinimum( 1
).withMaximum( 2 )
+ .create( );
+
+ try
+ {
+ final Argument targets = new SourceDestArgument( inputfiles,
+ bad_outputfile );
+ }
+ catch( final IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.SOURCE_DEST_MUST_ENFORCE_VALUES ),
+ exp.getMessage( ) );
+ }
+
+ final Argument outputfile = abuilder.withName( "output"
).withMinimum( 1 )
+ .withMaximum( 1 ).create( );
+
+ final Argument targets = new SourceDestArgument( inputfiles,
outputfile );
+ final StringBuffer buffer = new StringBuffer( "test content" );
+ targets.appendUsage( buffer, Collections.EMPTY_SET, null );
+
+ assertTrue( "buffer not added",
+ buffer.toString( ).startsWith( "test content" ) );
+ assertFalse( "space added", buffer.charAt( 12 ) == ' ' );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/option/CommandTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/option/CommandTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/option/CommandTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,248 +1,355 @@
-/**
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.option;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import net.dpml.cli.DisplaySetting;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.Parent;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-/**
- * @author Rob Oxspring
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class CommandTest
- extends AbstractParentTestCase {
- public static Command buildStartCommand() {
- return new Command("start", "Begins the process",
Collections.singleton("go"), false, null,
- null, 0);
- }
-
- public static Command buildCommitCommand() {
- return new Command("commit", "Commit the changes to the database",
null, true, null, null, 0);
- }
-
- public static Command buildLoginCommand() {
- return new Command("login", "Initiates a session for the user",
null, false,
- ArgumentTest.buildUsernameArgument(), null, 0);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.ParentTestCase#testProcessParent()
- */
- public void testProcessParent()
- throws OptionException {
- final Command option = buildStartCommand();
- final List args = list("go");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processParent(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("start"));
- assertTrue(commandLine.hasOption("go"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- public void testProcessParent_Spare()
- throws OptionException {
- final Command option = buildLoginCommand();
- final List args = list("login", "rob");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processParent(commandLine, iterator);
-
- assertEquals("rob", iterator.next());
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("login"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testCanProcess()
- */
- public void testCanProcess() {
- final Command option = buildStartCommand();
- assertTrue(option.canProcess(new WriteableCommandLineImpl(option,
null), "start"));
- }
-
- public void testCanProcess_BadMatch() {
- final Command option = buildStartCommand();
- assertFalse(option.canProcess(new WriteableCommandLineImpl(option,
null), "stop"));
- }
-
- public void testCanProcess_Alias() {
- final Command option = buildStartCommand();
- assertTrue(option.canProcess(new WriteableCommandLineImpl(option,
null), "go"));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testPrefixes()
- */
- public void testPrefixes() {
- final Command option = buildStartCommand();
- assertTrue(option.getPrefixes().isEmpty());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testProcess()
- */
- public void testProcess()
- throws OptionException {
- final Command option = buildLoginCommand();
- final List args = list("login", "rob");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("login"));
- assertEquals("rob", commandLine.getValue(option));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testTriggers()
- */
- public void testTriggers() {
- final Command option = buildStartCommand();
- final Set triggers = option.getTriggers();
- assertContentsEqual(list("start", "go"), triggers);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testValidate()
- */
- public void testValidate() {
- final Parent option = buildCommitCommand();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- try {
- option.validate(commandLine);
- fail("Missing an option");
- } catch (OptionException moe) {
- assertSame(option, moe.getOption());
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testAppendUsage()
- */
- public void testAppendUsage() {
- final Option option = buildStartCommand();
- final StringBuffer buffer = new StringBuffer();
- option.appendUsage(buffer, DisplaySetting.ALL, null);
-
- assertEquals("[start (go)]", buffer.toString());
- }
-
- public void testNullPreferredName() {
- try {
- new Command(null, "", Collections.singleton("go"), false, null,
null, 0);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception name",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.COMMAND_PREFERRED_NAME_TOO_SHORT),
- exp.getMessage());
- }
- }
-
- public void testEmotyPreferredName() {
- try {
- new Command("", "", Collections.singleton("go"), false, null,
null, 0);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception name",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.COMMAND_PREFERRED_NAME_TOO_SHORT),
- exp.getMessage());
- }
- }
-
- public void testAppendUsage_NoOptional() {
- final Option option = buildStartCommand();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_OPTIONAL);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("start (go)", buffer.toString());
- }
-
- public void testAppendUsage_NoAlias() {
- final Option option = buildStartCommand();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_ALIASES);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("[start]", buffer.toString());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
- */
- public void testGetPreferredName() {
- final Option option = buildStartCommand();
- assertEquals("start", option.getPreferredName());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetDescription()
- */
- public void testGetDescription() {
- final Option option = buildLoginCommand();
- assertEquals("Initiates a session for the user",
option.getDescription());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines() {
- // TODO Auto-generated method stub
- }
-}
+/**
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.option;
+
+import net.dpml.cli.DisplaySetting;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.Parent;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * @author Rob Oxspring
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class CommandTest extends AbstractParentTestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Command buildStartCommand( )
+ {
+ return new Command( "start", "Begins the process",
+ Collections.singleton( "go" ), false, null, null, 0 );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Command buildCommitCommand( )
+ {
+ return new Command( "commit", "Commit the changes to the database",
+ null, true, null, null, 0 );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Command buildLoginCommand( )
+ {
+ return new Command( "login", "Initiates a session for the user",
null,
+ false, ArgumentTest.buildUsernameArgument( ), null, 0 );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.ParentTestCase#testProcessParent()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessParent( ) throws OptionException
+ {
+ final Command option = buildStartCommand( );
+ final List args = list( "go" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processParent( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "start" ) );
+ assertTrue( commandLine.hasOption( "go" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessParent_Spare( ) throws OptionException
+ {
+ final Command option = buildLoginCommand( );
+ final List args = list( "login", "rob" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processParent( commandLine, iterator );
+
+ assertEquals( "rob", iterator.next( ) );
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "login" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testCanProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess( )
+ {
+ final Command option = buildStartCommand( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "start" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_BadMatch( )
+ {
+ final Command option = buildStartCommand( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "stop" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_Alias( )
+ {
+ final Command option = buildStartCommand( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "go" ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testPrefixes()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPrefixes( )
+ {
+ final Command option = buildStartCommand( );
+ assertTrue( option.getPrefixes( ).isEmpty( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess( ) throws OptionException
+ {
+ final Command option = buildLoginCommand( );
+ final List args = list( "login", "rob" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "login" ) );
+ assertEquals( "rob", commandLine.getValue( option ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testTriggers()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTriggers( )
+ {
+ final Command option = buildStartCommand( );
+ final Set triggers = option.getTriggers( );
+ assertContentsEqual( list( "start", "go" ), triggers );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testValidate()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate( )
+ {
+ final Parent option = buildCommitCommand( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "Missing an option" );
+ }
+ catch( OptionException moe )
+ {
+ assertSame( option, moe.getOption( ) );
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testAppendUsage()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage( )
+ {
+ final Option option = buildStartCommand( );
+ final StringBuffer buffer = new StringBuffer( );
+ option.appendUsage( buffer, DisplaySetting.ALL, null );
+
+ assertEquals( "[start (go)]", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullPreferredName( )
+ {
+ try
+ {
+ new Command( null, "", Collections.singleton( "go" ), false,
null,
+ null, 0 );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception name",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.COMMAND_PREFERRED_NAME_TOO_SHORT ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testEmotyPreferredName( )
+ {
+ try
+ {
+ new Command( "", "", Collections.singleton( "go" ), false, null,
+ null, 0 );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception name",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.COMMAND_PREFERRED_NAME_TOO_SHORT ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoOptional( )
+ {
+ final Option option = buildStartCommand( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_OPTIONAL );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "start (go)", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoAlias( )
+ {
+ final Option option = buildStartCommand( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_ALIASES );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "[start]", buffer.toString( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetPreferredName( )
+ {
+ final Option option = buildStartCommand( );
+ assertEquals( "start", option.getPreferredName( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetDescription()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetDescription( )
+ {
+ final Option option = buildLoginCommand( );
+ assertEquals( "Initiates a session for the user",
+ option.getDescription( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines( )
+ {
+ // TODO Auto-generated method stub
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/option/DefaultOptionTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/option/DefaultOptionTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/option/DefaultOptionTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,226 +1,284 @@
-/**
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.option;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import net.dpml.cli.DisplaySetting;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.Parent;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-
-/**
- * @author roberto
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class DefaultOptionTest extends AbstractParentTestCase {
-
- public static DefaultOption buildHelpOption() {
- final Set aliases = new HashSet(list("-h", "-?"));
- return new DefaultOption(
- "-",
- "--",
- true,
- "--help",
- "Displays the help",
- aliases,
- aliases,
- false,
- null,
- null,
- 'h');
- }
-
- public static DefaultOption buildXOption() {
- return new DefaultOption(
- "-",
- "--",
- true,
- "-X",
- "This is needed",
- null,
- null,
- true,
- null,
- null,
- 'X');
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.ParentTestCase#testProcessParent()
- */
- public void testProcessParent() throws OptionException {
- final DefaultOption option = buildHelpOption();
- final List args = list("--help");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processParent(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("--help"));
- assertTrue(commandLine.hasOption("-?"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- public void testProcessParent_Burst() throws OptionException {
- final DefaultOption option = buildHelpOption();
- final List args = list("-help");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processParent(commandLine, iterator);
-
- assertEquals("-elp", iterator.next());
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("--help"));
- assertTrue(commandLine.hasOption("-?"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testCanProcess()
- */
- public void testCanProcess() {
- final DefaultOption option = buildHelpOption();
- assertTrue(option.canProcess(new
WriteableCommandLineImpl(option,null), "-?"));
- }
-
- public void testCanProcess_BadMatch() {
- final DefaultOption option = buildHelpOption();
- assertFalse(option.canProcess(new
WriteableCommandLineImpl(option,null), "-H"));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testPrefixes()
- */
- public void testPrefixes() {
- final DefaultOption option = buildHelpOption();
- assertContentsEqual(list("-", "--"), option.getPrefixes());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testProcess()
- */
- public void testProcess() {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testTriggers()
- */
- public void testTriggers() {
- final DefaultOption option = buildHelpOption();
- assertContentsEqual(list("-?", "-h", "--help"),
option.getTriggers());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testValidate()
- */
- public void testValidate() {
- final Parent option = buildXOption();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- try {
- option.validate(commandLine);
- fail("Missing an option");
- }
- catch (OptionException moe) {
- assertSame(option, moe.getOption());
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testAppendUsage()
- */
- public void testAppendUsage() {
- final Option option = buildHelpOption();
- final StringBuffer buffer = new StringBuffer();
- option.appendUsage(buffer, DisplaySetting.ALL, null);
-
- assertEquals("[--help (-?,-h)]", buffer.toString());
- }
-
- public void testAppendUsage_NoOptional() {
- final Option option = buildHelpOption();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_OPTIONAL);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("--help (-?,-h)", buffer.toString());
- }
-
- public void testAppendUsage_NoAlias() {
- final Option option = buildHelpOption();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_ALIASES);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("[--help]", buffer.toString());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
- */
- public void testGetPreferredName() {
- final Option option = buildHelpOption();
- assertEquals("--help", option.getPreferredName());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetDescription()
- */
- public void testGetDescription() {
- final Option option = buildHelpOption();
- assertEquals("Displays the help", option.getDescription());
- }
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines() {
- // TODO Auto-generated method stub
- }
-}
+/**
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.option;
+
+import net.dpml.cli.DisplaySetting;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.Parent;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * @author roberto
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class DefaultOptionTest extends AbstractParentTestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static DefaultOption buildHelpOption( )
+ {
+ final Set aliases = new HashSet( list( "-h", "-?" ) );
+
+ return new DefaultOption( "-", "--", true, "--help",
+ "Displays the help", aliases, aliases, false, null, null, 'h' );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static DefaultOption buildXOption( )
+ {
+ return new DefaultOption( "-", "--", true, "-X", "This is needed",
+ null, null, true, null, null, 'X' );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.ParentTestCase#testProcessParent()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessParent( ) throws OptionException
+ {
+ final DefaultOption option = buildHelpOption( );
+ final List args = list( "--help" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processParent( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "--help" ) );
+ assertTrue( commandLine.hasOption( "-?" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessParent_Burst( ) throws OptionException
+ {
+ final DefaultOption option = buildHelpOption( );
+ final List args = list( "-help" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processParent( commandLine, iterator );
+
+ assertEquals( "-elp", iterator.next( ) );
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "--help" ) );
+ assertTrue( commandLine.hasOption( "-?" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testCanProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess( )
+ {
+ final DefaultOption option = buildHelpOption( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "-?" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_BadMatch( )
+ {
+ final DefaultOption option = buildHelpOption( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "-H" ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testPrefixes()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPrefixes( )
+ {
+ final DefaultOption option = buildHelpOption( );
+ assertContentsEqual( list( "-", "--" ), option.getPrefixes( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testProcess( )
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testTriggers()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTriggers( )
+ {
+ final DefaultOption option = buildHelpOption( );
+ assertContentsEqual( list( "-?", "-h", "--help" ),
+ option.getTriggers( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testValidate()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate( )
+ {
+ final Parent option = buildXOption( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "Missing an option" );
+ }
+ catch( OptionException moe )
+ {
+ assertSame( option, moe.getOption( ) );
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testAppendUsage()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage( )
+ {
+ final Option option = buildHelpOption( );
+ final StringBuffer buffer = new StringBuffer( );
+ option.appendUsage( buffer, DisplaySetting.ALL, null );
+
+ assertEquals( "[--help (-?,-h)]", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoOptional( )
+ {
+ final Option option = buildHelpOption( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_OPTIONAL );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "--help (-?,-h)", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoAlias( )
+ {
+ final Option option = buildHelpOption( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_ALIASES );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "[--help]", buffer.toString( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetPreferredName( )
+ {
+ final Option option = buildHelpOption( );
+ assertEquals( "--help", option.getPreferredName( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetDescription()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetDescription( )
+ {
+ final Option option = buildHelpOption( );
+ assertEquals( "Displays the help", option.getDescription( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines( )
+ {
+ // TODO Auto-generated method stub
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/option/GroupTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/option/GroupTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/option/GroupTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,439 +1,598 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.option;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import net.dpml.cli.DisplaySetting;
-import net.dpml.cli.Group;
-import net.dpml.cli.HelpLine;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-
-/**
- * @author Rob Oxspring
- */
-public class GroupTest
- extends AbstractGroupTestCase {
- public static final Command COMMAND_START =
- new Command("start", "Starts the server", null, false, null, null,
0);
- public static final Command COMMAND_STOP =
- new Command("stop", "Stops the server", null, false, null, null, 0);
- public static final Command COMMAND_RESTART =
- new Command("restart", "Stops and starts the server", null, false,
null, null, 0);
- public static final Command COMMAND_GRACEFUL =
- new Command("graceful", "Restarts the server without interruption",
null, false, null,
- null, 0);
-
- public static Group buildApacheCommandGroup() {
- final List options = new ArrayList();
- options.add(COMMAND_GRACEFUL);
- options.add(COMMAND_RESTART);
- options.add(COMMAND_START);
- options.add(COMMAND_STOP);
-
- return new GroupImpl(options, "httpd-cmds", "The command to pass to
the server", 1, 1);
- }
-
- public static Group buildApachectlGroup() {
- final List options = new ArrayList();
- options.add(DefaultOptionTest.buildHelpOption());
- options.add(ParentTest.buildKParent());
-
- return new GroupImpl(options, "apachectl", "Controls the apache http
deamon", 0,
- Integer.MAX_VALUE);
- }
-
- public static Group buildAntGroup() {
- final List options = new ArrayList();
- options.add(DefaultOptionTest.buildHelpOption());
- options.add(ArgumentTest.buildTargetsArgument());
-
- return new GroupImpl(options, "ant", "The options for ant", 0,
Integer.MAX_VALUE);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.GroupTestCase#testProcessAnonymousArguments()
- */
- public void testProcessAnonymousArguments()
- throws OptionException {
- final Group option = buildAntGroup();
- final List args = list("compile,test", "dist");
- final ListIterator iterator = args.listIterator();
- final WriteableCommandLine commandLine = commandLine(option, args);
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption("target"));
- assertListContentsEqual(commandLine.getValues("target"), args);
- assertListContentsEqual(list("compile", "test", "dist"), args);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.GroupTestCase#testProcessOptions()
- */
- public void testProcessOptions()
- throws OptionException {
- final Group option = buildApachectlGroup();
- final List args = list("-?", "-k");
- final ListIterator iterator = args.listIterator();
- final WriteableCommandLine commandLine = commandLine(option, args);
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption("--help"));
- assertTrue(commandLine.hasOption("-k"));
- assertFalse(commandLine.hasOption("start"));
- assertListContentsEqual(list("--help", "-k"), args);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testCanProcess()
- */
- public void testCanProcess() {
- final Group option = buildApacheCommandGroup();
- assertTrue(option.canProcess(new WriteableCommandLineImpl(option,
null), "start"));
- }
-
- public void testCanProcess_BadMatch() {
- final Group option = buildApacheCommandGroup();
- assertFalse(option.canProcess(new WriteableCommandLineImpl(option,
null), "begin"));
- }
-
- public void testCanProcess_NullMatch() {
- final Group option = buildApacheCommandGroup();
- assertFalse(option.canProcess(new WriteableCommandLineImpl(option,
null), (String) null));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testPrefixes()
- */
- public void testPrefixes() {
- final Group option = buildApachectlGroup();
- assertContentsEqual(list("-", "--"), option.getPrefixes());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testProcess()
- */
- public void testProcess()
- throws OptionException {
- final Group option = buildAntGroup();
- final List args = list("--help", "compile,test", "dist");
- final ListIterator iterator = args.listIterator();
- final WriteableCommandLine commandLine = commandLine(option, args);
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption("-?"));
- assertListContentsEqual(list("compile", "test", "dist"),
commandLine.getValues("target"));
- }
-
- public void testProcess_Nested()
- throws OptionException {
- final Group option = buildApachectlGroup();
- final List args = list("-h", "-k", "graceful");
- final ListIterator iterator = args.listIterator();
- final WriteableCommandLine commandLine = commandLine(option, args);
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption("-?"));
- assertTrue(commandLine.hasOption("-k"));
- assertTrue(commandLine.hasOption("graceful"));
- assertFalse(commandLine.hasOption("stop"));
- assertTrue(commandLine.getValues("start").isEmpty());
- assertListContentsEqual(list("--help", "-k", "graceful"), args);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testTriggers()
- */
- public void testTriggers() {
- final Group option = buildApachectlGroup();
- assertContentsEqual(list("--help", "-?", "-h", "-k"),
option.getTriggers());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testValidate()
- */
- public void testValidate()
- throws OptionException {
- final Group option = buildApacheCommandGroup();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- commandLine.addOption(COMMAND_RESTART);
-
- option.validate(commandLine);
- }
-
- public void testValidate_UnexpectedOption() {
- final Group option = buildApacheCommandGroup();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- commandLine.addOption(COMMAND_RESTART);
- commandLine.addOption(COMMAND_GRACEFUL);
-
- try {
- option.validate(commandLine);
- fail("Too many options");
- } catch (OptionException uoe) {
- assertEquals(option, uoe.getOption());
- }
- }
-
- public void testValidate_MissingOption() {
- final Group option = buildApacheCommandGroup();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- try {
- option.validate(commandLine);
- fail("Missing an option");
- } catch (OptionException moe) {
- assertEquals(option, moe.getOption());
- }
- }
-
- public void testValidate_RequiredChild()
- throws OptionException {
- final Option required =
- new
DefaultOptionBuilder().withLongName("required").withRequired(true).create();
- final Option optional =
- new
DefaultOptionBuilder().withLongName("optional").withRequired(false).create();
- final Group group =
- new
GroupBuilder().withOption(required).withOption(optional).withMinimum(1).create();
-
- WriteableCommandLine commandLine;
-
- commandLine = commandLine(group, list());
-
- try {
- group.validate(commandLine);
- fail("Missing option 'required'");
- } catch (OptionException moe) {
- assertEquals(required, moe.getOption());
- }
-
- commandLine = commandLine(group, list());
- commandLine.addOption(optional);
-
- try {
- group.validate(commandLine);
- fail("Missing option 'required'");
- } catch (OptionException moe) {
- assertEquals(required, moe.getOption());
- }
-
- commandLine = commandLine(group, list());
- commandLine.addOption(required);
- group.validate(commandLine);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testAppendUsage()
- */
- public void testAppendUsage() {
- final Option option = buildApacheCommandGroup();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
-
- //settings.remove(DisplaySetting.DISPLAY_ARGUMENT_NUMBERED);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("httpd-cmds (graceful|restart|start|stop)",
buffer.toString());
- }
-
- public void testAppendUsage_NoOptional() {
- final Option option = buildApacheCommandGroup();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_OPTIONAL);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("httpd-cmds (graceful|restart|start|stop)",
buffer.toString());
- }
-
- public void testAppendUsage_NoExpand() {
- final Option option = buildApacheCommandGroup();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("httpd-cmds", buffer.toString());
- }
-
- public void testAppendUsage_NoExpandOrName() {
- final Option option = buildApacheCommandGroup();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
- settings.remove(DisplaySetting.DISPLAY_GROUP_NAME);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("httpd-cmds", buffer.toString());
- }
-
- public void testAppendUsage_NoName() {
- final Option option = buildApacheCommandGroup();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_GROUP_NAME);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("graceful|restart|start|stop", buffer.toString());
- }
-
- public void testAppendUsage_WithArgs() {
- final Option option = buildAntGroup();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_GROUP_OUTER);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("[ant (--help (-?,-h)) [<target1> [<target2> ...]]]",
buffer.toString());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
- */
- public void testGetPreferredName() {
- final Option option = buildAntGroup();
- assertEquals("ant", option.getPreferredName());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetDescription()
- */
- public void testGetDescription() {
- final Option option = buildApachectlGroup();
- assertEquals("Controls the apache http deamon",
option.getDescription());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines() {
- final Option option = buildApacheCommandGroup();
- final List lines = option.helpLines(0, DisplaySetting.ALL, null);
- final Iterator i = lines.iterator();
-
- final HelpLine line1 = (HelpLine) i.next();
- assertEquals(0, line1.getIndent());
- assertEquals(option, line1.getOption());
-
- final HelpLine line2 = (HelpLine) i.next();
- assertEquals(1, line2.getIndent());
- assertEquals(COMMAND_GRACEFUL, line2.getOption());
-
- final HelpLine line3 = (HelpLine) i.next();
- assertEquals(1, line3.getIndent());
- assertEquals(COMMAND_RESTART, line3.getOption());
-
- final HelpLine line4 = (HelpLine) i.next();
- assertEquals(1, line4.getIndent());
- assertEquals(COMMAND_START, line4.getOption());
-
- final HelpLine line5 = (HelpLine) i.next();
- assertEquals(1, line5.getIndent());
- assertEquals(COMMAND_STOP, line5.getOption());
-
- assertFalse(i.hasNext());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines_NoExpanded() {
- final Option option = buildApacheCommandGroup();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
-
- final List lines = option.helpLines(0, settings, null);
- final Iterator i = lines.iterator();
-
- final HelpLine line1 = (HelpLine) i.next();
- assertEquals(0, line1.getIndent());
- assertEquals(option, line1.getOption());
-
- assertFalse(i.hasNext());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines_NoName() {
- final Option option = buildApacheCommandGroup();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_GROUP_NAME);
-
- final List lines = option.helpLines(0, settings, null);
- final Iterator i = lines.iterator();
-
- final HelpLine line2 = (HelpLine) i.next();
- assertEquals(1, line2.getIndent());
- assertEquals(COMMAND_GRACEFUL, line2.getOption());
-
- final HelpLine line3 = (HelpLine) i.next();
- assertEquals(1, line3.getIndent());
- assertEquals(COMMAND_RESTART, line3.getOption());
-
- final HelpLine line4 = (HelpLine) i.next();
- assertEquals(1, line4.getIndent());
- assertEquals(COMMAND_START, line4.getOption());
-
- final HelpLine line5 = (HelpLine) i.next();
- assertEquals(1, line5.getIndent());
- assertEquals(COMMAND_STOP, line5.getOption());
-
- assertFalse(i.hasNext());
- }
-}
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.option;
+
+import net.dpml.cli.DisplaySetting;
+import net.dpml.cli.Group;
+import net.dpml.cli.HelpLine;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * @author Rob Oxspring
+ */
+public class GroupTest extends AbstractGroupTestCase
+{
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Command COMMAND_START = new Command( "start",
+ "Starts the server", null, false, null, null, 0 );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Command COMMAND_STOP = new Command( "stop",
+ "Stops the server", null, false, null, null, 0 );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Command COMMAND_RESTART = new Command( "restart",
+ "Stops and starts the server", null, false, null, null, 0 );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Command COMMAND_GRACEFUL = new Command( "graceful",
+ "Restarts the server without interruption", null, false, null,
+ null, 0 );
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Group buildApacheCommandGroup( )
+ {
+ final List options = new ArrayList( );
+ options.add( COMMAND_GRACEFUL );
+ options.add( COMMAND_RESTART );
+ options.add( COMMAND_START );
+ options.add( COMMAND_STOP );
+
+ return new GroupImpl( options, "httpd-cmds",
+ "The command to pass to the server", 1, 1 );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Group buildApachectlGroup( )
+ {
+ final List options = new ArrayList( );
+ options.add( DefaultOptionTest.buildHelpOption( ) );
+ options.add( ParentTest.buildKParent( ) );
+
+ return new GroupImpl( options, "apachectl",
+ "Controls the apache http deamon", 0, Integer.MAX_VALUE );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Group buildAntGroup( )
+ {
+ final List options = new ArrayList( );
+ options.add( DefaultOptionTest.buildHelpOption( ) );
+ options.add( ArgumentTest.buildTargetsArgument( ) );
+
+ return new GroupImpl( options, "ant", "The options for ant", 0,
+ Integer.MAX_VALUE );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.GroupTestCase#testProcessAnonymousArguments()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessAnonymousArguments( ) throws OptionException
+ {
+ final Group option = buildAntGroup( );
+ final List args = list( "compile,test", "dist" );
+ final ListIterator iterator = args.listIterator( );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( "target" ) );
+ assertListContentsEqual( commandLine.getValues( "target" ), args );
+ assertListContentsEqual( list( "compile", "test", "dist" ), args );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.GroupTestCase#testProcessOptions()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessOptions( ) throws OptionException
+ {
+ final Group option = buildApachectlGroup( );
+ final List args = list( "-?", "-k" );
+ final ListIterator iterator = args.listIterator( );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( "--help" ) );
+ assertTrue( commandLine.hasOption( "-k" ) );
+ assertFalse( commandLine.hasOption( "start" ) );
+ assertListContentsEqual( list( "--help", "-k" ), args );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testCanProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess( )
+ {
+ final Group option = buildApacheCommandGroup( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "start" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_BadMatch( )
+ {
+ final Group option = buildApacheCommandGroup( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "begin" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_NullMatch( )
+ {
+ final Group option = buildApacheCommandGroup( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), (String) null
) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testPrefixes()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPrefixes( )
+ {
+ final Group option = buildApachectlGroup( );
+ assertContentsEqual( list( "-", "--" ), option.getPrefixes( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess( ) throws OptionException
+ {
+ final Group option = buildAntGroup( );
+ final List args = list( "--help", "compile,test", "dist" );
+ final ListIterator iterator = args.listIterator( );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( "-?" ) );
+ assertListContentsEqual( list( "compile", "test", "dist" ),
+ commandLine.getValues( "target" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_Nested( ) throws OptionException
+ {
+ final Group option = buildApachectlGroup( );
+ final List args = list( "-h", "-k", "graceful" );
+ final ListIterator iterator = args.listIterator( );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( "-?" ) );
+ assertTrue( commandLine.hasOption( "-k" ) );
+ assertTrue( commandLine.hasOption( "graceful" ) );
+ assertFalse( commandLine.hasOption( "stop" ) );
+ assertTrue( commandLine.getValues( "start" ).isEmpty( ) );
+ assertListContentsEqual( list( "--help", "-k", "graceful" ), args );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testTriggers()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTriggers( )
+ {
+ final Group option = buildApachectlGroup( );
+ assertContentsEqual( list( "--help", "-?", "-h", "-k" ),
+ option.getTriggers( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testValidate()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testValidate( ) throws OptionException
+ {
+ final Group option = buildApacheCommandGroup( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ commandLine.addOption( COMMAND_RESTART );
+
+ option.validate( commandLine );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_UnexpectedOption( )
+ {
+ final Group option = buildApacheCommandGroup( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ commandLine.addOption( COMMAND_RESTART );
+ commandLine.addOption( COMMAND_GRACEFUL );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "Too many options" );
+ }
+ catch( OptionException uoe )
+ {
+ assertEquals( option, uoe.getOption( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_MissingOption( )
+ {
+ final Group option = buildApacheCommandGroup( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "Missing an option" );
+ }
+ catch( OptionException moe )
+ {
+ assertEquals( option, moe.getOption( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testValidate_RequiredChild( ) throws OptionException
+ {
+ final Option required = new DefaultOptionBuilder( ).withLongName(
+ "required" ).withRequired( true ).create( );
+ final Option optional = new DefaultOptionBuilder( ).withLongName(
+ "optional" ).withRequired( false ).create( );
+ final Group group = new GroupBuilder( ).withOption( required )
+ .withOption( optional )
+ .withMinimum( 1 ).create( );
+
+ WriteableCommandLine commandLine;
+
+ commandLine = commandLine( group, list( ) );
+
+ try
+ {
+ group.validate( commandLine );
+ fail( "Missing option 'required'" );
+ }
+ catch( OptionException moe )
+ {
+ assertEquals( required, moe.getOption( ) );
+ }
+
+ commandLine = commandLine( group, list( ) );
+ commandLine.addOption( optional );
+
+ try
+ {
+ group.validate( commandLine );
+ fail( "Missing option 'required'" );
+ }
+ catch( OptionException moe )
+ {
+ assertEquals( required, moe.getOption( ) );
+ }
+
+ commandLine = commandLine( group, list( ) );
+ commandLine.addOption( required );
+ group.validate( commandLine );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testAppendUsage()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage( )
+ {
+ final Option option = buildApacheCommandGroup( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+
+ //settings.remove(DisplaySetting.DISPLAY_ARGUMENT_NUMBERED);
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "httpd-cmds (graceful|restart|start|stop)",
+ buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoOptional( )
+ {
+ final Option option = buildApacheCommandGroup( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_OPTIONAL );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "httpd-cmds (graceful|restart|start|stop)",
+ buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoExpand( )
+ {
+ final Option option = buildApacheCommandGroup( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_EXPANDED );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "httpd-cmds", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoExpandOrName( )
+ {
+ final Option option = buildApacheCommandGroup( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_EXPANDED );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_NAME );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "httpd-cmds", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoName( )
+ {
+ final Option option = buildApacheCommandGroup( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_NAME );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "graceful|restart|start|stop", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_WithArgs( )
+ {
+ final Option option = buildAntGroup( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_OUTER );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "[ant (--help (-?,-h)) [<target1> [<target2> ...]]]",
+ buffer.toString( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetPreferredName( )
+ {
+ final Option option = buildAntGroup( );
+ assertEquals( "ant", option.getPreferredName( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetDescription()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetDescription( )
+ {
+ final Option option = buildApachectlGroup( );
+ assertEquals( "Controls the apache http deamon",
+ option.getDescription( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines( )
+ {
+ final Option option = buildApacheCommandGroup( );
+ final List lines = option.helpLines( 0, DisplaySetting.ALL, null );
+ final Iterator i = lines.iterator( );
+
+ final HelpLine line1 = (HelpLine) i.next( );
+ assertEquals( 0, line1.getIndent( ) );
+ assertEquals( option, line1.getOption( ) );
+
+ final HelpLine line2 = (HelpLine) i.next( );
+ assertEquals( 1, line2.getIndent( ) );
+ assertEquals( COMMAND_GRACEFUL, line2.getOption( ) );
+
+ final HelpLine line3 = (HelpLine) i.next( );
+ assertEquals( 1, line3.getIndent( ) );
+ assertEquals( COMMAND_RESTART, line3.getOption( ) );
+
+ final HelpLine line4 = (HelpLine) i.next( );
+ assertEquals( 1, line4.getIndent( ) );
+ assertEquals( COMMAND_START, line4.getOption( ) );
+
+ final HelpLine line5 = (HelpLine) i.next( );
+ assertEquals( 1, line5.getIndent( ) );
+ assertEquals( COMMAND_STOP, line5.getOption( ) );
+
+ assertFalse( i.hasNext( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines_NoExpanded( )
+ {
+ final Option option = buildApacheCommandGroup( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_EXPANDED );
+
+ final List lines = option.helpLines( 0, settings, null );
+ final Iterator i = lines.iterator( );
+
+ final HelpLine line1 = (HelpLine) i.next( );
+ assertEquals( 0, line1.getIndent( ) );
+ assertEquals( option, line1.getOption( ) );
+
+ assertFalse( i.hasNext( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines_NoName( )
+ {
+ final Option option = buildApacheCommandGroup( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_NAME );
+
+ final List lines = option.helpLines( 0, settings, null );
+ final Iterator i = lines.iterator( );
+
+ final HelpLine line2 = (HelpLine) i.next( );
+ assertEquals( 1, line2.getIndent( ) );
+ assertEquals( COMMAND_GRACEFUL, line2.getOption( ) );
+
+ final HelpLine line3 = (HelpLine) i.next( );
+ assertEquals( 1, line3.getIndent( ) );
+ assertEquals( COMMAND_RESTART, line3.getOption( ) );
+
+ final HelpLine line4 = (HelpLine) i.next( );
+ assertEquals( 1, line4.getIndent( ) );
+ assertEquals( COMMAND_START, line4.getOption( ) );
+
+ final HelpLine line5 = (HelpLine) i.next( );
+ assertEquals( 1, line5.getIndent( ) );
+ assertEquals( COMMAND_STOP, line5.getOption( ) );
+
+ assertFalse( i.hasNext( ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/option/NestedGroupTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/option/NestedGroupTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/option/NestedGroupTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,191 +1,210 @@
-/**
- * Copyright 2003-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 net.dpml.cli.option;
-
-import net.dpml.cli.AbstractCLITestCase;
-import net.dpml.cli.CommandLine;
-import net.dpml.cli.Group;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.Parser;
-import net.dpml.cli.util.HelpFormatter;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * Test to exercise nested groups developed to demonstrate bug 32533
- */
-public class NestedGroupTest extends AbstractCLITestCase {
- final static DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
- final static ArgumentBuilder abuilder = new ArgumentBuilder();
- final static GroupBuilder gbuilder = new GroupBuilder();
-
- static Group buildActionGroup() {
- return gbuilder.withName("Action").withDescription("Action")
- .withMinimum(1).withMaximum(1)
- .withOption(obuilder.withId(5).withShortName("e")
- .withLongName("encrypt")
- .withDescription("Encrypt input")
- .create())
- .withOption(obuilder.withId(6).withShortName("d")
- .withLongName("decrypt")
- .withDescription("Decrypt input")
- .create()).create();
- }
-
- static Group buildAlgorithmGroup() {
- return gbuilder.withName("Algorithm")
- .withDescription("Encryption
Algorithm").withMaximum(1)
- .withOption(obuilder.withId(0).withShortName("b")
- .withLongName("blowfish")
-
.withDescription("Blowfish").create())
- .withOption(obuilder.withId(1).withShortName("3")
- .withLongName("3DES")
- .withDescription("Triple DES")
- .create()).create();
- }
-
- static Group buildInputGroup() {
- return
gbuilder.withName("Input").withDescription("Input").withMinimum(1)
- .withMaximum(1)
- .withOption(obuilder.withId(2).withShortName("f")
- .withLongName("file")
- .withDescription("Input file")
- .withArgument(abuilder.withName(
- "file").withMinimum(1).withMaximum(1).create()).create())
- .withOption(obuilder.withId(3).withShortName("s")
- .withLongName("string")
- .withDescription("Input string")
- .withArgument(abuilder.withName(
-
"string").withMinimum(1).withMaximum(1).create()).create())
- .create();
- }
-
- static Group buildEncryptionServiceGroup(Group[] nestedGroups) {
- gbuilder.withName("encryptionService")
- .withOption(obuilder.withId(4).withShortName("h")
- .withLongName("help")
- .withDescription("Print this message")
-
.create()).withOption(obuilder.withShortName(
- "k").withLongName("key").withDescription("Encryption key")
- .create());
-
- for (int i = 0; i < nestedGroups.length; i++) {
- gbuilder.withOption(nestedGroups[i]);
- }
-
- return gbuilder.create();
- }
-
- public void testNestedGroup()
- throws OptionException {
- final String[] args = {
- "-eb",
- "--file",
- "/tmp/filename.txt"
- };
-
- Group[] nestedGroups = {
- buildActionGroup(),
- buildAlgorithmGroup(),
- buildInputGroup()
- };
-
- Parser parser = new Parser();
- parser.setGroup(buildEncryptionServiceGroup(nestedGroups));
-
- CommandLine commandLine = parser.parse(args);
-
- assertTrue("/tmp/filename.txt".equals(commandLine.getValue("-f")));
- assertTrue(commandLine.hasOption("-e"));
- assertTrue(commandLine.hasOption("-b"));
- assertFalse(commandLine.hasOption("-d"));
- }
-
- public void testNestedGroupHelp() {
- Group[] nestedGroups = {
- buildActionGroup(),
- buildAlgorithmGroup(),
- buildInputGroup()
- };
-
- HelpFormatter helpFormatter = new HelpFormatter();
- helpFormatter.setGroup(buildEncryptionServiceGroup(nestedGroups));
-
- final StringWriter out = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(out));
-
- try {
- helpFormatter.print();
-
- final BufferedReader bufferedReader = new BufferedReader(new
StringReader(
- out.toString()));
- final String[] expected = new String[] {
- "Usage:
",
- " [-h -k -e|-d -b|-3 -f <file>|-s <string>]
",
- "encryptionService
",
- " -h (--help) Print this message
",
- " -k (--key) Encryption key
",
- " Action Action
",
- " -e (--encrypt) Encrypt input
",
- " -d (--decrypt) Decrypt input
",
- " Algorithm Encryption Algorithm
",
- " -b (--blowfish) Blowfish
",
- " -3 (--3DES) Triple DES
",
- " Input Input
",
- " -f (--file) file Input file
",
- " -s (--string) string Input string
"
- };
-
- List actual = new ArrayList(expected.length);
- String input;
-
- while ((input = bufferedReader.readLine()) != null) {
- actual.add(input);
- }
-
- // Show they are the same number of lines
- assertEquals("Help text lines should be " + expected.length,
- actual.size(), expected.length);
-
- for (int i = 0; i < expected.length; i++) {
- if (!expected[i].equals(actual.get(i))) {
- for (int x = 0; x < expected.length; i++) {
- System.out.println(" " + expected[i]);
- System.out.println((expected[i].equals(actual.get(i))
- ? "== "
- : "!= ") + actual.get(i));
- }
- }
-
- assertEquals(expected[i], actual.get(i));
- }
- }
- catch (IOException e) {
- fail(e.getLocalizedMessage());
- }
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.option;
+
+import net.dpml.cli.AbstractCLITestCase;
+import net.dpml.cli.CommandLine;
+import net.dpml.cli.Group;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.Parser;
+import net.dpml.cli.util.HelpFormatter;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test to exercise nested groups developed to demonstrate bug 32533
+ */
+public class NestedGroupTest extends AbstractCLITestCase
+{
+ final static DefaultOptionBuilder obuilder = new DefaultOptionBuilder(
);
+ final static ArgumentBuilder abuilder = new ArgumentBuilder( );
+ final static GroupBuilder gbuilder = new GroupBuilder( );
+
+ static Group buildActionGroup( )
+ {
+ return gbuilder.withName( "Action" ).withDescription( "Action" )
+ .withMinimum( 1 ).withMaximum( 1 )
+ .withOption( obuilder.withId( 5 ).withShortName( "e" )
+ .withLongName( "encrypt" )
+ .withDescription( "Encrypt
input" )
+ .create( ) )
+ .withOption( obuilder.withId( 6 ).withShortName( "d" )
+ .withLongName( "decrypt" )
+ .withDescription( "Decrypt
input" )
+ .create( ) ).create( );
+ }
+
+ static Group buildAlgorithmGroup( )
+ {
+ return gbuilder.withName( "Algorithm" )
+ .withDescription( "Encryption Algorithm"
).withMaximum( 1 )
+ .withOption( obuilder.withId( 0 ).withShortName( "b" )
+ .withLongName( "blowfish" )
+ .withDescription( "Blowfish" )
+ .create( ) )
+ .withOption( obuilder.withId( 1 ).withShortName( "3" )
+ .withLongName( "3DES" )
+ .withDescription( "Triple DES" )
+ .create( ) ).create( );
+ }
+
+ static Group buildInputGroup( )
+ {
+ return gbuilder.withName( "Input" ).withDescription( "Input" )
+ .withMinimum( 1 ).withMaximum( 1 )
+ .withOption( obuilder.withId( 2 ).withShortName( "f" )
+ .withLongName( "file" )
+ .withDescription( "Input file" )
+ .withArgument(
abuilder.withName(
+ "file" ).withMinimum( 1 ).withMaximum( 1 ).create( ) )
+ .create( ) )
+ .withOption( obuilder.withId( 3 ).withShortName( "s" )
+ .withLongName( "string" )
+ .withDescription( "Input string"
)
+ .withArgument(
abuilder.withName(
+ "string" ).withMinimum( 1 ).withMaximum( 1 ).create( ) )
+ .create( ) ).create( );
+ }
+
+ static Group buildEncryptionServiceGroup( Group[] nestedGroups )
+ {
+ gbuilder.withName( "encryptionService" )
+ .withOption( obuilder.withId( 4 ).withShortName( "h" )
+ .withLongName( "help" )
+ .withDescription( "Print this message" )
+ .create( ) )
+ .withOption( obuilder.withShortName( "k" ).withLongName(
"key" )
+ .withDescription( "Encryption key" )
+ .create( ) );
+
+ for( int i = 0; i < nestedGroups.length; i++ )
+ {
+ gbuilder.withOption( nestedGroups[i] );
+ }
+
+ return gbuilder.create( );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testNestedGroup( ) throws OptionException
+ {
+ final String[] args = {"-eb", "--file", "/tmp/filename.txt"};
+
+ Group[] nestedGroups =
+ {
+ buildActionGroup( ), buildAlgorithmGroup( ),
+ buildInputGroup( )
+ };
+
+ Parser parser = new Parser( );
+ parser.setGroup( buildEncryptionServiceGroup( nestedGroups ) );
+
+ CommandLine commandLine = parser.parse( args );
+
+ assertTrue( "/tmp/filename.txt".equals( commandLine.getValue( "-f" )
) );
+ assertTrue( commandLine.hasOption( "-e" ) );
+ assertTrue( commandLine.hasOption( "-b" ) );
+ assertFalse( commandLine.hasOption( "-d" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNestedGroupHelp( )
+ {
+ Group[] nestedGroups =
+ {
+ buildActionGroup( ), buildAlgorithmGroup( ),
+ buildInputGroup( )
+ };
+
+ HelpFormatter helpFormatter = new HelpFormatter( );
+ helpFormatter.setGroup( buildEncryptionServiceGroup( nestedGroups )
);
+
+ final StringWriter out = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( out ) );
+
+ try
+ {
+ helpFormatter.print( );
+
+ final BufferedReader bufferedReader = new BufferedReader( new
StringReader(
+ out.toString( ) ) );
+ final String[] expected = new String[]
+ {
+ "Usage:
",
+ " [-h -k -e|-d -b|-3 -f <file>|-s <string>]
",
+ "encryptionService
",
+ " -h (--help) Print this message
",
+ " -k (--key) Encryption key
",
+ " Action Action
",
+ " -e (--encrypt) Encrypt input
",
+ " -d (--decrypt) Decrypt input
",
+ " Algorithm Encryption Algorithm
",
+ " -b (--blowfish) Blowfish
",
+ " -3 (--3DES) Triple DES
",
+ " Input Input
",
+ " -f (--file) file Input file
",
+ " -s (--string) string Input string
"
+ };
+
+ List actual = new ArrayList( expected.length );
+ String input;
+
+ while( ( input = bufferedReader.readLine( ) ) != null )
+ {
+ actual.add( input );
+ }
+
+ // Show they are the same number of lines
+ assertEquals( "Help text lines should be " + expected.length,
+ actual.size( ), expected.length );
+
+ for( int i = 0; i < expected.length; i++ )
+ {
+ if( !expected[i].equals( actual.get( i ) ) )
+ {
+ for( int x = 0; x < expected.length; i++ )
+ {
+ System.out.println( " " + expected[i] );
+ System.out.println( ( expected[i].equals(
actual.get( i ) )
+ ? "== " : "!= " ) + actual.get( i ) );
+ }
+ }
+
+ assertEquals( expected[i], actual.get( i ) );
+ }
+ }
+ catch( IOException e )
+ {
+ fail( e.getLocalizedMessage( ) );
+ }
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/option/ParentTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/option/ParentTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/option/ParentTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,422 +1,596 @@
-/**
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.option;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import net.dpml.cli.Argument;
-import net.dpml.cli.DisplaySetting;
-import net.dpml.cli.Group;
-import net.dpml.cli.HelpLine;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.Parent;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.builder.ArgumentBuilder;
-import net.dpml.cli.builder.CommandBuilder;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-/**
- * @author Rob Oxspring
- */
-public class ParentTest
- extends AbstractParentTestCase {
- public static final Argument COMPLEX_ARGUMENT =
- new
ArgumentBuilder().withName("username").withMinimum(1).withMaximum(1).create();
- public static final Option COMPLEX_CHILD_SSL =
- new
DefaultOptionBuilder().withLongName("ssl").withShortName("s").create();
- public static final Option COMPLEX_CHILD_BASIC =
- new
DefaultOptionBuilder().withLongName("basic").withShortName("b").create();
- public static final Option COMPLEX_CHILD_DIGEST =
- new
DefaultOptionBuilder().withLongName("digest").withShortName("d").create();
- public static final Group COMPLEX_CHILDREN =
- new
GroupBuilder().withName("login-opts").withOption(COMPLEX_CHILD_BASIC)
-
.withOption(COMPLEX_CHILD_DIGEST).withOption(COMPLEX_CHILD_SSL).create();
-
- public static Parent buildLibParent() {
- final Argument argument = ArgumentTest.buildPathArgument();
-
- return new DefaultOption("-", "--", false, "--lib", "Specifies
library search path", null,
- null, false, argument, null, 'l');
- }
-
- public static Parent buildKParent() {
- final Group children = GroupTest.buildApacheCommandGroup();
-
- return new DefaultOption("-", "--", false, "-k", "desc", null, null,
false, null, children,
- 'k');
- }
-
- public static Parent buildComplexParent() {
- return new
CommandBuilder().withName("login").withName("lo").withName("l")
-
.withArgument(COMPLEX_ARGUMENT).withChildren(COMPLEX_CHILDREN)
- .create();
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.ParentTestCase#testProcessParent()
- */
- public void testProcessParent()
- throws OptionException {
- final Parent option = buildKParent();
- final List args = list("-k", "start");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processParent(commandLine, iterator);
-
- assertEquals("start", iterator.next());
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("-k"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testCanProcess()
- */
- public void testCanProcess() {
- final Parent option = buildKParent();
- assertTrue(option.canProcess(new WriteableCommandLineImpl(option,
null), "-k"));
- }
-
- public void testCanProcess_BadMatch() {
- final Parent option = buildKParent();
- assertFalse(option.canProcess(new WriteableCommandLineImpl(option,
null), "-K"));
- }
-
- public void testCanProcess_ContractedArgument() {
- final Parent option = buildLibParent();
- assertTrue(option.canProcess(new WriteableCommandLineImpl(option,
null), "--lib=/usr/lib"));
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testPrefixes()
- */
- public void testPrefixes() {
- final Parent option = buildKParent();
- assertContentsEqual(list("-", "--"), option.getPrefixes());
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testProcess()
- */
- public void testProcess()
- throws OptionException {
- final Parent option = CommandTest.buildStartCommand();
- final List args = list("start");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("start"));
- assertFalse(commandLine.hasOption("stop"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- public void testProcess_NoMatch()
- throws OptionException {
- final Parent option = CommandTest.buildStartCommand();
- final List args = list("whatever");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- try {
- option.process(commandLine, iterator);
- fail("unexpected token not thrown");
- } catch (OptionException exp) {
- OptionException e =
- new OptionException(option,
ResourceConstants.UNEXPECTED_TOKEN, "whatever");
- assertEquals("wrong exception message", e.getMessage(),
exp.getMessage());
- }
- }
-
- public void testProcess_Children()
- throws OptionException {
- final Parent option = buildKParent();
- final List args = list("-k", "start");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.process(commandLine, iterator);
-
- assertNull(option.findOption("whatever"));
- assertNotNull(option.findOption("start"));
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("-k"));
- assertTrue(commandLine.hasOption("start"));
- assertFalse(commandLine.hasOption("stop"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- public void testProcess_Argument()
- throws OptionException {
- final Parent option = buildLibParent();
- final List args = list("--lib=C:\\WINDOWS;C:\\WINNT;C:\\");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("--lib"));
- assertContentsEqual(list("C:\\WINDOWS", "C:\\WINNT", "C:\\"),
commandLine.getValues(option));
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testTriggers()
- */
- public void testTriggers() {
- final Parent option = buildKParent();
- assertContentsEqual(list("-k"), option.getTriggers());
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testValidate()
- */
- public void testValidate()
- throws OptionException {
- final Parent option = CommandTest.buildStartCommand();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- option.validate(commandLine);
-
- commandLine.addOption(option);
-
- option.validate(commandLine);
- }
-
- public void testValidate_Children()
- throws OptionException {
- final Parent option = buildKParent();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- option.validate(commandLine);
- commandLine.addOption(option);
-
- try {
- option.validate(commandLine);
- fail("Missing a command");
- } catch (OptionException moe) {
- assertNotNull(moe.getOption());
- assertNotSame(option, moe.getOption());
- }
- }
-
- public void testValidate_Argument()
- throws OptionException {
- final Command option = CommandTest.buildLoginCommand();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- option.validate(commandLine);
-
- commandLine.addOption(option);
-
- try {
- option.validate(commandLine);
- fail("Missing a value");
- } catch (OptionException moe) {
- assertSame(option, moe.getOption());
- }
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testAppendUsage()
- */
- public void testAppendUsage() {
- final Option option = buildComplexParent();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_GROUP_OUTER);
- option.appendUsage(buffer, settings, null);
-
- //assertEquals("[login (l,lo) <username> [login-opts (--basic
(-b)|--digest (-d)|--ssl (-s))]]",
- // buffer.toString());
- assertEquals("[login (l,lo) <username> [login-opts (--basic (-b)
--digest (-d) --ssl (-s))]]",
- buffer.toString());
- }
-
- public void testAppendUsage_NoArguments() {
- final Option option = buildComplexParent();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
- settings.remove(DisplaySetting.DISPLAY_GROUP_OUTER);
- option.appendUsage(buffer, settings, null);
-
- //assertEquals("[login (l,lo) [login-opts (--basic (-b)|--digest
(-d)|--ssl (-s))]]",
- // buffer.toString());
- assertEquals("[login (l,lo) [login-opts (--basic (-b) --digest (-d)
--ssl (-s))]]",
- buffer.toString());
- }
-
- public void testAppendUsage_NoChildren() {
- final Option option = buildComplexParent();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("[login (l,lo) <username>]", buffer.toString());
- }
-
- public void testAppendUsage_NoArgumentsOrChildren() {
- final Option option = buildComplexParent();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
- settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("[login (l,lo)]", buffer.toString());
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
- */
- public void testGetPreferredName() {
- final Option option = buildLibParent();
- assertEquals("--lib", option.getPreferredName());
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testGetDescription()
- */
- public void testGetDescription() {
- final Option option = buildLibParent();
- assertEquals("Specifies library search path",
option.getDescription());
- }
-
- /* (non-Javadoc)
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines() {
- final Option option = buildComplexParent();
- final List lines = option.helpLines(0, DisplaySetting.ALL, null);
- final Iterator i = lines.iterator();
-
- final HelpLine line1 = (HelpLine) i.next();
- assertEquals(0, line1.getIndent());
- assertEquals(option, line1.getOption());
-
- final HelpLine line2 = (HelpLine) i.next();
- assertEquals(1, line2.getIndent());
- assertEquals(COMPLEX_ARGUMENT, line2.getOption());
-
- final HelpLine line3 = (HelpLine) i.next();
- assertEquals(1, line3.getIndent());
- assertEquals(COMPLEX_CHILDREN, line3.getOption());
-
- final HelpLine line4 = (HelpLine) i.next();
- assertEquals(2, line4.getIndent());
- assertEquals(COMPLEX_CHILD_BASIC, line4.getOption());
-
- final HelpLine line5 = (HelpLine) i.next();
- assertEquals(2, line5.getIndent());
- assertEquals(COMPLEX_CHILD_DIGEST, line5.getOption());
-
- final HelpLine line6 = (HelpLine) i.next();
- assertEquals(2, line6.getIndent());
- assertEquals(COMPLEX_CHILD_SSL, line6.getOption());
-
- assertFalse(i.hasNext());
- }
-
- public void testHelpLines_NoArgument() {
- final Option option = buildComplexParent();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
-
- final List lines = option.helpLines(0, settings, null);
- final Iterator i = lines.iterator();
-
- final HelpLine line1 = (HelpLine) i.next();
- assertEquals(0, line1.getIndent());
- assertEquals(option, line1.getOption());
-
- final HelpLine line3 = (HelpLine) i.next();
- assertEquals(1, line3.getIndent());
- assertEquals(COMPLEX_CHILDREN, line3.getOption());
-
- final HelpLine line4 = (HelpLine) i.next();
- assertEquals(2, line4.getIndent());
- assertEquals(COMPLEX_CHILD_BASIC, line4.getOption());
-
- final HelpLine line5 = (HelpLine) i.next();
- assertEquals(2, line5.getIndent());
- assertEquals(COMPLEX_CHILD_DIGEST, line5.getOption());
-
- final HelpLine line6 = (HelpLine) i.next();
- assertEquals(2, line6.getIndent());
- assertEquals(COMPLEX_CHILD_SSL, line6.getOption());
-
- assertFalse(i.hasNext());
- }
-
- public void testHelpLines_NoChildren() {
- final Option option = buildComplexParent();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
-
- final List lines = option.helpLines(0, settings, null);
- final Iterator i = lines.iterator();
-
- final HelpLine line1 = (HelpLine) i.next();
- assertEquals(0, line1.getIndent());
- assertEquals(option, line1.getOption());
-
- final HelpLine line2 = (HelpLine) i.next();
- assertEquals(1, line2.getIndent());
- assertEquals(COMPLEX_ARGUMENT, line2.getOption());
-
- assertFalse(i.hasNext());
- }
-
- public void testNullPreferredName() {
- try {
- new CommandBuilder().create();
- } catch (IllegalStateException exp) {
-
assertEquals(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.OPTION_NO_NAME),
exp.getMessage());
- }
- }
-
- public void testRequired() {
- Command cmd = new
CommandBuilder().withRequired(true).withName("blah").create();
- assertTrue("cmd is not required", cmd.isRequired());
- assertEquals("id is incorrect", 0, cmd.getId());
- }
-
- public void testID() {
- Command cmd = new
CommandBuilder().withId('c').withName("blah").create();
- assertEquals("id is incorrect", 'c', cmd.getId());
- }
-
- public void testGetId() {
- assertEquals('h', DefaultOptionTest.buildHelpOption().getId());
- assertEquals('X', DefaultOptionTest.buildXOption().getId());
- assertEquals(0, CommandTest.buildStartCommand().getId());
- }
-}
+/**
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.option;
+
+import net.dpml.cli.Argument;
+import net.dpml.cli.DisplaySetting;
+import net.dpml.cli.Group;
+import net.dpml.cli.HelpLine;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.Parent;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.builder.ArgumentBuilder;
+import net.dpml.cli.builder.CommandBuilder;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * @author Rob Oxspring
+ */
+public class ParentTest extends AbstractParentTestCase
+{
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Argument COMPLEX_ARGUMENT = new ArgumentBuilder(
).withName(
+ "username" ).withMinimum( 1 ).withMaximum( 1 ).create( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Option COMPLEX_CHILD_SSL = new DefaultOptionBuilder(
).withLongName(
+ "ssl" ).withShortName( "s" ).create( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Option COMPLEX_CHILD_BASIC = new
DefaultOptionBuilder( ).withLongName(
+ "basic" ).withShortName( "b" ).create( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Option COMPLEX_CHILD_DIGEST = new
DefaultOptionBuilder( ).withLongName(
+ "digest" ).withShortName( "d" ).create( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final Group COMPLEX_CHILDREN = new GroupBuilder(
).withName(
+ "login-opts" ).withOption( COMPLEX_CHILD_BASIC )
+
.withOption( COMPLEX_CHILD_DIGEST )
+
.withOption( COMPLEX_CHILD_SSL )
+
.create( );
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Parent buildLibParent( )
+ {
+ final Argument argument = ArgumentTest.buildPathArgument( );
+
+ return new DefaultOption( "-", "--", false, "--lib",
+ "Specifies library search path", null, null, false, argument,
null,
+ 'l' );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Parent buildKParent( )
+ {
+ final Group children = GroupTest.buildApacheCommandGroup( );
+
+ return new DefaultOption( "-", "--", false, "-k", "desc", null, null,
+ false, null, children, 'k' );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Parent buildComplexParent( )
+ {
+ return new CommandBuilder( ).withName( "login" ).withName( "lo" )
+ .withName( "l" )
+ .withArgument( COMPLEX_ARGUMENT )
+ .withChildren( COMPLEX_CHILDREN
).create( );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.ParentTestCase#testProcessParent()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessParent( ) throws OptionException
+ {
+ final Parent option = buildKParent( );
+ final List args = list( "-k", "start" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processParent( commandLine, iterator );
+
+ assertEquals( "start", iterator.next( ) );
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "-k" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testCanProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess( )
+ {
+ final Parent option = buildKParent( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "-k" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_BadMatch( )
+ {
+ final Parent option = buildKParent( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "-K" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_ContractedArgument( )
+ {
+ final Parent option = buildLibParent( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ),
"--lib=/usr/lib" ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testPrefixes()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPrefixes( )
+ {
+ final Parent option = buildKParent( );
+ assertContentsEqual( list( "-", "--" ), option.getPrefixes( ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess( ) throws OptionException
+ {
+ final Parent option = CommandTest.buildStartCommand( );
+ final List args = list( "start" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "start" ) );
+ assertFalse( commandLine.hasOption( "stop" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_NoMatch( ) throws OptionException
+ {
+ final Parent option = CommandTest.buildStartCommand( );
+ final List args = list( "whatever" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ try
+ {
+ option.process( commandLine, iterator );
+ fail( "unexpected token not thrown" );
+ }
+ catch( OptionException exp )
+ {
+ OptionException e = new OptionException( option,
+ ResourceConstants.UNEXPECTED_TOKEN, "whatever" );
+ assertEquals( "wrong exception message", e.getMessage( ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_Children( ) throws OptionException
+ {
+ final Parent option = buildKParent( );
+ final List args = list( "-k", "start" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.process( commandLine, iterator );
+
+ assertNull( option.findOption( "whatever" ) );
+ assertNotNull( option.findOption( "start" ) );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "-k" ) );
+ assertTrue( commandLine.hasOption( "start" ) );
+ assertFalse( commandLine.hasOption( "stop" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_Argument( ) throws OptionException
+ {
+ final Parent option = buildLibParent( );
+ final List args = list( "--lib=C:\\WINDOWS;C:\\WINNT;C:\\" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "--lib" ) );
+ assertContentsEqual( list( "C:\\WINDOWS", "C:\\WINNT", "C:\\" ),
+ commandLine.getValues( option ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testTriggers()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTriggers( )
+ {
+ final Parent option = buildKParent( );
+ assertContentsEqual( list( "-k" ), option.getTriggers( ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testValidate()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testValidate( ) throws OptionException
+ {
+ final Parent option = CommandTest.buildStartCommand( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ option.validate( commandLine );
+
+ commandLine.addOption( option );
+
+ option.validate( commandLine );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testValidate_Children( ) throws OptionException
+ {
+ final Parent option = buildKParent( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ option.validate( commandLine );
+ commandLine.addOption( option );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "Missing a command" );
+ }
+ catch( OptionException moe )
+ {
+ assertNotNull( moe.getOption( ) );
+ assertNotSame( option, moe.getOption( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testValidate_Argument( ) throws OptionException
+ {
+ final Command option = CommandTest.buildLoginCommand( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ option.validate( commandLine );
+
+ commandLine.addOption( option );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "Missing a value" );
+ }
+ catch( OptionException moe )
+ {
+ assertSame( option, moe.getOption( ) );
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testAppendUsage()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage( )
+ {
+ final Option option = buildComplexParent( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_OUTER );
+ option.appendUsage( buffer, settings, null );
+
+ //assertEquals("[login (l,lo) <username> [login-opts (--basic
(-b)|--digest (-d)|--ssl (-s))]]",
+ // buffer.toString());
+ assertEquals( "[login (l,lo) <username> [login-opts (--basic (-b)
--digest (-d) --ssl (-s))]]",
+ buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoArguments( )
+ {
+ final Option option = buildComplexParent( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_PARENT_ARGUMENT );
+ settings.remove( DisplaySetting.DISPLAY_GROUP_OUTER );
+ option.appendUsage( buffer, settings, null );
+
+ //assertEquals("[login (l,lo) [login-opts (--basic (-b)|--digest
(-d)|--ssl (-s))]]",
+ // buffer.toString());
+ assertEquals( "[login (l,lo) [login-opts (--basic (-b) --digest (-d)
--ssl (-s))]]",
+ buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoChildren( )
+ {
+ final Option option = buildComplexParent( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_PARENT_CHILDREN );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "[login (l,lo) <username>]", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoArgumentsOrChildren( )
+ {
+ final Option option = buildComplexParent( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_PARENT_CHILDREN );
+ settings.remove( DisplaySetting.DISPLAY_PARENT_ARGUMENT );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "[login (l,lo)]", buffer.toString( ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetPreferredName( )
+ {
+ final Option option = buildLibParent( );
+ assertEquals( "--lib", option.getPreferredName( ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testGetDescription()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetDescription( )
+ {
+ final Option option = buildLibParent( );
+ assertEquals( "Specifies library search path",
option.getDescription( ) );
+ }
+
+ /* (non-Javadoc)
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines( )
+ {
+ final Option option = buildComplexParent( );
+ final List lines = option.helpLines( 0, DisplaySetting.ALL, null );
+ final Iterator i = lines.iterator( );
+
+ final HelpLine line1 = (HelpLine) i.next( );
+ assertEquals( 0, line1.getIndent( ) );
+ assertEquals( option, line1.getOption( ) );
+
+ final HelpLine line2 = (HelpLine) i.next( );
+ assertEquals( 1, line2.getIndent( ) );
+ assertEquals( COMPLEX_ARGUMENT, line2.getOption( ) );
+
+ final HelpLine line3 = (HelpLine) i.next( );
+ assertEquals( 1, line3.getIndent( ) );
+ assertEquals( COMPLEX_CHILDREN, line3.getOption( ) );
+
+ final HelpLine line4 = (HelpLine) i.next( );
+ assertEquals( 2, line4.getIndent( ) );
+ assertEquals( COMPLEX_CHILD_BASIC, line4.getOption( ) );
+
+ final HelpLine line5 = (HelpLine) i.next( );
+ assertEquals( 2, line5.getIndent( ) );
+ assertEquals( COMPLEX_CHILD_DIGEST, line5.getOption( ) );
+
+ final HelpLine line6 = (HelpLine) i.next( );
+ assertEquals( 2, line6.getIndent( ) );
+ assertEquals( COMPLEX_CHILD_SSL, line6.getOption( ) );
+
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines_NoArgument( )
+ {
+ final Option option = buildComplexParent( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_PARENT_ARGUMENT );
+
+ final List lines = option.helpLines( 0, settings, null );
+ final Iterator i = lines.iterator( );
+
+ final HelpLine line1 = (HelpLine) i.next( );
+ assertEquals( 0, line1.getIndent( ) );
+ assertEquals( option, line1.getOption( ) );
+
+ final HelpLine line3 = (HelpLine) i.next( );
+ assertEquals( 1, line3.getIndent( ) );
+ assertEquals( COMPLEX_CHILDREN, line3.getOption( ) );
+
+ final HelpLine line4 = (HelpLine) i.next( );
+ assertEquals( 2, line4.getIndent( ) );
+ assertEquals( COMPLEX_CHILD_BASIC, line4.getOption( ) );
+
+ final HelpLine line5 = (HelpLine) i.next( );
+ assertEquals( 2, line5.getIndent( ) );
+ assertEquals( COMPLEX_CHILD_DIGEST, line5.getOption( ) );
+
+ final HelpLine line6 = (HelpLine) i.next( );
+ assertEquals( 2, line6.getIndent( ) );
+ assertEquals( COMPLEX_CHILD_SSL, line6.getOption( ) );
+
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines_NoChildren( )
+ {
+ final Option option = buildComplexParent( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_PARENT_CHILDREN );
+
+ final List lines = option.helpLines( 0, settings, null );
+ final Iterator i = lines.iterator( );
+
+ final HelpLine line1 = (HelpLine) i.next( );
+ assertEquals( 0, line1.getIndent( ) );
+ assertEquals( option, line1.getOption( ) );
+
+ final HelpLine line2 = (HelpLine) i.next( );
+ assertEquals( 1, line2.getIndent( ) );
+ assertEquals( COMPLEX_ARGUMENT, line2.getOption( ) );
+
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullPreferredName( )
+ {
+ try
+ {
+ new CommandBuilder( ).create( );
+ }
+ catch( IllegalStateException exp )
+ {
+ assertEquals( ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.OPTION_NO_NAME ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testRequired( )
+ {
+ Command cmd = new CommandBuilder( ).withRequired( true )
+ .withName( "blah" ).create( );
+ assertTrue( "cmd is not required", cmd.isRequired( ) );
+ assertEquals( "id is incorrect", 0, cmd.getId( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testID( )
+ {
+ Command cmd = new CommandBuilder( ).withId( 'c' ).withName( "blah" )
+ .create( );
+ assertEquals( "id is incorrect", 'c', cmd.getId( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetId( )
+ {
+ assertEquals( 'h', DefaultOptionTest.buildHelpOption( ).getId( ) );
+ assertEquals( 'X', DefaultOptionTest.buildXOption( ).getId( ) );
+ assertEquals( 0, CommandTest.buildStartCommand( ).getId( ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/option/PropertyOptionTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/option/PropertyOptionTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/option/PropertyOptionTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,232 +1,313 @@
-/**
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.option;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import net.dpml.cli.DisplaySetting;
-import net.dpml.cli.HelpLine;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-
-/**
- * @author Rob Oxspring
- */
-public class PropertyOptionTest extends AbstractOptionTestCase {
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testCanProcess()
- */
- public void testCanProcess() {
- final Option option = new PropertyOption();
- assertTrue(option.canProcess(new
WriteableCommandLineImpl(option,null), "-Dmyprop=myval"));
- }
-
- public void testCanProcess_Null() {
- final Option option = new PropertyOption();
- assertFalse(option.canProcess(new
WriteableCommandLineImpl(option,null), (String) null));
- }
-
- public void testCanProcess_TooShort() {
- final Option option = new PropertyOption();
- assertFalse(option.canProcess(new
WriteableCommandLineImpl(option,null), "-D"));
- }
-
- public void testCanProcess_BadMatch() {
- final Option option = new PropertyOption();
- assertFalse(option.canProcess(new
WriteableCommandLineImpl(option,null),"-dump"));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testPrefixes()
- */
- public void testPrefixes() {
- final Option option = new PropertyOption();
- assertContentsEqual(list("-D"), option.getPrefixes());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testProcess()
- */
- public void testProcess() throws OptionException {
- final Option option = new PropertyOption();
- final List args = list("-Dmyprop=myvalue");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- option.process(commandLine, iterator);
- assertEquals("myvalue", commandLine.getProperty("myprop"));
- assertFalse(iterator.hasNext());
- assertEquals(1, commandLine.getProperties().size());
- }
-
- public void testProcess_UnexpectedOptionException() {
- final Option option = new PropertyOption();
- final List args = list("--help");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- try {
- option.process(commandLine, iterator);
- fail("UnexpectedOption");
- }
- catch (final OptionException uoe) {
- assertEquals(option, uoe.getOption());
- assertEquals(
- "Unexpected --help while processing -Dproperty=value",
- uoe.getMessage());
- }
- }
-
- public void testProcess_BadPropertyException() throws OptionException {
- final Option option = new PropertyOption();
- final List args = list("-Dmyprop");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- option.process(commandLine, iterator);
-
- assertEquals("true", commandLine.getProperty("myprop"));
- }
-
- public void testProcess_SetToEmpty() throws OptionException {
- final Option option = new PropertyOption();
- final List args = list("-Dmyprop=");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- option.process(commandLine, iterator);
- assertEquals("", commandLine.getProperty("myprop"));
- assertFalse(iterator.hasNext());
- assertEquals(1, commandLine.getProperties().size());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testTriggers()
- */
- public void testTriggers() {
- final Option option = new PropertyOption();
-
- assertContentsEqual(list("-D"), option.getTriggers());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testValidate()
- */
- public void testValidate() throws OptionException {
- final Option option = new PropertyOption();
- final List args = list("-Dproperty=value");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
-
- option.process(commandLine, iterator);
-
- option.validate(commandLine);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testAppendUsage()
- */
- public void testAppendUsage() {
- final Option option = new PropertyOption();
- final StringBuffer buffer = new StringBuffer();
- option.appendUsage(buffer, DisplaySetting.ALL, null);
-
- assertEquals("-D<property>=<value>", buffer.toString());
- }
-
- public void testAppendUsage_Hidden() {
- final Option option = new PropertyOption();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_PROPERTY_OPTION);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("", buffer.toString());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
- */
- public void testGetPreferredName() {
- final Option option = new PropertyOption();
- assertEquals("-D", option.getPreferredName());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetDescription()
- */
- public void testGetDescription() {
- final Option option = new PropertyOption();
- assertEquals(
- PropertyOption.DEFAULT_DESCRIPTION,
- option.getDescription());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines() {
- final Option option = new PropertyOption();
- final List lines = option.helpLines(0, DisplaySetting.ALL, null);
- final Iterator i = lines.iterator();
-
- final HelpLine line1 = (HelpLine)i.next();
- assertEquals(0, line1.getIndent());
- assertEquals(option, line1.getOption());
-
- assertFalse(i.hasNext());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines_NoDisplay() {
- final Option option = new PropertyOption();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_PROPERTY_OPTION);
- final List lines = option.helpLines(0, settings, null);
- final Iterator i = lines.iterator();
-
- assertFalse(i.hasNext());
- }
-}
+/**
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.option;
+
+import net.dpml.cli.DisplaySetting;
+import net.dpml.cli.HelpLine;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * @author Rob Oxspring
+ */
+public class PropertyOptionTest extends AbstractOptionTestCase
+{
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testCanProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess( )
+ {
+ final Option option = new PropertyOption( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ),
"-Dmyprop=myval" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_Null( )
+ {
+ final Option option = new PropertyOption( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), (String) null
) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_TooShort( )
+ {
+ final Option option = new PropertyOption( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "-D" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_BadMatch( )
+ {
+ final Option option = new PropertyOption( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "-dump" ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testPrefixes()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPrefixes( )
+ {
+ final Option option = new PropertyOption( );
+ assertContentsEqual( list( "-D" ), option.getPrefixes( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess( ) throws OptionException
+ {
+ final Option option = new PropertyOption( );
+ final List args = list( "-Dmyprop=myvalue" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ option.process( commandLine, iterator );
+ assertEquals( "myvalue", commandLine.getProperty( "myprop" ) );
+ assertFalse( iterator.hasNext( ) );
+ assertEquals( 1, commandLine.getProperties( ).size( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testProcess_UnexpectedOptionException( )
+ {
+ final Option option = new PropertyOption( );
+ final List args = list( "--help" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ try
+ {
+ option.process( commandLine, iterator );
+ fail( "UnexpectedOption" );
+ }
+ catch( final OptionException uoe )
+ {
+ assertEquals( option, uoe.getOption( ) );
+ assertEquals( "Unexpected --help while processing
-Dproperty=value",
+ uoe.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_BadPropertyException( ) throws OptionException
+ {
+ final Option option = new PropertyOption( );
+ final List args = list( "-Dmyprop" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ option.process( commandLine, iterator );
+
+ assertEquals( "true", commandLine.getProperty( "myprop" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcess_SetToEmpty( ) throws OptionException
+ {
+ final Option option = new PropertyOption( );
+ final List args = list( "-Dmyprop=" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ option.process( commandLine, iterator );
+ assertEquals( "", commandLine.getProperty( "myprop" ) );
+ assertFalse( iterator.hasNext( ) );
+ assertEquals( 1, commandLine.getProperties( ).size( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testTriggers()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTriggers( )
+ {
+ final Option option = new PropertyOption( );
+
+ assertContentsEqual( list( "-D" ), option.getTriggers( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testValidate()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testValidate( ) throws OptionException
+ {
+ final Option option = new PropertyOption( );
+ final List args = list( "-Dproperty=value" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+
+ option.process( commandLine, iterator );
+
+ option.validate( commandLine );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testAppendUsage()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage( )
+ {
+ final Option option = new PropertyOption( );
+ final StringBuffer buffer = new StringBuffer( );
+ option.appendUsage( buffer, DisplaySetting.ALL, null );
+
+ assertEquals( "-D<property>=<value>", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_Hidden( )
+ {
+ final Option option = new PropertyOption( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_PROPERTY_OPTION );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "", buffer.toString( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetPreferredName( )
+ {
+ final Option option = new PropertyOption( );
+ assertEquals( "-D", option.getPreferredName( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetDescription()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetDescription( )
+ {
+ final Option option = new PropertyOption( );
+ assertEquals( PropertyOption.DEFAULT_DESCRIPTION,
+ option.getDescription( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines( )
+ {
+ final Option option = new PropertyOption( );
+ final List lines = option.helpLines( 0, DisplaySetting.ALL, null );
+ final Iterator i = lines.iterator( );
+
+ final HelpLine line1 = (HelpLine) i.next( );
+ assertEquals( 0, line1.getIndent( ) );
+ assertEquals( option, line1.getOption( ) );
+
+ assertFalse( i.hasNext( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines_NoDisplay( )
+ {
+ final Option option = new PropertyOption( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_PROPERTY_OPTION );
+
+ final List lines = option.helpLines( 0, settings, null );
+ final Iterator i = lines.iterator( );
+
+ assertFalse( i.hasNext( ) );
+ }
+}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/option/SwitchTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/option/SwitchTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/option/SwitchTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,307 +1,442 @@
-/**
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.option;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import net.dpml.cli.DisplaySetting;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.Parent;
-import net.dpml.cli.WriteableCommandLine;
-import net.dpml.cli.commandline.WriteableCommandLineImpl;
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-/**
- * @author Rob Oxspring
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class SwitchTest
- extends AbstractParentTestCase {
- public static Switch buildDisplaySwitch() {
- final Set aliases = new HashSet();
- aliases.add("d");
- aliases.add("disp");
-
- return new Switch("+", "-", "display", aliases, "Sets whether to
display to screen", true,
- null, null, 'd', null);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.ParentTestCase#testProcessParent()
- */
- public void testProcessParent()
- throws OptionException {
- final Switch option = buildDisplaySwitch();
- final List args = list("+d");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.processParent(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("+d"));
- assertTrue(commandLine.hasOption("-display"));
- assertEquals(Boolean.TRUE, commandLine.getSwitch("-d"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- public void testProcessParent_Disabled()
- throws OptionException {
- final Switch option = buildDisplaySwitch();
- final List args = list("-disp");
- final WriteableCommandLine commandLine = commandLine(option, args);
- final ListIterator iterator = args.listIterator();
- option.process(commandLine, iterator);
-
- assertFalse(iterator.hasNext());
- assertTrue(commandLine.hasOption(option));
- assertTrue(commandLine.hasOption("+d"));
- assertTrue(commandLine.hasOption("-display"));
- assertEquals(Boolean.FALSE, commandLine.getSwitch("-d"));
- assertTrue(commandLine.getValues(option).isEmpty());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testCanProcess()
- */
- public void testCanProcess() {
- final Switch option = buildDisplaySwitch();
- assertTrue(option.canProcess(new WriteableCommandLineImpl(option,
null), "+d"));
- }
-
- public void testCanProcess_BadMatch() {
- final Switch option = buildDisplaySwitch();
- assertFalse(option.canProcess(new WriteableCommandLineImpl(option,
null), "-dont"));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testPrefixes()
- */
- public void testPrefixes() {
- final Switch option = buildDisplaySwitch();
- assertContentsEqual(list("-", "+"), option.getPrefixes());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testProcess()
- */
- public void testProcess() {
- // TODO Auto-generated method stub
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testTriggers()
- */
- public void testTriggers() {
- final Switch option = buildDisplaySwitch();
- assertContentsEqual(list("-d", "+d", "-disp", "+disp", "+display",
"-display"),
- option.getTriggers());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testValidate()
- */
- public void testValidate() {
- final Parent option = buildDisplaySwitch();
- final WriteableCommandLine commandLine = commandLine(option, list());
-
- try {
- option.validate(commandLine);
- fail("Missing an option");
- } catch (OptionException moe) {
- assertSame(option, moe.getOption());
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testAppendUsage()
- */
- public void testAppendUsage() {
- final Option option = buildDisplaySwitch();
- final StringBuffer buffer = new StringBuffer();
- option.appendUsage(buffer, DisplaySetting.ALL, null);
-
- assertEquals("+display|-display (+d|-d,+disp|-disp)",
buffer.toString());
- }
-
- public void testAppendUsage_NoAlias() {
- final Option option = buildDisplaySwitch();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_ALIASES);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("+display|-display", buffer.toString());
- }
-
- public void testAppendUsage_NoDisabled() {
- final Option option = buildDisplaySwitch();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_SWITCH_DISABLED);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("+display (+d,+disp)", buffer.toString());
- }
-
- public void testAppendUsage_NoEnabled() {
- final Option option = buildDisplaySwitch();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_SWITCH_ENABLED);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("-display (-d,-disp)", buffer.toString());
- }
-
- public void testAppendUsage_NoDisabledOrEnabled() {
- final Option option = buildDisplaySwitch();
- final StringBuffer buffer = new StringBuffer();
- final Set settings = new HashSet(DisplaySetting.ALL);
- settings.remove(DisplaySetting.DISPLAY_SWITCH_DISABLED);
- settings.remove(DisplaySetting.DISPLAY_SWITCH_ENABLED);
- option.appendUsage(buffer, settings, null);
-
- assertEquals("+display (+d,+disp)", buffer.toString());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
- */
- public void testGetPreferredName() {
- final Option option = buildDisplaySwitch();
- assertEquals("+display", option.getPreferredName());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testGetDescription()
- */
- public void testGetDescription() {
- final Option option = buildDisplaySwitch();
- assertEquals("Sets whether to display to screen",
option.getDescription());
- }
-
- public void testNullPreferredName() {
- try {
- new Switch("+", "-", null, null, "Sets whether to display to
screen", true, null, null,
- 'd', null);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT),
- exp.getMessage());
- }
- }
-
- public void testEmptyPreferredName() {
- try {
- new Switch("+", "-", "", null, "Sets whether to display to
screen", true, null, null,
- 'd', null);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT),
- exp.getMessage());
- }
- }
-
- public void testNullAliases() {
- try {
- new Switch("+", "-", "display", null, "Sets whether to display
to screen", true, null,
- null, 'd', null);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT),
- exp.getMessage());
- }
- }
-
- public void testNullEnablePrefix() {
- try {
- new Switch(null, "-", "display", null, "Sets whether to display
to screen", true, null,
- null, 'd', null);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_NO_ENABLED_PREFIX),
- exp.getMessage());
- }
- }
-
- public void testNullDisablePrefix() {
- try {
- new Switch("+", null, "display", null, "Sets whether to display
to screen", true, null,
- null, 'd', null);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_NO_DISABLED_PREFIX),
- exp.getMessage());
- }
- }
-
- public void testEnabledPrefixStartsWithDisabledPrefix() {
- try {
- new Switch("-", "-", "display", null, "Sets whether to display
to screen", true, null,
- null, 'd', null);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_ENABLED_STARTS_WITH_DISABLED),
- exp.getMessage());
- }
- }
-
- public void testDisabledPrefixStartsWithEnabledPrefix() {
- try {
- new Switch("o", "on", "display", null, "Sets whether to display
to screen", true, null,
- null, 'd', null);
- } catch (IllegalArgumentException exp) {
- assertEquals("wrong exception message",
-
ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_DISABLED_STARTWS_WITH_ENABLED),
- exp.getMessage());
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see net.dpml.cli.OptionTestCase#testHelpLines()
- */
- public void testHelpLines() {
- // TODO Auto-generated method stub
- }
-}
+/**
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.option;
+
+import net.dpml.cli.DisplaySetting;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.Parent;
+import net.dpml.cli.WriteableCommandLine;
+import net.dpml.cli.commandline.WriteableCommandLineImpl;
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * @author Rob Oxspring
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class SwitchTest extends AbstractParentTestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Switch buildDisplaySwitch( )
+ {
+ final Set aliases = new HashSet( );
+ aliases.add( "d" );
+ aliases.add( "disp" );
+
+ return new Switch( "+", "-", "display", aliases,
+ "Sets whether to display to screen", true, null, null, 'd', null
);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.ParentTestCase#testProcessParent()
+ */
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessParent( ) throws OptionException
+ {
+ final Switch option = buildDisplaySwitch( );
+ final List args = list( "+d" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.processParent( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "+d" ) );
+ assertTrue( commandLine.hasOption( "-display" ) );
+ assertEquals( Boolean.TRUE, commandLine.getSwitch( "-d" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws OptionException DOCUMENT ME!
+ */
+ public void testProcessParent_Disabled( ) throws OptionException
+ {
+ final Switch option = buildDisplaySwitch( );
+ final List args = list( "-disp" );
+ final WriteableCommandLine commandLine = commandLine( option, args );
+ final ListIterator iterator = args.listIterator( );
+ option.process( commandLine, iterator );
+
+ assertFalse( iterator.hasNext( ) );
+ assertTrue( commandLine.hasOption( option ) );
+ assertTrue( commandLine.hasOption( "+d" ) );
+ assertTrue( commandLine.hasOption( "-display" ) );
+ assertEquals( Boolean.FALSE, commandLine.getSwitch( "-d" ) );
+ assertTrue( commandLine.getValues( option ).isEmpty( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testCanProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess( )
+ {
+ final Switch option = buildDisplaySwitch( );
+ assertTrue( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "+d" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCanProcess_BadMatch( )
+ {
+ final Switch option = buildDisplaySwitch( );
+ assertFalse( option.canProcess(
+ new WriteableCommandLineImpl( option, null ), "-dont" ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testPrefixes()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPrefixes( )
+ {
+ final Switch option = buildDisplaySwitch( );
+ assertContentsEqual( list( "-", "+" ), option.getPrefixes( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testProcess()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testProcess( )
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testTriggers()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testTriggers( )
+ {
+ final Switch option = buildDisplaySwitch( );
+ assertContentsEqual( list( "-d", "+d", "-disp", "+disp", "+display",
+ "-display" ), option.getTriggers( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testValidate()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate( )
+ {
+ final Parent option = buildDisplaySwitch( );
+ final WriteableCommandLine commandLine = commandLine( option, list(
) );
+
+ try
+ {
+ option.validate( commandLine );
+ fail( "Missing an option" );
+ }
+ catch( OptionException moe )
+ {
+ assertSame( option, moe.getOption( ) );
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testAppendUsage()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage( )
+ {
+ final Option option = buildDisplaySwitch( );
+ final StringBuffer buffer = new StringBuffer( );
+ option.appendUsage( buffer, DisplaySetting.ALL, null );
+
+ assertEquals( "+display|-display (+d|-d,+disp|-disp)",
+ buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoAlias( )
+ {
+ final Option option = buildDisplaySwitch( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_ALIASES );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "+display|-display", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoDisabled( )
+ {
+ final Option option = buildDisplaySwitch( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_SWITCH_DISABLED );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "+display (+d,+disp)", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoEnabled( )
+ {
+ final Option option = buildDisplaySwitch( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_SWITCH_ENABLED );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "-display (-d,-disp)", buffer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAppendUsage_NoDisabledOrEnabled( )
+ {
+ final Option option = buildDisplaySwitch( );
+ final StringBuffer buffer = new StringBuffer( );
+ final Set settings = new HashSet( DisplaySetting.ALL );
+ settings.remove( DisplaySetting.DISPLAY_SWITCH_DISABLED );
+ settings.remove( DisplaySetting.DISPLAY_SWITCH_ENABLED );
+ option.appendUsage( buffer, settings, null );
+
+ assertEquals( "+display (+d,+disp)", buffer.toString( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetPreferredName()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetPreferredName( )
+ {
+ final Option option = buildDisplaySwitch( );
+ assertEquals( "+display", option.getPreferredName( ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testGetDescription()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGetDescription( )
+ {
+ final Option option = buildDisplaySwitch( );
+ assertEquals( "Sets whether to display to screen",
+ option.getDescription( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullPreferredName( )
+ {
+ try
+ {
+ new Switch( "+", "-", null, null,
+ "Sets whether to display to screen", true, null, null, 'd',
null );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testEmptyPreferredName( )
+ {
+ try
+ {
+ new Switch( "+", "-", "", null,
+ "Sets whether to display to screen", true, null, null, 'd',
null );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullAliases( )
+ {
+ try
+ {
+ new Switch( "+", "-", "display", null,
+ "Sets whether to display to screen", true, null, null, 'd',
null );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.SWITCH_PREFERRED_NAME_TOO_SHORT ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullEnablePrefix( )
+ {
+ try
+ {
+ new Switch( null, "-", "display", null,
+ "Sets whether to display to screen", true, null, null, 'd',
null );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.SWITCH_NO_ENABLED_PREFIX ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNullDisablePrefix( )
+ {
+ try
+ {
+ new Switch( "+", null, "display", null,
+ "Sets whether to display to screen", true, null, null, 'd',
null );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.SWITCH_NO_DISABLED_PREFIX ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testEnabledPrefixStartsWithDisabledPrefix( )
+ {
+ try
+ {
+ new Switch( "-", "-", "display", null,
+ "Sets whether to display to screen", true, null, null, 'd',
null );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.SWITCH_ENABLED_STARTS_WITH_DISABLED ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testDisabledPrefixStartsWithEnabledPrefix( )
+ {
+ try
+ {
+ new Switch( "o", "on", "display", null,
+ "Sets whether to display to screen", true, null, null, 'd',
null );
+ }
+ catch( IllegalArgumentException exp )
+ {
+ assertEquals( "wrong exception message",
+ ResourceHelper.getResourceHelper( )
+ .getMessage(
ResourceConstants.SWITCH_DISABLED_STARTWS_WITH_ENABLED ),
+ exp.getMessage( ) );
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.dpml.cli.OptionTestCase#testHelpLines()
+ */
+ /**
+ * DOCUMENT ME!
+ */
+ public void testHelpLines( )
+ {
+ // TODO Auto-generated method stub
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/resource/ResourceHelperTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/resource/ResourceHelperTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/resource/ResourceHelperTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -15,67 +15,113 @@
*/
package net.dpml.cli.resource;

+import junit.framework.TestCase;
+
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

-import junit.framework.TestCase;
-
/**
* A utility class used to provide internationalisation support.
*
* @author John Keyes
*/
-public class ResourceHelperTest extends TestCase {
+public class ResourceHelperTest extends TestCase
+{
/** system property */
private static final String PROP_LOCALE = "net.dpml.cli.resource.bundle";
-
private static ResourceHelper helper;

/** resource bundle */
private ResourceBundle bundle;

- public void setUp() {
- System.setProperty(PROP_LOCALE, "net.dpml.cli.resource.TestBundle");
- helper = ResourceHelper.getResourceHelper();
- }
-
- public void tearDown() {
- System.setProperty(PROP_LOCALE,
"net.dpml.cli.resource.CLIMessageBundle_en_US.properties");
- }
-
/**
* Create a new ResourceHelper for the specified class.
*
* @param clazz the Class that requires some resources
*/
- public ResourceHelperTest() {
- super("ResourceHelperTest");
+ public ResourceHelperTest( )
+ {
+ super( "ResourceHelperTest" );
}
-
- public void testOverridden() {
- assertEquals("wrong message", "The class name \"ResourceHelper\" is
invalid.", helper.getMessage("ClassValidator.bad.classname",
"ResourceHelper"));
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void setUp( )
+ {
+ System.setProperty( PROP_LOCALE, "net.dpml.cli.resource.TestBundle"
);
+ helper = ResourceHelper.getResourceHelper( );
}
-
- public void testNewMessage1Param() {
- assertEquals("wrong message", "Some might say we will find a brighter
day.", helper.getMessage("test.message"));
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void tearDown( )
+ {
+ System.setProperty( PROP_LOCALE,
+ "net.dpml.cli.resource.CLIMessageBundle_en_US.properties" );
}

- public void testNewMessage2Params() {
- assertEquals("wrong message", "Some might say we will find a brighter
day.", helper.getMessage("test.message", "Some"));
+ /**
+ * DOCUMENT ME!
+ */
+ public void testOverridden( )
+ {
+ assertEquals( "wrong message",
+ "The class name \"ResourceHelper\" is invalid.",
+ helper.getMessage( "ClassValidator.bad.classname",
"ResourceHelper" ) );
}

- public void testNewMessage3Params() {
- assertEquals("wrong message", "Some might say we will find a brighter
day.", helper.getMessage("test.message", "Some", "might"));
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNewMessage1Param( )
+ {
+ assertEquals( "wrong message",
+ "Some might say we will find a brighter day.",
+ helper.getMessage( "test.message" ) );
}

- public void testNewMessage4Params() {
- assertEquals("wrong message", "Some might say we will find a brighter
day.", helper.getMessage("test.message", "Some", "might", "say"));
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNewMessage2Params( )
+ {
+ assertEquals( "wrong message",
+ "Some might say we will find a brighter day.",
+ helper.getMessage( "test.message", "Some" ) );
}

- public void testDefaultBundle() {
- System.setProperty(PROP_LOCALE, "madeupname.properties");
- helper = ResourceHelper.getResourceHelper();
- assertEquals("wrong message", "The class name \"ResourceHelper\" is
invalid.", helper.getMessage("ClassValidator.bad.classname",
"ResourceHelper"));
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNewMessage3Params( )
+ {
+ assertEquals( "wrong message",
+ "Some might say we will find a brighter day.",
+ helper.getMessage( "test.message", "Some", "might" ) );
}
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNewMessage4Params( )
+ {
+ assertEquals( "wrong message",
+ "Some might say we will find a brighter day.",
+ helper.getMessage( "test.message", "Some", "might", "say" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testDefaultBundle( )
+ {
+ System.setProperty( PROP_LOCALE, "madeupname.properties" );
+ helper = ResourceHelper.getResourceHelper( );
+ assertEquals( "wrong message",
+ "The class name \"ResourceHelper\" is invalid.",
+ helper.getMessage( "ClassValidator.bad.classname",
"ResourceHelper" ) );
+ }
}

Modified: trunk/main/util/cli/src/test/net/dpml/cli/util/ComparatorsTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/util/ComparatorsTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/util/ComparatorsTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,220 +1,265 @@
-/**
- * Copyright 2003-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 net.dpml.cli.util;
-
-import java.util.Collections;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.AbstractCLITestCase;
-import net.dpml.cli.Option;
-import net.dpml.cli.option.CommandTest;
-import net.dpml.cli.option.DefaultOptionTest;
-import net.dpml.cli.option.GroupTest;
-import net.dpml.cli.option.ParentTest;
-import net.dpml.cli.option.SwitchTest;
-
-/**
- * @author Rob Oxspring
- */
-public class ComparatorsTest extends AbstractCLITestCase {
- public void testGroupFirst() {
- final Option o1 = GroupTest.buildAntGroup();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.groupFirst());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o1, o2),
- list);
- }
-
- public void testGroupLast() {
- final Option o1 = GroupTest.buildAntGroup();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.groupLast());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o2, o1),
- list);
- }
-
- public void testSwitchFirst() {
- final Option o1 = SwitchTest.buildDisplaySwitch();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.switchFirst());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o1, o2),
- list);
- }
-
- public void testSwitchLast() {
- final Option o1 = SwitchTest.buildDisplaySwitch();
- final Option o2 = ParentTest.buildLibParent();
- //final Option o3 = new SwitchBuilder().withName("hidden").create();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.switchLast());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o2, o1),
- list);
- }
-
- public void testCommandFirst() {
- final Option o1 = CommandTest.buildCommitCommand();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.commandFirst());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o1, o2),
- list);
- }
-
- public void testCommandLast() {
- final Option o1 = CommandTest.buildCommitCommand();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.commandLast());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o2, o1),
- list);
- }
-
- public void testDefaultOptionFirst() {
- final Option o1 = DefaultOptionTest.buildHelpOption();
- final Option o2 = CommandTest.buildCommitCommand();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.defaultOptionFirst());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o1, o2),
- list);
- }
-
- public void testDefaultOptionLast() {
- final Option o1 = DefaultOptionTest.buildHelpOption();
- final Option o2 = CommandTest.buildCommitCommand();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.defaultOptionLast());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o2, o1),
- list);
- }
-
- public void testNamedFirst() {
- final Option o1 = DefaultOptionTest.buildHelpOption();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.namedFirst("--help"));
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o1, o2),
- list);
- }
-
- public void testNamedLast() {
- final Option o1 = DefaultOptionTest.buildHelpOption();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.namedLast("--help"));
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o2, o1),
- list);
- }
-
- public void testPreferredNameFirst() {
- final Option o1 = DefaultOptionTest.buildHelpOption();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.preferredNameFirst());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o1, o2),
- list);
- }
-
- public void testPreferredNameLast() {
- final Option o1 = DefaultOptionTest.buildHelpOption();
- final Option o2 = ParentTest.buildLibParent();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.preferredNameLast());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o2, o1),
- list);
- }
-
- public void testRequiredFirst() {
- final Option o1 = DefaultOptionTest.buildHelpOption();
- final Option o2 = DefaultOptionTest.buildXOption();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.requiredFirst());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o2, o1),
- list);
- }
-
- public void testRequiredLast() {
- final Option o1 = DefaultOptionTest.buildHelpOption();
- final Option o2 = DefaultOptionTest.buildXOption();
- final List list = AbstractCLITestCase.list(o1, o2);
-
- Collections.sort(list, Comparators.requiredLast());
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o1, o2),
- list);
- }
-
- public void testChained() {
- final Option o1 = CommandTest.buildCommitCommand();
- final Option o2 = SwitchTest.buildDisplaySwitch();
- final Option o3 = DefaultOptionTest.buildHelpOption();
- final List list = AbstractCLITestCase.list(o1, o2, o3);
-
- Collections.sort(
- list,
- Comparators.chain(
- Comparators.namedFirst("--help"),
- Comparators.commandFirst()));
-
- AbstractCLITestCase.assertListContentsEqual(
- AbstractCLITestCase.list(o3, o1, o2),
- list);
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.util;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.AbstractCLITestCase;
+import net.dpml.cli.Option;
+import net.dpml.cli.option.CommandTest;
+import net.dpml.cli.option.DefaultOptionTest;
+import net.dpml.cli.option.GroupTest;
+import net.dpml.cli.option.ParentTest;
+import net.dpml.cli.option.SwitchTest;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Rob Oxspring
+ */
+public class ComparatorsTest extends AbstractCLITestCase
+{
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGroupFirst( )
+ {
+ final Option o1 = GroupTest.buildAntGroup( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.groupFirst( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o1, o2 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testGroupLast( )
+ {
+ final Option o1 = GroupTest.buildAntGroup( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.groupLast( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o2, o1 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitchFirst( )
+ {
+ final Option o1 = SwitchTest.buildDisplaySwitch( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.switchFirst( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o1, o2 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testSwitchLast( )
+ {
+ final Option o1 = SwitchTest.buildDisplaySwitch( );
+ final Option o2 = ParentTest.buildLibParent( );
+
+ //final Option o3 = new SwitchBuilder().withName("hidden").create();
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.switchLast( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o2, o1 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCommandFirst( )
+ {
+ final Option o1 = CommandTest.buildCommitCommand( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.commandFirst( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o1, o2 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCommandLast( )
+ {
+ final Option o1 = CommandTest.buildCommitCommand( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.commandLast( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o2, o1 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testDefaultOptionFirst( )
+ {
+ final Option o1 = DefaultOptionTest.buildHelpOption( );
+ final Option o2 = CommandTest.buildCommitCommand( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.defaultOptionFirst( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o1, o2 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testDefaultOptionLast( )
+ {
+ final Option o1 = DefaultOptionTest.buildHelpOption( );
+ final Option o2 = CommandTest.buildCommitCommand( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.defaultOptionLast( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o2, o1 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNamedFirst( )
+ {
+ final Option o1 = DefaultOptionTest.buildHelpOption( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.namedFirst( "--help" ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o1, o2 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNamedLast( )
+ {
+ final Option o1 = DefaultOptionTest.buildHelpOption( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.namedLast( "--help" ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o2, o1 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPreferredNameFirst( )
+ {
+ final Option o1 = DefaultOptionTest.buildHelpOption( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.preferredNameFirst( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o1, o2 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testPreferredNameLast( )
+ {
+ final Option o1 = DefaultOptionTest.buildHelpOption( );
+ final Option o2 = ParentTest.buildLibParent( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.preferredNameLast( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o2, o1 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testRequiredFirst( )
+ {
+ final Option o1 = DefaultOptionTest.buildHelpOption( );
+ final Option o2 = DefaultOptionTest.buildXOption( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.requiredFirst( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o2, o1 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testRequiredLast( )
+ {
+ final Option o1 = DefaultOptionTest.buildHelpOption( );
+ final Option o2 = DefaultOptionTest.buildXOption( );
+ final List list = AbstractCLITestCase.list( o1, o2 );
+
+ Collections.sort( list, Comparators.requiredLast( ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o1, o2 ), list );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testChained( )
+ {
+ final Option o1 = CommandTest.buildCommitCommand( );
+ final Option o2 = SwitchTest.buildDisplaySwitch( );
+ final Option o3 = DefaultOptionTest.buildHelpOption( );
+ final List list = AbstractCLITestCase.list( o1, o2, o3 );
+
+ Collections.sort( list,
+ Comparators.chain( Comparators.namedFirst( "--help" ),
+ Comparators.commandFirst( ) ) );
+
+ AbstractCLITestCase.assertListContentsEqual(
AbstractCLITestCase.list(
+ o3, o1, o2 ), list );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/util/HelpFormatterTest.java
===================================================================
--- trunk/main/util/cli/src/test/net/dpml/cli/util/HelpFormatterTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++ trunk/main/util/cli/src/test/net/dpml/cli/util/HelpFormatterTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,542 +1,705 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.util;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.DisplaySetting;
-import net.dpml.cli.Group;
-import net.dpml.cli.Option;
-import net.dpml.cli.OptionException;
-import net.dpml.cli.builder.DefaultOptionBuilder;
-import net.dpml.cli.builder.GroupBuilder;
-import net.dpml.cli.option.ArgumentTest;
-import net.dpml.cli.option.DefaultOptionTest;
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-public class HelpFormatterTest
- extends TestCase {
- private ResourceHelper resources = ResourceHelper.getResourceHelper();
- private HelpFormatter helpFormatter;
- private Option verbose;
- private Group options;
-
- public void setUp() {
- helpFormatter = new HelpFormatter("|*", "*-*", "*|", 80 );
-
helpFormatter.setDivider("+------------------------------------------------------------------------------+");
- helpFormatter.setHeader("Jakarta Commons CLI");
- helpFormatter.setFooter("Copyright 2003\nApache Software
Foundation");
- helpFormatter.setShellCommand("ant");
-
- verbose =
- new DefaultOptionBuilder().withLongName("verbose")
- .withDescription("print the version
information and exit")
- .create();
-
- options =
- new
GroupBuilder().withName("options").withOption(DefaultOptionTest.buildHelpOption())
-
.withOption(ArgumentTest.buildTargetsArgument())
- .withOption(new
DefaultOptionBuilder().withLongName("diagnostics")
-
.withDescription("print information that might be helpful to diagnose or
report problems.")
-
.create())
- .withOption(new
DefaultOptionBuilder().withLongName("projecthelp")
-
.withDescription("print project help information")
-
.create()).withOption(verbose)
- .create();
-
- helpFormatter.setGroup(options);
- }
-
- public void testPrint()
- throws IOException {
- final StringWriter writer = new StringWriter();
- final PrintWriter pw = new PrintWriter(writer);
- helpFormatter.setPrintWriter(pw);
- helpFormatter.print();
-
- // test shell
- assertEquals("incorrect shell command", "ant",
helpFormatter.getShellCommand());
-
- // test group
- assertEquals("incorrect group", this.options,
helpFormatter.getGroup());
-
- // test pagewidth
- assertEquals("incorrect page width", 76,
helpFormatter.getPageWidth());
-
- // test pw
- assertEquals("incorrect print writer", pw,
helpFormatter.getPrintWriter());
-
- // test divider
- assertEquals("incorrect divider",
-
"+------------------------------------------------------------------------------+",
- helpFormatter.getDivider());
-
- // test header
- assertEquals("incorrect header", "Jakarta Commons CLI",
helpFormatter.getHeader());
-
- // test footer
- assertEquals("incorrect footer", "Copyright 2003\nApache Software
Foundation",
- helpFormatter.getFooter());
-
- // test gutters
- assertEquals("incorrect left gutter", "|*",
helpFormatter.getGutterLeft());
- assertEquals("incorrect right gutter", "*|",
helpFormatter.getGutterRight());
- assertEquals("incorrect center gutter", "*-*",
helpFormatter.getGutterCenter());
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Jakarta Commons CLI
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Usage:
*|",
- reader.readLine());
- assertEquals("|*ant [--help --diagnostics --projecthelp --verbose]
[<target1> [<target2> *|",
- reader.readLine());
- assertEquals("|*...]]
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*options *-*
*|",
- reader.readLine());
- assertEquals("|* --help (-?,-h) *-*Displays the help
*|",
- reader.readLine());
- assertEquals("|* --diagnostics *-*print information that might
be helpful to diagnose *|",
- reader.readLine());
- assertEquals("|* *-*or report problems.
*|",
- reader.readLine());
- assertEquals("|* --projecthelp *-*print project help
information *|",
- reader.readLine());
- assertEquals("|* --verbose *-*print the version
information and exit *|",
- reader.readLine());
- assertEquals("|* target [target ...]*-*The targets ant should build
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Copyright 2003
*|",
- reader.readLine());
- assertEquals("|*Apache Software Foundation
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testComparator()
- throws IOException {
- final StringWriter writer = new StringWriter();
- final PrintWriter pw = new PrintWriter(writer);
- helpFormatter.setPrintWriter(pw);
-
- final Comparator comparator = new OptionComparator();
- helpFormatter.setComparator(comparator);
- helpFormatter.print();
-
- // test comparator
- assertEquals("invalid comparator", comparator,
helpFormatter.getComparator());
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Jakarta Commons CLI
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Usage:
*|",
- reader.readLine());
- assertEquals("|*ant [--verbose --projecthelp --help --diagnostics]
[<target1> [<target2> *|",
- reader.readLine());
- assertEquals("|*...]]
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*options *-*
*|",
- reader.readLine());
- assertEquals("|* --verbose *-*print the version
information and exit *|",
- reader.readLine());
- assertEquals("|* --projecthelp *-*print project help
information *|",
- reader.readLine());
- assertEquals("|* --help (-?,-h) *-*Displays the help
*|",
- reader.readLine());
- assertEquals("|* --diagnostics *-*print information that might
be helpful to diagnose *|",
- reader.readLine());
- assertEquals("|* *-*or report problems.
*|",
- reader.readLine());
- assertEquals("|* target [target ...]*-*The targets ant should build
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Copyright 2003
*|",
- reader.readLine());
- assertEquals("|*Apache Software Foundation
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testPrintHelp()
- throws IOException {
- final StringWriter writer = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.printHelp();
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*options *-*
*|",
- reader.readLine());
- assertEquals("|* --help (-?,-h) *-*Displays the help
*|",
- reader.readLine());
- assertEquals("|* --diagnostics *-*print information that might
be helpful to diagnose *|",
- reader.readLine());
- assertEquals("|* *-*or report problems.
*|",
- reader.readLine());
- assertEquals("|* --projecthelp *-*print project help
information *|",
- reader.readLine());
- assertEquals("|* --verbose *-*print the version
information and exit *|",
- reader.readLine());
- assertEquals("|* target [target ...]*-*The targets ant should build
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testPrintHelp_WithException()
- throws IOException {
- final StringWriter writer = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.setException(new OptionException(verbose));
- helpFormatter.printHelp();
-
- //System.out.println(writer);
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*--verbose*-*print the version information and exit
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testPrintHelp_TooNarrow()
- throws IOException {
- final StringWriter writer = new StringWriter();
- helpFormatter = new HelpFormatter("<", "=", ">", 4);
- helpFormatter.setGroup(options);
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.printHelp();
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
- assertEquals("<options = >", reader.readLine());
- assertEquals("< --help (-?,-h) =D>", reader.readLine());
- assertEquals("< =i>", reader.readLine());
-
- // lots more lines unchecked
- }
-
- public void testPrintException()
- throws IOException {
- final StringWriter writer = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.setException(new OptionException(verbose,
ResourceConstants.MISSING_OPTION));
- helpFormatter.printException();
-
- //System.out.println(writer);
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Missing option --verbose
*|",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testPrintUsage()
- throws IOException {
- final StringWriter writer = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.printUsage();
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Usage:
*|",
- reader.readLine());
- assertEquals("|*ant [--help --diagnostics --projecthelp --verbose]
[<target1> [<target2> *|",
- reader.readLine());
- assertEquals("|*...]]
*|",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testPrintHeader()
- throws IOException {
- final StringWriter writer = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.printHeader();
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertEquals("|*Jakarta Commons CLI
*|",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testPrintFooter()
- throws IOException {
- final StringWriter writer = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.printFooter();
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
- assertEquals("|*Copyright 2003
*|",
- reader.readLine());
- assertEquals("|*Apache Software Foundation
*|",
- reader.readLine());
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testPrintDivider()
- throws IOException {
- final StringWriter writer = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.printDivider();
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
-
assertEquals("+------------------------------------------------------------------------------+",
- reader.readLine());
- assertNull(reader.readLine());
- }
-
- public void testWrap() {
- final Iterator i = HelpFormatter.wrap("Apache Software Foundation",
30).iterator();
- assertEquals("Apache Software Foundation", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testWrap_WrapNeeded() {
- final Iterator i = HelpFormatter.wrap("Apache Software Foundation",
20).iterator();
- assertEquals("Apache Software", i.next());
- assertEquals("Foundation", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testWrap_BeforeSpace() {
- final Iterator i = HelpFormatter.wrap("Apache Software Foundation",
16).iterator();
- assertEquals("Apache Software", i.next());
- assertEquals("Foundation", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testWrap_AfterSpace() {
- final Iterator i = HelpFormatter.wrap("Apache Software Foundation",
17).iterator();
- assertEquals("Apache Software", i.next());
- assertEquals("Foundation", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testWrap_InWord() {
- final Iterator i = HelpFormatter.wrap("Apache Software Foundation",
8).iterator();
- assertEquals("Apache", i.next());
- assertEquals("Software", i.next());
- assertEquals("Foundati", i.next());
- assertEquals("on", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testWrap_NewLine() {
- final Iterator i = HelpFormatter.wrap("\nApache Software
Foundation\n", 30).iterator();
- assertEquals("", i.next());
- assertEquals("Apache Software Foundation", i.next());
- assertEquals("", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testWrap_NewLine2() {
- List wrapped =
- HelpFormatter.wrap("A really quite long general description of
the option with specific alternatives documented:\n" +
- " Indented special case\n" + " Alternative
scenario", 30);
-
- final Iterator i = wrapped.iterator();
-
- assertEquals("A really quite long general", i.next());
- assertEquals("description of the option", i.next());
- assertEquals("with specific alternatives", i.next());
- assertEquals("documented:", i.next());
- assertEquals(" Indented special case", i.next());
- assertEquals(" Alternative scenario", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testWrap_Below1Length() {
- try {
- HelpFormatter.wrap("Apache Software Foundation", -1);
- fail("IllegalArgumentException");
- } catch (IllegalArgumentException e) {
-
assertEquals(resources.getMessage(ResourceConstants.HELPFORMATTER_WIDTH_TOO_NARROW,
- new Object[] { new Integer(-1)
}), e.getMessage());
- }
- }
-
- public void testPad()
- throws IOException {
- final StringWriter writer = new StringWriter();
- HelpFormatter.pad("hello", 10, writer);
- assertEquals("hello ", writer.toString());
- }
-
- public void testPad_Null()
- throws IOException {
- final StringWriter writer = new StringWriter();
- HelpFormatter.pad(null, 10, writer);
- assertEquals(" ", writer.toString());
- }
-
- public void testPad_TooLong()
- throws IOException {
- final StringWriter writer = new StringWriter();
- HelpFormatter.pad("hello world", 10, writer);
- assertEquals("hello world", writer.toString());
- }
-
- public void testPad_TooShort()
- throws IOException {
- final StringWriter writer = new StringWriter();
- HelpFormatter.pad("hello world", -5, writer);
- assertEquals("hello world", writer.toString());
- }
-
- public void testGutters()
- throws IOException {
- helpFormatter = new HelpFormatter(null, null, null, 80);
- helpFormatter.setShellCommand("ant");
-
- final Set lusage = new HashSet();
- lusage.add(DisplaySetting.DISPLAY_ALIASES);
- lusage.add(DisplaySetting.DISPLAY_GROUP_NAME);
- helpFormatter.setLineUsageSettings(lusage);
-
- // test line usage
- assertEquals("incorrect line usage", lusage,
helpFormatter.getLineUsageSettings());
-
- final Set fusage = new HashSet();
- fusage.add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
- fusage.add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
- fusage.add(DisplaySetting.DISPLAY_GROUP_OUTER);
- fusage.add(DisplaySetting.DISPLAY_GROUP_EXPANDED);
- fusage.add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
- fusage.add(DisplaySetting.DISPLAY_ARGUMENT_NUMBERED);
- fusage.add(DisplaySetting.DISPLAY_SWITCH_ENABLED);
- fusage.add(DisplaySetting.DISPLAY_SWITCH_DISABLED);
- fusage.add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
- fusage.add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
- fusage.add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
- fusage.add(DisplaySetting.DISPLAY_OPTIONAL);
- helpFormatter.setFullUsageSettings(fusage);
-
- // test line usage
- assertEquals("incorrect full usage", fusage,
helpFormatter.getFullUsageSettings());
-
- final Set dsettings = new HashSet();
- dsettings.add(DisplaySetting.DISPLAY_GROUP_NAME);
- dsettings.add(DisplaySetting.DISPLAY_GROUP_EXPANDED);
- dsettings.add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
-
- helpFormatter.setDisplaySettings(dsettings);
-
- verbose =
- new DefaultOptionBuilder().withLongName("verbose")
- .withDescription("print the version
information and exit")
- .create();
-
- options =
- new
GroupBuilder().withName("options").withOption(DefaultOptionTest.buildHelpOption())
-
.withOption(ArgumentTest.buildTargetsArgument())
- .withOption(new
DefaultOptionBuilder().withLongName("diagnostics")
-
.withDescription("print information that might be helpful to diagnose or
report problems.")
-
.create())
- .withOption(new
DefaultOptionBuilder().withLongName("projecthelp")
-
.withDescription("print project help information")
-
.create()).withOption(verbose)
- .create();
-
- helpFormatter.setGroup(options);
-
- // test default gutters
- assertEquals("incorrect left gutter",
HelpFormatter.DEFAULT_GUTTER_LEFT,
- helpFormatter.getGutterLeft());
- assertEquals("incorrect right gutter",
HelpFormatter.DEFAULT_GUTTER_RIGHT,
- helpFormatter.getGutterRight());
- assertEquals("incorrect center gutter",
HelpFormatter.DEFAULT_GUTTER_CENTER,
- helpFormatter.getGutterCenter());
-
- final StringWriter writer = new StringWriter();
- helpFormatter.setPrintWriter(new PrintWriter(writer));
- helpFormatter.print();
-
- final BufferedReader reader = new BufferedReader(new
StringReader(writer.toString()));
- assertEquals("Usage:
",
- reader.readLine());
- assertEquals("ant [--help --diagnostics --projecthelp --verbose]
[<target1> [<target2> ...]] ",
- reader.readLine());
- assertEquals("options
",
- reader.readLine());
- assertEquals(" --help (-?,-h) Displays the help
",
- reader.readLine());
- assertEquals(" --diagnostics print information that might
be helpful to diagnose or ",
- reader.readLine());
- assertEquals(" report problems.
",
- reader.readLine());
- assertEquals(" --projecthelp print project help
information ",
- reader.readLine());
- assertEquals(" --verbose print the version information
and exit ",
- reader.readLine());
- assertEquals(" target [target ...] The targets ant should build
",
- reader.readLine());
- assertNull(reader.readLine());
- }
-}
-
-
-class OptionComparator implements Comparator {
- public int compare(Object o1,
- Object o2) {
- Option opt1 = (Option) o1;
- Option opt2 = (Option) o2;
-
- return -opt1.getPreferredName().compareTo(opt2.getPreferredName());
- }
-}
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.util;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.DisplaySetting;
+import net.dpml.cli.Group;
+import net.dpml.cli.Option;
+import net.dpml.cli.OptionException;
+import net.dpml.cli.builder.DefaultOptionBuilder;
+import net.dpml.cli.builder.GroupBuilder;
+import net.dpml.cli.option.ArgumentTest;
+import net.dpml.cli.option.DefaultOptionTest;
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class HelpFormatterTest extends TestCase
+{
+ private ResourceHelper resources = ResourceHelper.getResourceHelper( );
+ private HelpFormatter helpFormatter;
+ private Option verbose;
+ private Group options;
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void setUp( )
+ {
+ helpFormatter = new HelpFormatter( "|*", "*-*", "*|", 80 );
+ helpFormatter.setDivider(
+
"+------------------------------------------------------------------------------+"
);
+ helpFormatter.setHeader( "Jakarta Commons CLI" );
+ helpFormatter.setFooter( "Copyright 2003\nApache Software
Foundation" );
+ helpFormatter.setShellCommand( "ant" );
+
+ verbose = new DefaultOptionBuilder( ).withLongName( "verbose" )
+ .withDescription( "print the
version information and exit" )
+ .create( );
+
+ options = new GroupBuilder( ).withName( "options" )
+ .withOption(
DefaultOptionTest.buildHelpOption( ) )
+ .withOption(
ArgumentTest.buildTargetsArgument( ) )
+ .withOption( new DefaultOptionBuilder(
).withLongName(
+ "diagnostics" )
+
.withDescription( "print information that might be helpful to diagnose or
report problems." )
+
.create( ) )
+ .withOption( new DefaultOptionBuilder(
).withLongName(
+ "projecthelp" )
+
.withDescription( "print project help information" )
+
.create( ) )
+ .withOption( verbose ).create( );
+
+ helpFormatter.setGroup( options );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrint( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ final PrintWriter pw = new PrintWriter( writer );
+ helpFormatter.setPrintWriter( pw );
+ helpFormatter.print( );
+
+ // test shell
+ assertEquals( "incorrect shell command", "ant",
+ helpFormatter.getShellCommand( ) );
+
+ // test group
+ assertEquals( "incorrect group", this.options,
+ helpFormatter.getGroup( ) );
+
+ // test pagewidth
+ assertEquals( "incorrect page width", 76,
helpFormatter.getPageWidth( ) );
+
+ // test pw
+ assertEquals( "incorrect print writer", pw,
+ helpFormatter.getPrintWriter( ) );
+
+ // test divider
+ assertEquals( "incorrect divider",
+
"+------------------------------------------------------------------------------+",
+ helpFormatter.getDivider( ) );
+
+ // test header
+ assertEquals( "incorrect header", "Jakarta Commons CLI",
+ helpFormatter.getHeader( ) );
+
+ // test footer
+ assertEquals( "incorrect footer",
+ "Copyright 2003\nApache Software Foundation",
+ helpFormatter.getFooter( ) );
+
+ // test gutters
+ assertEquals( "incorrect left gutter", "|*",
+ helpFormatter.getGutterLeft( ) );
+ assertEquals( "incorrect right gutter", "*|",
+ helpFormatter.getGutterRight( ) );
+ assertEquals( "incorrect center gutter", "*-*",
+ helpFormatter.getGutterCenter( ) );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Jakarta Commons CLI
*|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Usage:
*|",
+ reader.readLine( ) );
+ assertEquals( "|*ant [--help --diagnostics --projecthelp --verbose]
[<target1> [<target2> *|",
+ reader.readLine( ) );
+ assertEquals( "|*...]]
*|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*options *-*
*|",
+ reader.readLine( ) );
+ assertEquals( "|* --help (-?,-h) *-*Displays the help
*|",
+ reader.readLine( ) );
+ assertEquals( "|* --diagnostics *-*print information that
might be helpful to diagnose *|",
+ reader.readLine( ) );
+ assertEquals( "|* *-*or report problems.
*|",
+ reader.readLine( ) );
+ assertEquals( "|* --projecthelp *-*print project help
information *|",
+ reader.readLine( ) );
+ assertEquals( "|* --verbose *-*print the version
information and exit *|",
+ reader.readLine( ) );
+ assertEquals( "|* target [target ...]*-*The targets ant should
build *|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Copyright 2003
*|",
+ reader.readLine( ) );
+ assertEquals( "|*Apache Software Foundation
*|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testComparator( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ final PrintWriter pw = new PrintWriter( writer );
+ helpFormatter.setPrintWriter( pw );
+
+ final Comparator comparator = new OptionComparator( );
+ helpFormatter.setComparator( comparator );
+ helpFormatter.print( );
+
+ // test comparator
+ assertEquals( "invalid comparator", comparator,
+ helpFormatter.getComparator( ) );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Jakarta Commons CLI
*|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Usage:
*|",
+ reader.readLine( ) );
+ assertEquals( "|*ant [--verbose --projecthelp --help --diagnostics]
[<target1> [<target2> *|",
+ reader.readLine( ) );
+ assertEquals( "|*...]]
*|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*options *-*
*|",
+ reader.readLine( ) );
+ assertEquals( "|* --verbose *-*print the version
information and exit *|",
+ reader.readLine( ) );
+ assertEquals( "|* --projecthelp *-*print project help
information *|",
+ reader.readLine( ) );
+ assertEquals( "|* --help (-?,-h) *-*Displays the help
*|",
+ reader.readLine( ) );
+ assertEquals( "|* --diagnostics *-*print information that
might be helpful to diagnose *|",
+ reader.readLine( ) );
+ assertEquals( "|* *-*or report problems.
*|",
+ reader.readLine( ) );
+ assertEquals( "|* target [target ...]*-*The targets ant should
build *|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Copyright 2003
*|",
+ reader.readLine( ) );
+ assertEquals( "|*Apache Software Foundation
*|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrintHelp( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.printHelp( );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*options *-*
*|",
+ reader.readLine( ) );
+ assertEquals( "|* --help (-?,-h) *-*Displays the help
*|",
+ reader.readLine( ) );
+ assertEquals( "|* --diagnostics *-*print information that
might be helpful to diagnose *|",
+ reader.readLine( ) );
+ assertEquals( "|* *-*or report problems.
*|",
+ reader.readLine( ) );
+ assertEquals( "|* --projecthelp *-*print project help
information *|",
+ reader.readLine( ) );
+ assertEquals( "|* --verbose *-*print the version
information and exit *|",
+ reader.readLine( ) );
+ assertEquals( "|* target [target ...]*-*The targets ant should
build *|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrintHelp_WithException( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.setException( new OptionException( verbose ) );
+ helpFormatter.printHelp( );
+
+ //System.out.println(writer);
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*--verbose*-*print the version information and exit
*|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrintHelp_TooNarrow( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ helpFormatter = new HelpFormatter( "<", "=", ">", 4 );
+ helpFormatter.setGroup( options );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.printHelp( );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals( "<options = >", reader.readLine( ) );
+ assertEquals( "< --help (-?,-h) =D>", reader.readLine( ) );
+ assertEquals( "< =i>", reader.readLine( ) );
+
+ // lots more lines unchecked
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrintException( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.setException( new OptionException( verbose,
+ ResourceConstants.MISSING_OPTION ) );
+ helpFormatter.printException( );
+
+ //System.out.println(writer);
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Missing option --verbose
*|",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrintUsage( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.printUsage( );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Usage:
*|",
+ reader.readLine( ) );
+ assertEquals( "|*ant [--help --diagnostics --projecthelp --verbose]
[<target1> [<target2> *|",
+ reader.readLine( ) );
+ assertEquals( "|*...]]
*|",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrintHeader( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.printHeader( );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertEquals( "|*Jakarta Commons CLI
*|",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrintFooter( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.printFooter( );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals( "|*Copyright 2003
*|",
+ reader.readLine( ) );
+ assertEquals( "|*Apache Software Foundation
*|",
+ reader.readLine( ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPrintDivider( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.printDivider( );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals(
"+------------------------------------------------------------------------------+",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWrap( )
+ {
+ final Iterator i = HelpFormatter.wrap( "Apache Software Foundation",
30 )
+ .iterator( );
+ assertEquals( "Apache Software Foundation", i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWrap_WrapNeeded( )
+ {
+ final Iterator i = HelpFormatter.wrap( "Apache Software Foundation",
20 )
+ .iterator( );
+ assertEquals( "Apache Software", i.next( ) );
+ assertEquals( "Foundation", i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWrap_BeforeSpace( )
+ {
+ final Iterator i = HelpFormatter.wrap( "Apache Software Foundation",
16 )
+ .iterator( );
+ assertEquals( "Apache Software", i.next( ) );
+ assertEquals( "Foundation", i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWrap_AfterSpace( )
+ {
+ final Iterator i = HelpFormatter.wrap( "Apache Software Foundation",
17 )
+ .iterator( );
+ assertEquals( "Apache Software", i.next( ) );
+ assertEquals( "Foundation", i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWrap_InWord( )
+ {
+ final Iterator i = HelpFormatter.wrap( "Apache Software Foundation",
8 )
+ .iterator( );
+ assertEquals( "Apache", i.next( ) );
+ assertEquals( "Software", i.next( ) );
+ assertEquals( "Foundati", i.next( ) );
+ assertEquals( "on", i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWrap_NewLine( )
+ {
+ final Iterator i = HelpFormatter.wrap( "\nApache Software
Foundation\n",
+ 30 ).iterator( );
+ assertEquals( "", i.next( ) );
+ assertEquals( "Apache Software Foundation", i.next( ) );
+ assertEquals( "", i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWrap_NewLine2( )
+ {
+ List wrapped = HelpFormatter.wrap(
+ "A really quite long general description of the option with
specific alternatives documented:\n" +
+ " Indented special case\n" + " Alternative scenario", 30 );
+
+ final Iterator i = wrapped.iterator( );
+
+ assertEquals( "A really quite long general", i.next( ) );
+ assertEquals( "description of the option", i.next( ) );
+ assertEquals( "with specific alternatives", i.next( ) );
+ assertEquals( "documented:", i.next( ) );
+ assertEquals( " Indented special case", i.next( ) );
+ assertEquals( " Alternative scenario", i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testWrap_Below1Length( )
+ {
+ try
+ {
+ HelpFormatter.wrap( "Apache Software Foundation", -1 );
+ fail( "IllegalArgumentException" );
+ }
+ catch( IllegalArgumentException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.HELPFORMATTER_WIDTH_TOO_NARROW,
+ new Object[]{new Integer( -1 )} ), e.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPad( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ HelpFormatter.pad( "hello", 10, writer );
+ assertEquals( "hello ", writer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPad_Null( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ HelpFormatter.pad( null, 10, writer );
+ assertEquals( " ", writer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPad_TooLong( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ HelpFormatter.pad( "hello world", 10, writer );
+ assertEquals( "hello world", writer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testPad_TooShort( ) throws IOException
+ {
+ final StringWriter writer = new StringWriter( );
+ HelpFormatter.pad( "hello world", -5, writer );
+ assertEquals( "hello world", writer.toString( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws IOException DOCUMENT ME!
+ */
+ public void testGutters( ) throws IOException
+ {
+ helpFormatter = new HelpFormatter( null, null, null, 80 );
+ helpFormatter.setShellCommand( "ant" );
+
+ final Set lusage = new HashSet( );
+ lusage.add( DisplaySetting.DISPLAY_ALIASES );
+ lusage.add( DisplaySetting.DISPLAY_GROUP_NAME );
+ helpFormatter.setLineUsageSettings( lusage );
+
+ // test line usage
+ assertEquals( "incorrect line usage", lusage,
+ helpFormatter.getLineUsageSettings( ) );
+
+ final Set fusage = new HashSet( );
+ fusage.add( DisplaySetting.DISPLAY_PARENT_CHILDREN );
+ fusage.add( DisplaySetting.DISPLAY_GROUP_ARGUMENT );
+ fusage.add( DisplaySetting.DISPLAY_GROUP_OUTER );
+ fusage.add( DisplaySetting.DISPLAY_GROUP_EXPANDED );
+ fusage.add( DisplaySetting.DISPLAY_ARGUMENT_BRACKETED );
+ fusage.add( DisplaySetting.DISPLAY_ARGUMENT_NUMBERED );
+ fusage.add( DisplaySetting.DISPLAY_SWITCH_ENABLED );
+ fusage.add( DisplaySetting.DISPLAY_SWITCH_DISABLED );
+ fusage.add( DisplaySetting.DISPLAY_PROPERTY_OPTION );
+ fusage.add( DisplaySetting.DISPLAY_PARENT_CHILDREN );
+ fusage.add( DisplaySetting.DISPLAY_PARENT_ARGUMENT );
+ fusage.add( DisplaySetting.DISPLAY_OPTIONAL );
+ helpFormatter.setFullUsageSettings( fusage );
+
+ // test line usage
+ assertEquals( "incorrect full usage", fusage,
+ helpFormatter.getFullUsageSettings( ) );
+
+ final Set dsettings = new HashSet( );
+ dsettings.add( DisplaySetting.DISPLAY_GROUP_NAME );
+ dsettings.add( DisplaySetting.DISPLAY_GROUP_EXPANDED );
+ dsettings.add( DisplaySetting.DISPLAY_GROUP_ARGUMENT );
+
+ helpFormatter.setDisplaySettings( dsettings );
+
+ verbose = new DefaultOptionBuilder( ).withLongName( "verbose" )
+ .withDescription( "print the
version information and exit" )
+ .create( );
+
+ options = new GroupBuilder( ).withName( "options" )
+ .withOption(
DefaultOptionTest.buildHelpOption( ) )
+ .withOption(
ArgumentTest.buildTargetsArgument( ) )
+ .withOption( new DefaultOptionBuilder(
).withLongName(
+ "diagnostics" )
+
.withDescription( "print information that might be helpful to diagnose or
report problems." )
+
.create( ) )
+ .withOption( new DefaultOptionBuilder(
).withLongName(
+ "projecthelp" )
+
.withDescription( "print project help information" )
+
.create( ) )
+ .withOption( verbose ).create( );
+
+ helpFormatter.setGroup( options );
+
+ // test default gutters
+ assertEquals( "incorrect left gutter",
+ HelpFormatter.DEFAULT_GUTTER_LEFT, helpFormatter.getGutterLeft(
) );
+ assertEquals( "incorrect right gutter",
+ HelpFormatter.DEFAULT_GUTTER_RIGHT,
helpFormatter.getGutterRight( ) );
+ assertEquals( "incorrect center gutter",
+ HelpFormatter.DEFAULT_GUTTER_CENTER,
+ helpFormatter.getGutterCenter( ) );
+
+ final StringWriter writer = new StringWriter( );
+ helpFormatter.setPrintWriter( new PrintWriter( writer ) );
+ helpFormatter.print( );
+
+ final BufferedReader reader = new BufferedReader( new StringReader(
+ writer.toString( ) ) );
+ assertEquals( "Usage:
",
+ reader.readLine( ) );
+ assertEquals( "ant [--help --diagnostics --projecthelp --verbose]
[<target1> [<target2> ...]] ",
+ reader.readLine( ) );
+ assertEquals( "options
",
+ reader.readLine( ) );
+ assertEquals( " --help (-?,-h) Displays the help
",
+ reader.readLine( ) );
+ assertEquals( " --diagnostics print information that might
be helpful to diagnose or ",
+ reader.readLine( ) );
+ assertEquals( " report problems.
",
+ reader.readLine( ) );
+ assertEquals( " --projecthelp print project help
information ",
+ reader.readLine( ) );
+ assertEquals( " --verbose print the version
information and exit ",
+ reader.readLine( ) );
+ assertEquals( " target [target ...] The targets ant should build
",
+ reader.readLine( ) );
+ assertNull( reader.readLine( ) );
+ }
+}
+
+
+class OptionComparator implements Comparator
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @param o1 DOCUMENT ME!
+ * @param o2 DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int compare( Object o1, Object o2 )
+ {
+ Option opt1 = (Option) o1;
+ Option opt2 = (Option) o2;
+
+ return -opt1.getPreferredName( ).compareTo( opt2.getPreferredName(
) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/validation/ClassValidatorTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/validation/ClassValidatorTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/validation/ClassValidatorTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,247 +1,309 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.validation;
-
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.resource.ResourceHelper;
-
-public class ClassValidatorTest extends TestCase {
-
- private final static ResourceHelper resources =
- ResourceHelper.getResourceHelper();
-
- private ClassValidator validator;
-
- protected void setUp() {
- validator = new ClassValidator();
- }
-
- public void testValidName() throws InvalidArgumentException {
- final Object[] array = new Object[] { "MyApp", "org.apache.ant.Main"
};
- final List list = Arrays.asList(array);
-
- validator.validate(list);
-
- assertEquals("Name is incorrect", "MyApp", list.get(0));
- assertEquals("Name is incorrect", "org.apache.ant.Main",
list.get(1));
- }
-
- public void testNameBadStart() {
- final String className = "1stClass";
- final Object[] array = new Object[] { className };
- final List list = Arrays.asList(array);
-
- try {
- validator.validate(list);
- fail("Class name cannot start with a number.");
- } catch (InvalidArgumentException ive) {
- assertEquals(
- resources.getMessage(
- "ClassValidator.bad.classname",
- className),
- ive.getMessage());
- }
- }
-
- public void testNameBadEnd() {
- final String className = "My.Class.";
-
- final Object[] array = new Object[] { className };
- final List list = Arrays.asList(array);
-
- try {
- validator.validate(list);
- fail("Trailing period not permitted.");
- } catch (InvalidArgumentException ive) {
- assertEquals(
- resources.getMessage(
- "ClassValidator.bad.classname",
- className),
- ive.getMessage());
- }
- }
-
- public void testNameBadMiddle() {
- final String className = "My..Class";
-
- final Object[] array = new Object[] { className };
- final List list = Arrays.asList(array);
-
- try {
- validator.validate(list);
- fail("Two consecutive periods is not permitted.");
- } catch (InvalidArgumentException ive) {
- assertEquals(
- resources.getMessage(
- "ClassValidator.bad.classname",
- className),
- ive.getMessage());
- }
- }
-
- public void testIllegalNameChar() {
- final String className = "My?Class";
-
- final Object[] array = new Object[] { className };
- final List list = Arrays.asList(array);
-
- try {
- validator.validate(list);
- fail("Illegal character not allowed in Class name.");
- } catch (InvalidArgumentException ive) {
- assertEquals(
- resources.getMessage(
- "ClassValidator.bad.classname",
- className),
- ive.getMessage());
- }
- }
-
- public void testLoadable() {
- assertFalse("Validator is loadable", validator.isLoadable());
- validator.setLoadable(true);
- assertTrue("Validator is NOT loadable", validator.isLoadable());
- validator.setLoadable(false);
- assertFalse("Validator is loadable", validator.isLoadable());
- }
-
- public void testLoadValid() throws InvalidArgumentException {
- final Object[] array =
- new Object[] {
- "net.dpml.cli.Option",
- "java.util.Vector" };
- final List list = Arrays.asList(array);
-
- validator.setLoadable(true);
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(
- "net.dpml.cli.Option",
- ((Class) i.next()).getName());
- assertEquals("java.util.Vector", ((Class) i.next()).getName());
- assertFalse(i.hasNext());
- }
-
- public void testLoadInvalid() {
- final String className = "net.dpml.cli.NonOption";
-
- final Object[] array = new Object[] { className, "java.util.Vectors"
};
- final List list = Arrays.asList(array);
-
- validator.setLoadable(true);
-
- try {
- validator.validate(list);
- fail("Class Not Found");
- } catch (InvalidArgumentException ive) {
- assertEquals(
- resources.getMessage(
- "ClassValidator.class.notfound",
- className),
- ive.getMessage());
- }
- }
-
- public void testInstantiate() {
- assertFalse("Validator creates instances", validator.isInstance());
- validator.setInstance(true);
- assertTrue(
- "Validator does NOT create instances",
- validator.isInstance());
- validator.setInstance(false);
- assertFalse("Validator creates instances", validator.isInstance());
- }
-
- public void testCreateClassInstance() throws InvalidArgumentException {
- final Object[] array = new Object[] { "java.util.Vector" };
- final List list = Arrays.asList(array);
-
- validator.setInstance(true);
-
- validator.validate(list);
- assertTrue(
- "Vector instance NOT found",
- list.get(0) instanceof java.util.Vector);
- }
-
- public void testCreateInterfaceInstance() {
- final String className = "java.util.Map";
- final Object[] array = new Object[] { className };
- final List list = Arrays.asList(array);
-
- validator.setInstance(true);
-
- try {
- validator.validate(list);
- fail("It's not possible to create a '" + className + "'");
- }
- catch (final InvalidArgumentException ive) {
- assertEquals(
- resources.getMessage(
- "ClassValidator.class.create",
- className),
- ive.getMessage());
- }
- }
-
- public void testCreateProtectedInstance() {
- final String className =
"net.dpml.cli.validation.protect.ProtectedClass";
- final Object[] array = new Object[] { className };
- final List list = Arrays.asList(array);
-
- validator.setInstance(true);
-
- try {
- validator.validate(list);
- fail("It's not possible to create a '" + className + "'");
- }
- catch (final InvalidArgumentException ive) {
- assertEquals(
- resources.getMessage(
- "ClassValidator.class.access",
- className,
- "Class net.dpml.cli.validation.ClassValidator " +
- "can not access a member of class " +
- "net.dpml.cli.validation.protect.ProtectedClass
" +
- "with modifiers \"protected\""),
- ive.getMessage());
- }
- }
-
- public void testClassloader() {
- assertEquals(
- "Wrong classloader found",
- validator.getClass().getClassLoader(),
- validator.getClassLoader());
-
- URLClassLoader classloader = new URLClassLoader(new URL[] {
- });
- validator.setClassLoader(classloader);
-
- assertEquals(
- "Wrong classloader found",
- classloader,
- validator.getClassLoader());
- }
-}
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.validation;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class ClassValidatorTest extends TestCase
+{
+ private final static ResourceHelper resources =
ResourceHelper.getResourceHelper( );
+ private ClassValidator validator;
+
+ /**
+ * DOCUMENT ME!
+ */
+ protected void setUp( )
+ {
+ validator = new ClassValidator( );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testValidName( ) throws InvalidArgumentException
+ {
+ final Object[] array = new Object[]{"MyApp", "org.apache.ant.Main"};
+ final List list = Arrays.asList( array );
+
+ validator.validate( list );
+
+ assertEquals( "Name is incorrect", "MyApp", list.get( 0 ) );
+ assertEquals( "Name is incorrect", "org.apache.ant.Main", list.get(
1 ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNameBadStart( )
+ {
+ final String className = "1stClass";
+ final Object[] array = new Object[]{className};
+ final List list = Arrays.asList( array );
+
+ try
+ {
+ validator.validate( list );
+ fail( "Class name cannot start with a number." );
+ }
+ catch( InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
+ "ClassValidator.bad.classname", className ),
+ ive.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNameBadEnd( )
+ {
+ final String className = "My.Class.";
+
+ final Object[] array = new Object[]{className};
+ final List list = Arrays.asList( array );
+
+ try
+ {
+ validator.validate( list );
+ fail( "Trailing period not permitted." );
+ }
+ catch( InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
+ "ClassValidator.bad.classname", className ),
+ ive.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNameBadMiddle( )
+ {
+ final String className = "My..Class";
+
+ final Object[] array = new Object[]{className};
+ final List list = Arrays.asList( array );
+
+ try
+ {
+ validator.validate( list );
+ fail( "Two consecutive periods is not permitted." );
+ }
+ catch( InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
+ "ClassValidator.bad.classname", className ),
+ ive.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testIllegalNameChar( )
+ {
+ final String className = "My?Class";
+
+ final Object[] array = new Object[]{className};
+ final List list = Arrays.asList( array );
+
+ try
+ {
+ validator.validate( list );
+ fail( "Illegal character not allowed in Class name." );
+ }
+ catch( InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
+ "ClassValidator.bad.classname", className ),
+ ive.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testLoadable( )
+ {
+ assertFalse( "Validator is loadable", validator.isLoadable( ) );
+ validator.setLoadable( true );
+ assertTrue( "Validator is NOT loadable", validator.isLoadable( ) );
+ validator.setLoadable( false );
+ assertFalse( "Validator is loadable", validator.isLoadable( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testLoadValid( ) throws InvalidArgumentException
+ {
+ final Object[] array = new Object[]
+ {
+ "net.dpml.cli.Option", "java.util.Vector"
+ };
+ final List list = Arrays.asList( array );
+
+ validator.setLoadable( true );
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( "net.dpml.cli.Option", ( (Class) i.next( ) ).getName(
) );
+ assertEquals( "java.util.Vector", ( (Class) i.next( ) ).getName( )
);
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testLoadInvalid( )
+ {
+ final String className = "net.dpml.cli.NonOption";
+
+ final Object[] array = new Object[]{className, "java.util.Vectors"};
+ final List list = Arrays.asList( array );
+
+ validator.setLoadable( true );
+
+ try
+ {
+ validator.validate( list );
+ fail( "Class Not Found" );
+ }
+ catch( InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
+ "ClassValidator.class.notfound", className ),
+ ive.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testInstantiate( )
+ {
+ assertFalse( "Validator creates instances", validator.isInstance( )
);
+ validator.setInstance( true );
+ assertTrue( "Validator does NOT create instances",
+ validator.isInstance( ) );
+ validator.setInstance( false );
+ assertFalse( "Validator creates instances", validator.isInstance( )
);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testCreateClassInstance( ) throws InvalidArgumentException
+ {
+ final Object[] array = new Object[]{"java.util.Vector"};
+ final List list = Arrays.asList( array );
+
+ validator.setInstance( true );
+
+ validator.validate( list );
+ assertTrue( "Vector instance NOT found",
+ list.get( 0 ) instanceof java.util.Vector );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCreateInterfaceInstance( )
+ {
+ final String className = "java.util.Map";
+ final Object[] array = new Object[]{className};
+ final List list = Arrays.asList( array );
+
+ validator.setInstance( true );
+
+ try
+ {
+ validator.validate( list );
+ fail( "It's not possible to create a '" + className + "'" );
+ }
+ catch( final InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
"ClassValidator.class.create",
+ className ), ive.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testCreateProtectedInstance( )
+ {
+ final String className =
"net.dpml.cli.validation.protect.ProtectedClass";
+ final Object[] array = new Object[]{className};
+ final List list = Arrays.asList( array );
+
+ validator.setInstance( true );
+
+ try
+ {
+ validator.validate( list );
+ fail( "It's not possible to create a '" + className + "'" );
+ }
+ catch( final InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
"ClassValidator.class.access",
+ className,
+ "Class net.dpml.cli.validation.ClassValidator " +
+ "can not access a member of class " +
+ "net.dpml.cli.validation.protect.ProtectedClass " +
+ "with modifiers \"protected\"" ), ive.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testClassloader( )
+ {
+ assertEquals( "Wrong classloader found",
+ validator.getClass( ).getClassLoader( ),
+ validator.getClassLoader( ) );
+
+ URLClassLoader classloader = new URLClassLoader( new URL[]{} );
+ validator.setClassLoader( classloader );
+
+ assertEquals( "Wrong classloader found", classloader,
+ validator.getClassLoader( ) );
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/validation/DateValidatorTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/validation/DateValidatorTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/validation/DateValidatorTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,237 +1,302 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.validation;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-/**
- * JUnit test case for DateValidator.
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public class DateValidatorTest
- extends TestCase {
- private static final ResourceHelper resources =
ResourceHelper.getResourceHelper();
- public static final DateFormat D_M_YY = new SimpleDateFormat("d/M/yy");
- public static final DateFormat YYYY_MM_YY = new
SimpleDateFormat("yyyy-MM-dd");
- private List formats = Arrays.asList(new Object[] { D_M_YY, YYYY_MM_YY
});
-
- public void testSingleFormatValidate()
- throws InvalidArgumentException
- {
- final Object[] array = new Object[] { "23/12/03" };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator(D_M_YY);
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals("2003-12-23", YYYY_MM_YY.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testDefaultDateFormatValidate()
- throws InvalidArgumentException
- {
- final Date now = new Date();
- final String date = DateFormat.getDateInstance().format( now );
- final DateFormat df = new SimpleDateFormat("yyyy/M/dd");
- final String formatted = df.format( now );
- final Object[] array = new Object[] { date };
- final List list = Arrays.asList(array);
- final Validator validator = DateValidator.getDateInstance();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(formatted, df.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testDefaultTimeFormatValidate()
- throws InvalidArgumentException
- {
- final Date now = new Date();
- final String time = DateFormat.getTimeInstance().format( now );
- final DateFormat df = new SimpleDateFormat("HH:mm:ss");
- final String formatted = df.format( now );
- final Object[] array = new Object[] { time };
- final List list = Arrays.asList(array);
- final Validator validator = DateValidator.getTimeInstance();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(formatted, df.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testDefaultDateTimeFormatValidate()
- throws InvalidArgumentException
- {
- final Date now = new Date();
- final String date = DateFormat.getDateTimeInstance().format( now );
- final DateFormat df = new SimpleDateFormat("yyyy/M/dd HH:mm:ss");
- final String formatted = df.format( now );
- final Object[] array = new Object[] { date };
- final List list = Arrays.asList(array);
- final Validator validator = DateValidator.getDateTimeInstance();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(formatted, df.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testDefaultValidator()
- throws InvalidArgumentException
- {
- final Date now = new Date();
- final String date = DateFormat.getInstance().format( now );
- final DateFormat df = new SimpleDateFormat("yyyy/M/dd HH:mm");
- final String formatted = df.format( now );
- final Object[] array = new Object[] { date };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(formatted, df.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testValidate()
- throws InvalidArgumentException
- {
- final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
- final List list = Arrays.asList(array);
- final Validator validator = new DateValidator(formats);
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals("2003-12-23", YYYY_MM_YY.format((Date) i.next()));
- assertEquals("2002-10-12", YYYY_MM_YY.format((Date) i.next()));
- assertFalse(i.hasNext());
- }
-
- public void testMinimumBounds()
- throws InvalidArgumentException
- {
- final DateValidator validator = new DateValidator(formats);
- final Calendar cal = Calendar.getInstance();
-
- {
- final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
- final List list = Arrays.asList(array);
- cal.set(2002, 1, 12);
-
- final Date min = cal.getTime();
- validator.setMinimum(min);
- assertTrue("maximum bound is set", validator.getMaximum() ==
null);
- assertEquals("minimum bound is incorrect", min,
validator.getMinimum());
- validator.validate(list);
- }
-
- {
- final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
- final List list = Arrays.asList(array);
- cal.set(2003, 1, 12);
-
- final Date min = cal.getTime();
- validator.setMinimum(min);
-
- try {
- validator.validate(list);
- fail("minimum out of bounds exception not caught");
- } catch (final InvalidArgumentException exp) {
-
assertEquals(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
- new Object[] {
"2002-10-12" }), exp.getMessage());
- }
- }
- }
-
- public void testFormats()
- throws InvalidArgumentException
- {
- final DateValidator validator = new DateValidator(formats);
- assertEquals("date format is incorrect", ((SimpleDateFormat)
formats.get(0)).toPattern(),
- ((SimpleDateFormat)
validator.getFormats()[0]).toPattern());
- assertEquals("date format is incorrect", ((SimpleDateFormat)
formats.get(1)).toPattern(),
- ((SimpleDateFormat)
validator.getFormats()[1]).toPattern());
- }
-
- public void testMaximumBounds()
- throws InvalidArgumentException
- {
- final DateValidator validator = new DateValidator(formats);
- final Calendar cal = Calendar.getInstance();
-
- {
- final Object[] array = new Object[] { "23/12/03", "2002-10-12" };
- final List list = Arrays.asList(array);
- cal.set(2004, 1, 12);
-
- final Date max = cal.getTime();
- validator.setMaximum(max);
- assertTrue("minimum bound is set", validator.getMinimum() ==
null);
- assertEquals("maximum bound is incorrect", max,
validator.getMaximum());
- validator.validate(list);
- }
-
- {
- final Object[] array = new Object[] { "23/12/03", "2004-10-12" };
- final List list = Arrays.asList(array);
- cal.set(2004, 1, 12);
-
- final Date max = cal.getTime();
- validator.setMaximum(max);
-
- try {
- validator.validate(list);
- fail("maximum out of bounds exception not caught");
- } catch (final InvalidArgumentException exp) {
-
assertEquals(resources.getMessage(ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
- new Object[] {
"2004-10-12" }), exp.getMessage());
- }
- }
- }
-
- public static Test suite()
- {
- Test result = new TestSuite(DateValidatorTest.class); // default
behavior
- result = new TimeZoneTestSuite("EST", result); // ensure it runs in
EST timezone
-
- return result;
- }
-}
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.validation;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * JUnit test case for DateValidator.
+ *
+ * @author Rob Oxspring
+ * @author John Keyes
+ */
+public class DateValidatorTest extends TestCase
+{
+ private static final ResourceHelper resources =
ResourceHelper.getResourceHelper( );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final DateFormat D_M_YY = new SimpleDateFormat( "d/M/yy" );
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static final DateFormat YYYY_MM_YY = new SimpleDateFormat(
+ "yyyy-MM-dd" );
+ private List formats = Arrays.asList( new Object[]{D_M_YY, YYYY_MM_YY} );
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testSingleFormatValidate( ) throws InvalidArgumentException
+ {
+ final Object[] array = new Object[]{"23/12/03"};
+ final List list = Arrays.asList( array );
+ final Validator validator = new DateValidator( D_M_YY );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( "2003-12-23", YYYY_MM_YY.format( (Date) i.next( ) ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testDefaultDateFormatValidate( )
+ throws InvalidArgumentException
+ {
+ final Date now = new Date( );
+ final String date = DateFormat.getDateInstance( ).format( now );
+ final DateFormat df = new SimpleDateFormat( "yyyy/M/dd" );
+ final String formatted = df.format( now );
+ final Object[] array = new Object[]{date};
+ final List list = Arrays.asList( array );
+ final Validator validator = DateValidator.getDateInstance( );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( formatted, df.format( (Date) i.next( ) ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testDefaultTimeFormatValidate( )
+ throws InvalidArgumentException
+ {
+ final Date now = new Date( );
+ final String time = DateFormat.getTimeInstance( ).format( now );
+ final DateFormat df = new SimpleDateFormat( "HH:mm:ss" );
+ final String formatted = df.format( now );
+ final Object[] array = new Object[]{time};
+ final List list = Arrays.asList( array );
+ final Validator validator = DateValidator.getTimeInstance( );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( formatted, df.format( (Date) i.next( ) ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testDefaultDateTimeFormatValidate( )
+ throws InvalidArgumentException
+ {
+ final Date now = new Date( );
+ final String date = DateFormat.getDateTimeInstance( ).format( now );
+ final DateFormat df = new SimpleDateFormat( "yyyy/M/dd HH:mm:ss" );
+ final String formatted = df.format( now );
+ final Object[] array = new Object[]{date};
+ final List list = Arrays.asList( array );
+ final Validator validator = DateValidator.getDateTimeInstance( );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( formatted, df.format( (Date) i.next( ) ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testDefaultValidator( ) throws InvalidArgumentException
+ {
+ final Date now = new Date( );
+ final String date = DateFormat.getInstance( ).format( now );
+ final DateFormat df = new SimpleDateFormat( "yyyy/M/dd HH:mm" );
+ final String formatted = df.format( now );
+ final Object[] array = new Object[]{date};
+ final List list = Arrays.asList( array );
+ final Validator validator = new DateValidator( );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( formatted, df.format( (Date) i.next( ) ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testValidate( ) throws InvalidArgumentException
+ {
+ final Object[] array = new Object[]{"23/12/03", "2002-10-12"};
+ final List list = Arrays.asList( array );
+ final Validator validator = new DateValidator( formats );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( "2003-12-23", YYYY_MM_YY.format( (Date) i.next( ) ) );
+ assertEquals( "2002-10-12", YYYY_MM_YY.format( (Date) i.next( ) ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testMinimumBounds( ) throws InvalidArgumentException
+ {
+ final DateValidator validator = new DateValidator( formats );
+ final Calendar cal = Calendar.getInstance( );
+
+ {
+ final Object[] array = new Object[]{"23/12/03", "2002-10-12"};
+ final List list = Arrays.asList( array );
+ cal.set( 2002, 1, 12 );
+
+ final Date min = cal.getTime( );
+ validator.setMinimum( min );
+ assertTrue( "maximum bound is set", validator.getMaximum( ) ==
null );
+ assertEquals( "minimum bound is incorrect", min,
+ validator.getMinimum( ) );
+ validator.validate( list );
+ }
+
+ {
+ final Object[] array = new Object[]{"23/12/03", "2002-10-12"};
+ final List list = Arrays.asList( array );
+ cal.set( 2003, 1, 12 );
+
+ final Date min = cal.getTime( );
+ validator.setMinimum( min );
+
+ try
+ {
+ validator.validate( list );
+ fail( "minimum out of bounds exception not caught" );
+ }
+ catch( final InvalidArgumentException exp )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
+ new Object[]{"2002-10-12"} ), exp.getMessage( ) );
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testFormats( ) throws InvalidArgumentException
+ {
+ final DateValidator validator = new DateValidator( formats );
+ assertEquals( "date format is incorrect",
+ ( (SimpleDateFormat) formats.get( 0 ) ).toPattern( ),
+ ( (SimpleDateFormat) validator.getFormats( )[0] ).toPattern( )
);
+ assertEquals( "date format is incorrect",
+ ( (SimpleDateFormat) formats.get( 1 ) ).toPattern( ),
+ ( (SimpleDateFormat) validator.getFormats( )[1] ).toPattern( )
);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testMaximumBounds( ) throws InvalidArgumentException
+ {
+ final DateValidator validator = new DateValidator( formats );
+ final Calendar cal = Calendar.getInstance( );
+
+ {
+ final Object[] array = new Object[]{"23/12/03", "2002-10-12"};
+ final List list = Arrays.asList( array );
+ cal.set( 2004, 1, 12 );
+
+ final Date max = cal.getTime( );
+ validator.setMaximum( max );
+ assertTrue( "minimum bound is set", validator.getMinimum( ) ==
null );
+ assertEquals( "maximum bound is incorrect", max,
+ validator.getMaximum( ) );
+ validator.validate( list );
+ }
+
+ {
+ final Object[] array = new Object[]{"23/12/03", "2004-10-12"};
+ final List list = Arrays.asList( array );
+ cal.set( 2004, 1, 12 );
+
+ final Date max = cal.getTime( );
+ validator.setMaximum( max );
+
+ try
+ {
+ validator.validate( list );
+ fail( "maximum out of bounds exception not caught" );
+ }
+ catch( final InvalidArgumentException exp )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.DATEVALIDATOR_DATE_OUTOFRANGE,
+ new Object[]{"2004-10-12"} ), exp.getMessage( ) );
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static Test suite( )
+ {
+ Test result = new TestSuite( DateValidatorTest.class ); // default
behavior
+ result = new TimeZoneTestSuite( "EST", result ); // ensure it runs
in EST timezone
+
+ return result;
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/validation/EnumValidatorTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/validation/EnumValidatorTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/validation/EnumValidatorTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,65 +1,86 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.validation;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-public class EnumValidatorTest
- extends TestCase {
- private final static ResourceHelper resources =
ResourceHelper.getResourceHelper();
- private final Set enumSet = new TreeSet(Arrays.asList(new Object[] {
"red", "green", "blue" }));
-
- public void testValidate()
- throws InvalidArgumentException {
- final Object[] array = new Object[] { "red", "green" };
-
- {
- final List list = Arrays.asList(array);
- final EnumValidator validator = new EnumValidator(enumSet);
- assertEquals("valid values are incorrect", enumSet,
validator.getValidValues());
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals("red", i.next());
- assertEquals("green", i.next());
- assertFalse(i.hasNext());
- }
- }
-
- public void testNonMember() {
- final Object[] array = new Object[] { "red", "pink" };
- final List list = Arrays.asList(array);
- final EnumValidator validator = new EnumValidator(enumSet);
-
- try {
- validator.validate(list);
- fail("InvalidArgumentException");
- } catch (InvalidArgumentException e) {
-
assertEquals(resources.getMessage(ResourceConstants.ENUM_ILLEGAL_VALUE,
- new Object[] { "pink",
validator.getValuesAsString() }),
- e.getMessage());
- }
- }
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.validation;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class EnumValidatorTest extends TestCase
+{
+ private final static ResourceHelper resources =
ResourceHelper.getResourceHelper( );
+ private final Set enumSet = new TreeSet( Arrays.asList(
+ new Object[]{"red", "green", "blue"} ) );
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testValidate( ) throws InvalidArgumentException
+ {
+ final Object[] array = new Object[]{"red", "green"};
+
+ {
+ final List list = Arrays.asList( array );
+ final EnumValidator validator = new EnumValidator( enumSet );
+ assertEquals( "valid values are incorrect", enumSet,
+ validator.getValidValues( ) );
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( "red", i.next( ) );
+ assertEquals( "green", i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testNonMember( )
+ {
+ final Object[] array = new Object[]{"red", "pink"};
+ final List list = Arrays.asList( array );
+ final EnumValidator validator = new EnumValidator( enumSet );
+
+ try
+ {
+ validator.validate( list );
+ fail( "InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.ENUM_ILLEGAL_VALUE,
+ new Object[]{"pink", validator.getValuesAsString( )} ),
+ e.getMessage( ) );
+ }
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/validation/FileValidatorTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/validation/FileValidatorTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/validation/FileValidatorTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,210 +1,210 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.validation;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-/**
- * JUnit test case for the FileValidator.
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public class FileValidatorTest extends TestCase {
-
- public void testValidate() throws InvalidArgumentException {
- final Object[] array = new Object[] { "src", "build.xml",
- "veryunlikelyfilename" };
- final List list = Arrays.asList(array);
- final FileValidator validator = new FileValidator();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals( "src", new File("src"), i.next());
- assertEquals( "build.xml", new File("build.xml"), i.next());
- assertEquals( "veryunlikelyfilename", new
File("veryunlikelyfilename"), i.next());
- assertFalse( "next", i.hasNext() );
- }
-
- public void testValidate_Directory() {
- final Object[] array = new Object[] { "src", "build.xml" };
- final List list = Arrays.asList(array);
- final FileValidator validator = FileValidator
- .getExistingDirectoryInstance();
-
- assertTrue("is a directory validator", validator.isDirectory());
- assertFalse("is not a file validator", validator.isFile());
- assertTrue("is an existing file validator", validator.isExisting());
- //assertFalse("is not a hidden file validator",
validator.isHidden());
-
- try {
- validator.validate(list);
- fail("InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals("build.xml", e.getMessage());
- }
- }
-
- public void testValidate_ReadableFile() {
- // make file readonly
- File file = new File("target/test/data/readable.txt");
- if( !file.exists() )
- {
- throw new IllegalStateException(
- "Missing test resource: 'target/test/data/readable.txt'
relative to "
- + System.getProperty( "user.dir" ) );
- }
- file.setReadOnly();
-
- final Object[] array = new Object[] {
"target/test/data/readable.txt",
- "target/test/data/notreadable.txt" };
- final List list = Arrays.asList(array);
- final FileValidator validator =
FileValidator.getExistingFileInstance();
- validator.setReadable(true);
-
- assertFalse("is not a directory validator", validator.isDirectory());
- assertTrue("is a file validator", validator.isFile());
- assertTrue("is an existing file validator", validator.isExisting());
- //assertFalse("is not a hidden file validator",
validator.isHidden());
- assertTrue("is a readable file validator", validator.isReadable());
- assertFalse("is not a writable file validator",
validator.isWritable());
-
- try {
- validator.validate(list);
- fail("InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals("target/test/data/notreadable.txt", e.getMessage());
- }
- }
-
- public void testValidate_WritableFile() {
- // make file readonly
- File file = new File("target/test/data/readable.txt");
- file.setReadOnly();
-
- final Object[] array = new Object[] {
"target/test/data/writable.txt",
- "target/test/data/readable.txt" };
- final List list = Arrays.asList(array);
- final FileValidator validator =
FileValidator.getExistingFileInstance();
- validator.setWritable(true);
-
- assertFalse("is not a directory validator", validator.isDirectory());
- assertTrue("is a file validator", validator.isFile());
- assertTrue("is an existing file validator", validator.isExisting());
- //assertFalse("is not a hidden file validator",
validator.isHidden());
- assertFalse("is not a readable file validator",
validator.isReadable());
- assertTrue("is a writable file validator", validator.isWritable());
-
- try {
- validator.validate(list);
- fail("InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals("target/test/data/readable.txt", e.getMessage());
- }
- }
-
- //
- // WARNING - this test fails because the validation handler is checking
if the .hidden.txt
- // file is hidden but the JVM is returning false even though the file is
showing up as
- // hidden under Windows.
- //
- /*
- public void testValidate_HiddenFile() throws InvalidArgumentException {
- // make file hidden on Windows
- attribute("H");
-
- final Object[] array = new Object[] {
"target/test/data/.hidden.txt", "src" };
- final List list = Arrays.asList(array);
- final FileValidator validator =
FileValidator.getExistingFileInstance();
- validator.setHidden(true);
-
- assertFalse("is not a directory validator", validator.isDirectory());
- assertTrue("is a file validator", validator.isFile());
- assertTrue("is an existing file validator", validator.isExisting());
- assertTrue("is a hidden file validator", validator.isHidden());
-
- File file = new File( "target/test/data/.hidden.txt" );
- System.out.println( "# " + file.getAbsolutePath() + ", " +
file.exists() + ", " + file.isHidden() );
-
- try
- {
- validator.validate(list);
- fail("InvalidArgumentException");
- }
- catch (InvalidArgumentException e)
- {
- assertEquals("src", e.getMessage());
- }
- }
-
- private void attribute(String attr) {
- final String os = System.getProperty("os.name").toLowerCase();
-
- // if the test is run on windows, run the attrib program
- // to set the hidden attribute
- if (os.indexOf("windows") != -1) {
- // windows
- try {
- Process proc = Runtime.getRuntime().exec(
- "attrib.exe +" + attr + "
target/test/data/.hidden.txt",
- null, new File("."));
- } catch (IOException e) {
- System.out.println(e.getMessage());
- e.printStackTrace();
- }
- }
- }
- */
-
- public void testValidate_Existing() {
- final Object[] array = new Object[] { "build.xml",
- "veryunlikelyfilename" };
- final List list = Arrays.asList(array);
- final FileValidator validator = FileValidator.getExistingInstance();
-
- assertFalse("is not a directory validator", validator.isDirectory());
- assertFalse("is not a file validator", validator.isFile());
- assertTrue("is an existing file validator", validator.isExisting());
- //assertFalse("is not a hidden file validator",
validator.isHidden());
-
- try {
- validator.validate(list);
- fail("InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals("veryunlikelyfilename", e.getMessage());
- }
- }
-
- public void testValidate_File() {
- final Object[] array = new Object[] { "build.xml", "src" };
- final List list = Arrays.asList(array);
- final Validator validator = FileValidator.getExistingFileInstance();
-
- try {
- validator.validate(list);
- fail("InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals("src", e.getMessage());
- }
- }
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.validation;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * JUnit test case for the FileValidator.
+ *
+ * @author Rob Oxspring
+ * @author John Keyes
+ */
+public class FileValidatorTest extends TestCase
+{
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testValidate( ) throws InvalidArgumentException
+ {
+ final Object[] array = new Object[]
+ {
+ "src", "build.xml", "veryunlikelyfilename"
+ };
+ final List list = Arrays.asList( array );
+ final FileValidator validator = new FileValidator( );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( "src", new File( "src" ), i.next( ) );
+ assertEquals( "build.xml", new File( "build.xml" ), i.next( ) );
+ assertEquals( "veryunlikelyfilename",
+ new File( "veryunlikelyfilename" ), i.next( ) );
+ assertFalse( "next", i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_Directory( )
+ {
+ final Object[] array = new Object[]{"src", "build.xml"};
+ final List list = Arrays.asList( array );
+ final FileValidator validator =
FileValidator.getExistingDirectoryInstance( );
+
+ assertTrue( "is a directory validator", validator.isDirectory( ) );
+ assertFalse( "is not a file validator", validator.isFile( ) );
+ assertTrue( "is an existing file validator", validator.isExisting(
) );
+
+ //assertFalse("is not a hidden file validator",
validator.isHidden());
+ try
+ {
+ validator.validate( list );
+ fail( "InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( "build.xml", e.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_ReadableFile( )
+ {
+ // make file readonly
+ File file = new File( "target/test/data/readable.txt" );
+
+ if( !file.exists( ) )
+ {
+ throw new IllegalStateException(
+ "Missing test resource: 'target/test/data/readable.txt'
relative to " +
+ System.getProperty( "user.dir" ) );
+ }
+
+ file.setReadOnly( );
+
+ final Object[] array = new Object[]
+ {
+ "target/test/data/readable.txt",
+ "target/test/data/notreadable.txt"
+ };
+ final List list = Arrays.asList( array );
+ final FileValidator validator =
FileValidator.getExistingFileInstance( );
+ validator.setReadable( true );
+
+ assertFalse( "is not a directory validator", validator.isDirectory(
) );
+ assertTrue( "is a file validator", validator.isFile( ) );
+ assertTrue( "is an existing file validator", validator.isExisting(
) );
+ //assertFalse("is not a hidden file validator",
validator.isHidden());
+ assertTrue( "is a readable file validator", validator.isReadable( )
);
+ assertFalse( "is not a writable file validator",
+ validator.isWritable( ) );
+
+ try
+ {
+ validator.validate( list );
+ fail( "InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( "target/test/data/notreadable.txt", e.getMessage(
) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_WritableFile( )
+ {
+ // make file readonly
+ File file = new File( "target/test/data/readable.txt" );
+ file.setReadOnly( );
+
+ final Object[] array = new Object[]
+ {
+ "target/test/data/writable.txt",
"target/test/data/readable.txt"
+ };
+ final List list = Arrays.asList( array );
+ final FileValidator validator =
FileValidator.getExistingFileInstance( );
+ validator.setWritable( true );
+
+ assertFalse( "is not a directory validator", validator.isDirectory(
) );
+ assertTrue( "is a file validator", validator.isFile( ) );
+ assertTrue( "is an existing file validator", validator.isExisting(
) );
+ //assertFalse("is not a hidden file validator",
validator.isHidden());
+ assertFalse( "is not a readable file validator",
+ validator.isReadable( ) );
+ assertTrue( "is a writable file validator", validator.isWritable( )
);
+
+ try
+ {
+ validator.validate( list );
+ fail( "InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( "target/test/data/readable.txt", e.getMessage( )
);
+ }
+ }
+
+ //
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_Existing( )
+ {
+ final Object[] array = new Object[]{"build.xml",
"veryunlikelyfilename"};
+ final List list = Arrays.asList( array );
+ final FileValidator validator = FileValidator.getExistingInstance(
);
+
+ assertFalse( "is not a directory validator", validator.isDirectory(
) );
+ assertFalse( "is not a file validator", validator.isFile( ) );
+ assertTrue( "is an existing file validator", validator.isExisting(
) );
+
+ //assertFalse("is not a hidden file validator",
validator.isHidden());
+ try
+ {
+ validator.validate( list );
+ fail( "InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( "veryunlikelyfilename", e.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_File( )
+ {
+ final Object[] array = new Object[]{"build.xml", "src"};
+ final List list = Arrays.asList( array );
+ final Validator validator = FileValidator.getExistingFileInstance(
);
+
+ try
+ {
+ validator.validate( list );
+ fail( "InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( "src", e.getMessage( ) );
+ }
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/validation/NumberValidatorTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/validation/NumberValidatorTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/validation/NumberValidatorTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,167 +1,217 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.validation;
-
-import java.text.NumberFormat;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-/**
- * JUnit test case for NumberValidator.
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public class NumberValidatorTest
- extends TestCase {
- private static final ResourceHelper resources =
ResourceHelper.getResourceHelper();
-
- public void testValidate_Number()
- throws InvalidArgumentException {
- final NumberFormat format = NumberFormat.getNumberInstance();
-
- final Object[] array =
- new Object[] { format.format(1d), format.format(1.07d),
format.format(-.45d) };
-
- {
- final List list = Arrays.asList(array);
- final Validator validator = NumberValidator.getNumberInstance();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001);
- assertFalse(i.hasNext());
- }
- }
-
- public void testValidate_Currency()
- throws InvalidArgumentException {
- NumberFormat format = NumberFormat.getCurrencyInstance();
- final Object[] array =
- new Object[] { format.format(1d), format.format(1.07),
format.format(-0.45) };
- final List list = Arrays.asList(array);
-
- final NumberValidator validator =
NumberValidator.getCurrencyInstance();
- assertEquals("incorrect currency format", format,
validator.getFormat());
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001);
- assertFalse(i.hasNext());
- }
-
- public void testValidate_Percent()
- throws InvalidArgumentException {
- final NumberFormat format = NumberFormat.getPercentInstance();
-
- final Object[] array =
- new Object[] {
- format.format(.01), format.format(1.07),
format.format(-.45),
- format.format(0.001)
- };
- final List list = Arrays.asList(array);
- final Validator validator = NumberValidator.getPercentInstance();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(0.01d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(1.07d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(-.45d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(0.00001d, ((Number) i.next()).doubleValue(), 0.0001);
- assertFalse(i.hasNext());
- }
-
- public void testValidate_Integer()
- throws InvalidArgumentException {
- final Object[] array = new Object[] { "1", "107", "-45" };
- final List list = Arrays.asList(array);
- final Validator validator = NumberValidator.getIntegerInstance();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(1d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(107d, ((Number) i.next()).doubleValue(), 0.0001);
- assertEquals(-45d, ((Number) i.next()).doubleValue(), 0.0001);
- assertFalse(i.hasNext());
- }
-
- public void testValidate_ExcessChars() {
- final Object[] array = new Object[] { "10DowningStreet" };
- final List list = Arrays.asList(array);
- final Validator validator = NumberValidator.getIntegerInstance();
-
- try {
- validator.validate(list);
- fail("InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals("10DowningStreet", e.getMessage());
- }
- }
-
- public void testValidate_Maximum() {
- final Object[] array = new Object[] { "1", "107" };
- final List list = Arrays.asList(array);
- final NumberValidator validator =
NumberValidator.getIntegerInstance();
- Integer max = new Integer(100);
-
- validator.setMaximum(max);
-
- assertTrue("no minimum set", validator.getMinimum() == null);
- assertEquals("incorrect maximum value", max, validator.getMaximum());
-
- try {
- validator.validate(list);
- fail("107 too big");
- } catch (InvalidArgumentException ive) {
-
assertEquals(resources.getMessage(ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE,
- "107"), ive.getMessage());
- }
- }
-
- public void testValidate_Minimum() {
- final Object[] array = new Object[] { "107", "1" };
- final List list = Arrays.asList(array);
- final NumberValidator validator =
NumberValidator.getIntegerInstance();
- Integer min = new Integer(100);
- validator.setMinimum(min);
-
- assertTrue("no maximum set", validator.getMaximum() == null);
- assertEquals("incorrect minimum value", min, validator.getMinimum());
-
- try {
- validator.validate(list);
- fail("1 too small");
- } catch (InvalidArgumentException ive) {
-
assertEquals(resources.getMessage(ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE,
- "1"), ive.getMessage());
- }
- }
-}
+/*
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.validation;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.text.NumberFormat;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * JUnit test case for NumberValidator.
+ *
+ * @author Rob Oxspring
+ * @author John Keyes
+ */
+public class NumberValidatorTest extends TestCase
+{
+ private static final ResourceHelper resources =
ResourceHelper.getResourceHelper( );
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testValidate_Number( ) throws InvalidArgumentException
+ {
+ final NumberFormat format = NumberFormat.getNumberInstance( );
+
+ final Object[] array = new Object[]
+ {
+ format.format( 1d ), format.format( 1.07d ),
+ format.format( -.45d )
+ };
+
+ {
+ final List list = Arrays.asList( array );
+ final Validator validator = NumberValidator.getNumberInstance(
);
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( 1d, ( (Number) i.next( ) ).doubleValue( ),
0.0001 );
+ assertEquals( 1.07d, ( (Number) i.next( ) ).doubleValue( ),
0.0001 );
+ assertEquals( -.45d, ( (Number) i.next( ) ).doubleValue( ),
0.0001 );
+ assertFalse( i.hasNext( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testValidate_Currency( ) throws InvalidArgumentException
+ {
+ NumberFormat format = NumberFormat.getCurrencyInstance( );
+ final Object[] array = new Object[]
+ {
+ format.format( 1d ), format.format( 1.07 ),
+ format.format( -0.45 )
+ };
+ final List list = Arrays.asList( array );
+
+ final NumberValidator validator =
NumberValidator.getCurrencyInstance( );
+ assertEquals( "incorrect currency format", format,
+ validator.getFormat( ) );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( 1d, ( (Number) i.next( ) ).doubleValue( ), 0.0001 );
+ assertEquals( 1.07d, ( (Number) i.next( ) ).doubleValue( ), 0.0001
);
+ assertEquals( -.45d, ( (Number) i.next( ) ).doubleValue( ), 0.0001
);
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testValidate_Percent( ) throws InvalidArgumentException
+ {
+ final NumberFormat format = NumberFormat.getPercentInstance( );
+
+ final Object[] array = new Object[]
+ {
+ format.format( .01 ), format.format( 1.07 ),
+ format.format( -.45 ), format.format( 0.001 )
+ };
+ final List list = Arrays.asList( array );
+ final Validator validator = NumberValidator.getPercentInstance( );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( 0.01d, ( (Number) i.next( ) ).doubleValue( ), 0.0001
);
+ assertEquals( 1.07d, ( (Number) i.next( ) ).doubleValue( ), 0.0001
);
+ assertEquals( -.45d, ( (Number) i.next( ) ).doubleValue( ), 0.0001
);
+ assertEquals( 0.00001d, ( (Number) i.next( ) ).doubleValue( ),
0.0001 );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ */
+ public void testValidate_Integer( ) throws InvalidArgumentException
+ {
+ final Object[] array = new Object[]{"1", "107", "-45"};
+ final List list = Arrays.asList( array );
+ final Validator validator = NumberValidator.getIntegerInstance( );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( 1d, ( (Number) i.next( ) ).doubleValue( ), 0.0001 );
+ assertEquals( 107d, ( (Number) i.next( ) ).doubleValue( ), 0.0001
);
+ assertEquals( -45d, ( (Number) i.next( ) ).doubleValue( ), 0.0001
);
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_ExcessChars( )
+ {
+ final Object[] array = new Object[]{"10DowningStreet"};
+ final List list = Arrays.asList( array );
+ final Validator validator = NumberValidator.getIntegerInstance( );
+
+ try
+ {
+ validator.validate( list );
+ fail( "InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( "10DowningStreet", e.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_Maximum( )
+ {
+ final Object[] array = new Object[]{"1", "107"};
+ final List list = Arrays.asList( array );
+ final NumberValidator validator =
NumberValidator.getIntegerInstance( );
+ Integer max = new Integer( 100 );
+
+ validator.setMaximum( max );
+
+ assertTrue( "no minimum set", validator.getMinimum( ) == null );
+ assertEquals( "incorrect maximum value", max, validator.getMaximum(
) );
+
+ try
+ {
+ validator.validate( list );
+ fail( "107 too big" );
+ }
+ catch( InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE,
"107" ),
+ ive.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testValidate_Minimum( )
+ {
+ final Object[] array = new Object[]{"107", "1"};
+ final List list = Arrays.asList( array );
+ final NumberValidator validator =
NumberValidator.getIntegerInstance( );
+ Integer min = new Integer( 100 );
+ validator.setMinimum( min );
+
+ assertTrue( "no maximum set", validator.getMaximum( ) == null );
+ assertEquals( "incorrect minimum value", min, validator.getMinimum(
) );
+
+ try
+ {
+ validator.validate( list );
+ fail( "1 too small" );
+ }
+ catch( InvalidArgumentException ive )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE, "1"
),
+ ive.getMessage( ) );
+ }
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/validation/TimeZoneTestSuite.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/validation/TimeZoneTestSuite.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/validation/TimeZoneTestSuite.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,45 +1,66 @@
-/**
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.dpml.cli.validation;
-
-import java.util.TimeZone;
-
-import junit.extensions.TestDecorator;
-
-import junit.framework.Test;
-import junit.framework.TestResult;
-
-public class TimeZoneTestSuite
- extends TestDecorator {
- private final TimeZone timeZone;
- private final TimeZone originalTimeZone;
-
- public TimeZoneTestSuite(String timeZone,
- Test test) {
- super(test);
- this.timeZone = TimeZone.getTimeZone(timeZone);
- this.originalTimeZone = TimeZone.getDefault();
- }
-
- public void run(TestResult testResult) {
- try {
- TimeZone.setDefault(timeZone);
- super.run(testResult);
- } finally {
- TimeZone.setDefault(originalTimeZone); // cleanup
- }
- }
-}
+/**
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.cli.validation;
+
+import junit.extensions.TestDecorator;
+
+import junit.framework.Test;
+import junit.framework.TestResult;
+
+import java.util.TimeZone;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class TimeZoneTestSuite extends TestDecorator
+{
+ private final TimeZone timeZone;
+ private final TimeZone originalTimeZone;
+
+ /**
+ * Creates a new TimeZoneTestSuite object.
+ *
+ * @param timeZone DOCUMENT ME!
+ * @param test DOCUMENT ME!
+ */
+ public TimeZoneTestSuite( String timeZone, Test test )
+ {
+ super( test );
+ this.timeZone = TimeZone.getTimeZone( timeZone );
+ this.originalTimeZone = TimeZone.getDefault( );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param testResult DOCUMENT ME!
+ */
+ public void run( TestResult testResult )
+ {
+ try
+ {
+ TimeZone.setDefault( timeZone );
+ super.run( testResult );
+ }
+ finally
+ {
+ TimeZone.setDefault( originalTimeZone ); // cleanup
+ }
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/validation/URLValidatorTest.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/validation/URLValidatorTest.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/validation/URLValidatorTest.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,92 +1,136 @@
-/**
- * Copyright 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 net.dpml.cli.validation;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import net.dpml.cli.resource.ResourceConstants;
-import net.dpml.cli.resource.ResourceHelper;
-
-public class URLValidatorTest
- extends TestCase {
- private static final ResourceHelper resources =
ResourceHelper.getResourceHelper();
-
- public void testValidate()
- throws InvalidArgumentException, MalformedURLException {
- final Object[] array = new Object[] { "http://www.apache.org/";,
"file:///etc" };
- final List list = Arrays.asList(array);
- final Validator validator = new URLValidator();
-
- validator.validate(list);
-
- final Iterator i = list.iterator();
- assertEquals(new URL("http://www.apache.org/";), i.next());
- assertEquals(new URL("file:///etc"), i.next());
- assertFalse(i.hasNext());
- }
-
- public void testMalformedURL()
- throws InvalidArgumentException, MalformedURLException {
- final Object[] array = new Object[] { "www.apache.org" };
- final List list = Arrays.asList(array);
- final Validator validator = new URLValidator();
-
- try {
- validator.validate(list);
- } catch (InvalidArgumentException e) {
-
assertEquals(resources.getMessage(ResourceConstants.URLVALIDATOR_MALFORMED_URL,
- new Object[] {
"www.apache.org" }), e.getMessage());
- }
- }
-
- public void testBadProtocol() {
- {
- final Object[] array = new Object[] { "http://www.apache.org/";,
"file:///etc" };
- final List list = Arrays.asList(array);
- final URLValidator validator = new URLValidator();
- validator.setProtocol("http");
-
- assertEquals("incorrect protocol", "http",
validator.getProtocol());
-
- try {
- validator.validate(list);
- fail("Expected InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals("file:///etc", e.getMessage());
- }
- }
-
- {
- final Object[] array = new Object[] { "http://www.apache.org/";,
"file:///etc" };
- final List list = Arrays.asList(array);
- final URLValidator validator = new URLValidator("http");
-
- try {
- validator.validate(list);
- fail("Expected InvalidArgumentException");
- } catch (InvalidArgumentException e) {
- assertEquals("file:///etc", e.getMessage());
- }
- }
- }
-}
+/**
+ * Copyright 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 net.dpml.cli.validation;
+
+import junit.framework.TestCase;
+
+import net.dpml.cli.resource.ResourceConstants;
+import net.dpml.cli.resource.ResourceHelper;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class URLValidatorTest extends TestCase
+{
+ private static final ResourceHelper resources =
ResourceHelper.getResourceHelper( );
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ * @throws MalformedURLException DOCUMENT ME!
+ */
+ public void testValidate( )
+ throws InvalidArgumentException, MalformedURLException
+ {
+ final Object[] array = new Object[]
+ {
+ "http://www.apache.org/";, "file:///etc"
+ };
+ final List list = Arrays.asList( array );
+ final Validator validator = new URLValidator( );
+
+ validator.validate( list );
+
+ final Iterator i = list.iterator( );
+ assertEquals( new URL( "http://www.apache.org/"; ), i.next( ) );
+ assertEquals( new URL( "file:///etc" ), i.next( ) );
+ assertFalse( i.hasNext( ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws InvalidArgumentException DOCUMENT ME!
+ * @throws MalformedURLException DOCUMENT ME!
+ */
+ public void testMalformedURL( )
+ throws InvalidArgumentException, MalformedURLException
+ {
+ final Object[] array = new Object[]{"www.apache.org"};
+ final List list = Arrays.asList( array );
+ final Validator validator = new URLValidator( );
+
+ try
+ {
+ validator.validate( list );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( resources.getMessage(
+ ResourceConstants.URLVALIDATOR_MALFORMED_URL,
+ new Object[]{"www.apache.org"} ), e.getMessage( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testBadProtocol( )
+ {
+ {
+ final Object[] array = new Object[]
+ {
+ "http://www.apache.org/";, "file:///etc"
+ };
+ final List list = Arrays.asList( array );
+ final URLValidator validator = new URLValidator( );
+ validator.setProtocol( "http" );
+
+ assertEquals( "incorrect protocol", "http",
+ validator.getProtocol( ) );
+
+ try
+ {
+ validator.validate( list );
+ fail( "Expected InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( "file:///etc", e.getMessage( ) );
+ }
+ }
+
+ {
+ final Object[] array = new Object[]
+ {
+ "http://www.apache.org/";, "file:///etc"
+ };
+ final List list = Arrays.asList( array );
+ final URLValidator validator = new URLValidator( "http" );
+
+ try
+ {
+ validator.validate( list );
+ fail( "Expected InvalidArgumentException" );
+ }
+ catch( InvalidArgumentException e )
+ {
+ assertEquals( "file:///etc", e.getMessage( ) );
+ }
+ }
+ }
+}

Modified:
trunk/main/util/cli/src/test/net/dpml/cli/validation/protect/ProtectedClass.java
===================================================================
---
trunk/main/util/cli/src/test/net/dpml/cli/validation/protect/ProtectedClass.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/cli/src/test/net/dpml/cli/validation/protect/ProtectedClass.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -1,22 +1,27 @@
-/**
- * Copyright 2003-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 net.dpml.cli.validation.protect;
-
-class ProtectedClass {
- protected ProtectedClass() {
- // used to test illegal attempts to load protected classes
- }
-}
+/**
+ * Copyright 2003-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 net.dpml.cli.validation.protect;
+
+class ProtectedClass
+{
+ /**
+ * Creates a new ProtectedClass object.
+ */
+ protected ProtectedClass( )
+ {
+ // used to test illegal attempts to load protected classes
+ }
+}

Modified:
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationBuilderTestCase.java
===================================================================
---
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationBuilderTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationBuilderTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -5,9 +5,9 @@
* 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.
@@ -16,24 +16,23 @@
*/
package net.dpml.configuration.test;

-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
import junit.framework.TestCase;

import net.dpml.configuration.Configuration;
import net.dpml.configuration.ConfigurationException;
import net.dpml.configuration.impl.DefaultConfigurationBuilder;

+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.xml.sax.InputSource;
-import org.xml.sax.EntityResolver;

+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;

/**
* Test that the <code>Configuration</code>s built by
@@ -41,255 +40,289 @@
*
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
*/
-public final class DefaultConfigurationBuilderTestCase
- extends TestCase
+public final class DefaultConfigurationBuilderTestCase extends TestCase
{
private static final String SIMPLE_FILE_NAME = "config_simple.xml";
private static final String NS_FILE_NAME = "config_namespaces.xml";
private static final String EXTERNAL_FILE_NAME =
"config_usingexternal.xml";
private static final String INNER_FILE_NAME = "config_inner.xml";
private static final String TEST_PATH = "io";
-
private DefaultConfigurationBuilder m_builder;
private DefaultConfigurationBuilder m_nsBuilder;
-
private File m_file;
private File m_nsFile;
private File m_fileWithExternalEntity;
private File m_innerXmlFile;
private File m_testDirectory;
+ private final String SIMPLE_XML = "<?xml version=\"1.0\" ?>" +
+ "<config boolAttr=\"true\" floatAttr=\"1.32\">" + " <elements-a>" +
+ " <element name=\"a\"/>" + " </elements-a>" +
+ " <elements-b>" + " <element name=\"b\"/> " +
+ " </elements-b>" + " <elements-b type=\"type-b\"/>" +
+ " <elements-c>" + " true" + " </elements-c>" + "</config>";
+ private final String NS_XML = "<?xml version=\"1.0\" ?>" +
"<conf:config" +
+ " boolAttr=\"true\" floatAttr=\"1.32\"" +
+ " xmlns:conf=\"http://conf.com\"; xmlns:a=\"http://a.com\";
xmlns:b=\"http://b.com\"; xmlns:c=\"http://c.com\"; xmlns:d=\"http://d.com\";
xmlns:e=\"http://e.com\";>" +
+ " <a:elements-a>" + " <c:element name=\"a\"/>" +
+ " </a:elements-a>" +
+ " <elements-b xmlns=\"http://defaultns.com\";>" +
+ " <element name=\"b\"/> " + " </elements-b>" +
+ " <b:elements-b type=\"type-b\"/>" + " <elements-c>" + " true"
+
+ " </elements-c>" + " <d:element>d:element</d:element>" +
+ " <e:element>e:element</e:element>" + "</conf:config>";
+ private final String spaceTrimmingCheckXML = "<?xml version=\"1.0\" ?>" +
+ " <config>" + " <trimmed-item>\n" + " value \n" +
+ " </trimmed-item>\n" + " <preserved-item
xml:space='preserve'>\n" +
+ " a space&#13; a CR, then a trailing space </preserved-item>\n" +
+ " <first-level-item xml:space='preserve'>\n" +
+ " <second-level-preserved> whitespace around
</second-level-preserved>\n" +
+ " </first-level-item>\n" + " <trimmed-again-item>\n" +
+ " value \n" + " </trimmed-again-item>\n" + "</config>";
+ private final String mixedContentXML = "<?xml version=\"1.0\" ?>" +
+ "<a>a<a/></a>";
+ private final String XML_WITH_EXTERNAL_ENTITY = "<?xml version=\"1.0\"
?>" +
+ "<!DOCTYPE document" + "[" + "<!ENTITY config SYSTEM \"inner.xml\">"
+
+ "]>" + "<config boolAttr=\"true\" floatAttr=\"1.32\">" +
+ " &config; " + "</config>";
+ private final String INNER_XML = " <elements-a>" +
+ " <element name=\"a\"/>" + " </elements-a>" +
+ " <elements-b>" + " <element name=\"b\"/> " +
+ " </elements-b>" + " <elements-b type=\"type-b\"/>" +
+ " <elements-c>" + " true" + " </elements-c>";

- private final String SIMPLE_XML =
- "<?xml version=\"1.0\" ?>"+
- "<config boolAttr=\"true\" floatAttr=\"1.32\">"+
- " <elements-a>"+
- " <element name=\"a\"/>"+
- " </elements-a>"+
- " <elements-b>"+
- " <element name=\"b\"/> "+
- " </elements-b>"+
- " <elements-b type=\"type-b\"/>"+
- " <elements-c>"+
- " true"+
- " </elements-c>"+
- "</config>";
+ /**
+ * Creates a new DefaultConfigurationBuilderTestCase object.
+ */
+ public DefaultConfigurationBuilderTestCase( )
+ {
+ this( "DefaultConfigurationBuilder Test Case" );
+ }

/**
+ * Creates a new DefaultConfigurationBuilderTestCase object.
+ *
+ * @param name DOCUMENT ME!
+ */
+ public DefaultConfigurationBuilderTestCase( final String name )
+ {
+ super( name );
+
+ File basedir = getWorkDir( );
+ m_testDirectory = ( new File( basedir, TEST_PATH )
).getAbsoluteFile( );
+
+ if( !m_testDirectory.exists( ) )
+ {
+ m_testDirectory.mkdirs( );
+ }
+ }
+
+ /**
* These assertions apply when the default builder is used to create a
* Configuration from <code>simpleXML</code>, ie namespace
* support is disabled.
*/
- private void simpleAssertions(Configuration conf)
+ private void simpleAssertions( Configuration conf )
throws ConfigurationException
{
- assertEquals( "config", conf.getName() );
- assertEquals( "getNamespace() should default to \"\"", "",
conf.getNamespace() );
- try {
- conf.getValue();
- fail( "Should throw a ConfigurationException, as this element"+
- "contains child elements, not a value" );
- } catch ( ConfigurationException e )
- {}
+ assertEquals( "config", conf.getName( ) );
+ assertEquals( "getNamespace() should default to \"\"", "",
+ conf.getNamespace( ) );

+ try
+ {
+ conf.getValue( );
+ fail( "Should throw a ConfigurationException, as this element" +
+ "contains child elements, not a value" );
+ }
+ catch( ConfigurationException e )
+ {
+ }
+
Configuration[] children;
- children = conf.getChildren();
+ children = conf.getChildren( );
assertEquals( 4, children.length );
- assertEquals( "elements-a", children[0].getName() );
- assertEquals( "elements-b", children[1].getName() );
- assertEquals( "b", children[1].getChild("element",
false).getAttribute("name") );
- assertEquals( "elements-b", children[2].getName() );
- assertEquals( "elements-c", children[3].getName() );
+ assertEquals( "elements-a", children[0].getName( ) );
+ assertEquals( "elements-b", children[1].getName( ) );
+ assertEquals( "b",
+ children[1].getChild( "element", false ).getAttribute( "name" )
);
+ assertEquals( "elements-b", children[2].getName( ) );
+ assertEquals( "elements-c", children[3].getName( ) );

- final String[] attrNames = conf.getAttributeNames();
+ final String[] attrNames = conf.getAttributeNames( );
assertEquals( 2, attrNames.length );
- assertEquals( "default", conf.getAttribute("nonexistent", "default")
);
- assertEquals( true, conf.getAttributeAsBoolean("boolAttr") );
- assertEquals( (float)1.32, conf.getAttributeAsFloat("floatAttr"),
0.0 );
+ assertEquals( "default", conf.getAttribute( "nonexistent", "default"
) );
+ assertEquals( true, conf.getAttributeAsBoolean( "boolAttr" ) );
+ assertEquals( (float) 1.32, conf.getAttributeAsFloat( "floatAttr" ),
0.0 );

// Check that the auto-node-creation feature is working correctly.
- assertEquals(
- "When a non-existent child is requested, a blank node
should be created",
- "nonexistent",
- conf.getChild( "nonexistent" ).getName()
- );
- assertEquals(
- "When a non-existent child is requested, a blank node
should be created",
- "baz",
- conf.getChild( "foo"
).getChild("bar").getChild("baz").getName()
- );
- try {
- conf.getChild("nonexistent").getValue();
+ assertEquals( "When a non-existent child is requested, a blank node
should be created",
+ "nonexistent", conf.getChild( "nonexistent" ).getName( ) );
+ assertEquals( "When a non-existent child is requested, a blank node
should be created",
+ "baz",
+ conf.getChild( "foo" ).getChild( "bar" ).getChild( "baz"
).getName( ) );
+
+ try
+ {
+ conf.getChild( "nonexistent" ).getValue( );
fail( "Auto-created child nodes should not have a value" );
- } catch ( ConfigurationException e )
- {}
- assertEquals( "Turning auto-node-creation off failed", null,
conf.getChild( "nonexistent", false )
- );
- assertEquals( "Standard getChild() lookup failed", "elements-b",
conf.getChild( "elements-b", false ).getName() );
- assertEquals( "Boolean value surrounded by whitespace failed", true,
conf.getChild("elements-c").getValueAsBoolean( false ) );
- assertEquals( "A value-containing element should have no child
nodes", 0, conf.getChild("elements-c").getChildren().length );
+ }
+ catch( ConfigurationException e )
+ {
+ }
+
+ assertEquals( "Turning auto-node-creation off failed", null,
+ conf.getChild( "nonexistent", false ) );
+ assertEquals( "Standard getChild() lookup failed", "elements-b",
+ conf.getChild( "elements-b", false ).getName( ) );
+ assertEquals( "Boolean value surrounded by whitespace failed", true,
+ conf.getChild( "elements-c" ).getValueAsBoolean( false ) );
+ assertEquals( "A value-containing element should have no child
nodes",
+ 0, conf.getChild( "elements-c" ).getChildren( ).length );
}

- private final String NS_XML =
- "<?xml version=\"1.0\" ?>"+
- "<conf:config"+
- " boolAttr=\"true\" floatAttr=\"1.32\""+
- " xmlns:conf=\"http://conf.com\"; xmlns:a=\"http://a.com\";
xmlns:b=\"http://b.com\"; xmlns:c=\"http://c.com\"; xmlns:d=\"http://d.com\";
xmlns:e=\"http://e.com\";>"+
- " <a:elements-a>"+
- " <c:element name=\"a\"/>"+
- " </a:elements-a>"+
- " <elements-b xmlns=\"http://defaultns.com\";>"+
- " <element name=\"b\"/> "+
- " </elements-b>"+
- " <b:elements-b type=\"type-b\"/>"+
- " <elements-c>"+
- " true"+
- " </elements-c>"+
- " <d:element>d:element</d:element>"+
- " <e:element>e:element</e:element>"+
- "</conf:config>";
-
/**
* These assertions apply when the default builder is used to create a
* Configuration from <code>nsXML</code>, ie namespace support is
disabled,
- * but the XML uses namespaces.
+ * but the XML uses namespaces.
*/
- private void simpleAssertionsNS(Configuration conf)
+ private void simpleAssertionsNS( Configuration conf )
throws ConfigurationException
{
- assertEquals( "conf:config", conf.getName() );
- assertEquals( "getNamespace() should default to \"\"", "",
conf.getNamespace() );
- try {
- conf.getValue();
- fail( "Should throw a ConfigurationException, as this element"+
- "contains child elements, not a value" );
- } catch ( ConfigurationException e )
- {}
+ assertEquals( "conf:config", conf.getName( ) );
+ assertEquals( "getNamespace() should default to \"\"", "",
+ conf.getNamespace( ) );

+ try
+ {
+ conf.getValue( );
+ fail( "Should throw a ConfigurationException, as this element" +
+ "contains child elements, not a value" );
+ }
+ catch( ConfigurationException e )
+ {
+ }
+
Configuration[] children;
- children = conf.getChildren();
+ children = conf.getChildren( );
assertEquals( 6, children.length );
- assertEquals( "a:elements-a", children[0].getName() );
- assertEquals( "elements-b", children[1].getName() );
- assertEquals( "b", children[1].getChild("element",
false).getAttribute("name") );
- assertEquals( "b:elements-b", children[2].getName() );
- assertEquals( "elements-c", children[3].getName() );
+ assertEquals( "a:elements-a", children[0].getName( ) );
+ assertEquals( "elements-b", children[1].getName( ) );
+ assertEquals( "b",
+ children[1].getChild( "element", false ).getAttribute( "name" )
);
+ assertEquals( "b:elements-b", children[2].getName( ) );
+ assertEquals( "elements-c", children[3].getName( ) );

- final String[] attrNames = conf.getAttributeNames();
+ final String[] attrNames = conf.getAttributeNames( );
assertEquals( 8, attrNames.length );
- assertEquals( "true", conf.getAttribute("boolAttr", null) );
- assertEquals( true, conf.getAttributeAsBoolean("boolAttr") );
- assertEquals( (float)1.32, conf.getAttributeAsFloat("floatAttr"),
0.0 );
- assertEquals( "http://conf.com";, conf.getAttribute("xmlns:conf") );
- assertEquals( "http://a.com";, conf.getAttribute("xmlns:a") );
- assertEquals( "http://b.com";, conf.getAttribute("xmlns:b") );
- assertEquals( "http://c.com";, conf.getAttribute("xmlns:c") );
+ assertEquals( "true", conf.getAttribute( "boolAttr", null ) );
+ assertEquals( true, conf.getAttributeAsBoolean( "boolAttr" ) );
+ assertEquals( (float) 1.32, conf.getAttributeAsFloat( "floatAttr" ),
0.0 );
+ assertEquals( "http://conf.com";, conf.getAttribute( "xmlns:conf" ) );
+ assertEquals( "http://a.com";, conf.getAttribute( "xmlns:a" ) );
+ assertEquals( "http://b.com";, conf.getAttribute( "xmlns:b" ) );
+ assertEquals( "http://c.com";, conf.getAttribute( "xmlns:c" ) );

// Check that the auto-node-creation feature is working correctly.
- assertEquals(
- "When a non-existent child is requested, a blank node
should be created",
- "nonexistent",
- conf.getChild( "nonexistent" ).getName()
- );
- assertEquals(
- "When a non-existent child is requested, a blank node
should be created",
- "baz",
- conf.getChild( "foo"
).getChild("bar").getChild("baz").getName()
- );
- try {
- conf.getChild("nonexistent").getValue();
+ assertEquals( "When a non-existent child is requested, a blank node
should be created",
+ "nonexistent", conf.getChild( "nonexistent" ).getName( ) );
+ assertEquals( "When a non-existent child is requested, a blank node
should be created",
+ "baz",
+ conf.getChild( "foo" ).getChild( "bar" ).getChild( "baz"
).getName( ) );
+
+ try
+ {
+ conf.getChild( "nonexistent" ).getValue( );
fail( "Auto-created child nodes should not have a value" );
- } catch ( ConfigurationException e )
- {}
- assertEquals( "Turning auto-node-creation off failed", null,
conf.getChild( "nonexistent", false )
- );
- assertEquals( "Standard getChild() lookup failed", "b:elements-b",
conf.getChild( "b:elements-b", false ).getName() );
- assertEquals( "Boolean value surrounded by whitespace failed", true,
conf.getChild("elements-c").getValueAsBoolean( false ) );
- assertEquals( "A value-containing element should have no child
nodes", 0, conf.getChild("elements-c").getChildren().length );
-
- assertEquals( "d:element", conf.getChild("d:element").getValue() );
- assertEquals( "e:element", conf.getChild("e:element").getValue() );
+ }
+ catch( ConfigurationException e )
+ {
+ }
+
+ assertEquals( "Turning auto-node-creation off failed", null,
+ conf.getChild( "nonexistent", false ) );
+ assertEquals( "Standard getChild() lookup failed", "b:elements-b",
+ conf.getChild( "b:elements-b", false ).getName( ) );
+ assertEquals( "Boolean value surrounded by whitespace failed", true,
+ conf.getChild( "elements-c" ).getValueAsBoolean( false ) );
+ assertEquals( "A value-containing element should have no child
nodes",
+ 0, conf.getChild( "elements-c" ).getChildren( ).length );
+
+ assertEquals( "d:element", conf.getChild( "d:element" ).getValue( )
);
+ assertEquals( "e:element", conf.getChild( "e:element" ).getValue( )
);
}

-
/**
* These assertions apply when the namespace-enabled builder is used to
* create a Configuration from <code>nsXML</code>, ie namespace support
is
- * enabled, and the XML uses namespaces.
+ * enabled, and the XML uses namespaces.
*/
- private void nsAssertions(Configuration conf)
+ private void nsAssertions( Configuration conf )
throws ConfigurationException
{
- assertEquals( "config", conf.getName() );
- assertEquals( "Namespace not set correctly", "http://conf.com";,
conf.getNamespace() );
- try {
- conf.getValue();
- fail( "Should throw a ConfigurationException, as this element"+
- "contains child elements, not a value" );
- } catch ( ConfigurationException e )
- {}
+ assertEquals( "config", conf.getName( ) );
+ assertEquals( "Namespace not set correctly", "http://conf.com";,
+ conf.getNamespace( ) );

+ try
+ {
+ conf.getValue( );
+ fail( "Should throw a ConfigurationException, as this element" +
+ "contains child elements, not a value" );
+ }
+ catch( ConfigurationException e )
+ {
+ }
+
Configuration[] children;
- children = conf.getChildren();
+ children = conf.getChildren( );
assertEquals( 6, children.length );
- assertEquals( "elements-a", children[0].getName() );
- assertEquals( "http://a.com";, children[0].getNamespace() );
- assertEquals( "elements-b", children[1].getName() );
- assertEquals( "http://defaultns.com";, children[1].getNamespace() );
- assertEquals( "b", children[1].getChild("element",
false).getAttribute("name") );
- assertEquals( "elements-b", children[2].getName() );
- assertEquals( "http://b.com";, children[2].getNamespace() );
- assertEquals( "elements-c", children[3].getName() );
- assertEquals( "", children[3].getNamespace() );
+ assertEquals( "elements-a", children[0].getName( ) );
+ assertEquals( "http://a.com";, children[0].getNamespace( ) );
+ assertEquals( "elements-b", children[1].getName( ) );
+ assertEquals( "http://defaultns.com";, children[1].getNamespace( ) );
+ assertEquals( "b",
+ children[1].getChild( "element", false ).getAttribute( "name" )
);
+ assertEquals( "elements-b", children[2].getName( ) );
+ assertEquals( "http://b.com";, children[2].getNamespace( ) );
+ assertEquals( "elements-c", children[3].getName( ) );
+ assertEquals( "", children[3].getNamespace( ) );

- final String[] attrNames = conf.getAttributeNames();
+ final String[] attrNames = conf.getAttributeNames( );
assertEquals( 2, attrNames.length ); // the other 4 are xmlns and so
shouldn't appear
- assertEquals( "true", conf.getAttribute("boolAttr", null) );
- assertEquals( true, conf.getAttributeAsBoolean("boolAttr") );
- assertEquals( (float)1.32, conf.getAttributeAsFloat("floatAttr"),
0.0 );
+ assertEquals( "true", conf.getAttribute( "boolAttr", null ) );
+ assertEquals( true, conf.getAttributeAsBoolean( "boolAttr" ) );
+ assertEquals( (float) 1.32, conf.getAttributeAsFloat( "floatAttr" ),
0.0 );

// Check that the auto-node-creation feature is working correctly.
- assertEquals(
- "When a non-existent child is requested, a blank node
should be created",
- "nonexistent",
- conf.getChild( "nonexistent" ).getName()
- );
- assertEquals(
- "When a non-existent child is requested, a blank node
should be created",
- "baz",
- conf.getChild( "foo"
).getChild("bar").getChild("baz").getName()
- );
- try {
- conf.getChild("nonexistent").getValue();
- fail( "Auto-created child nodes should not have a value" );
- } catch ( ConfigurationException e )
- {}
- assertEquals( "Turning auto-node-creation off failed", null,
conf.getChild( "nonexistent", false )
- );
- assertEquals( "Standard getChild() lookup failed", "elements-b",
conf.getChild( "elements-b", false ).getName() );
- assertEquals( "Boolean value surrounded by whitespace failed", true,
conf.getChild("elements-c").getValueAsBoolean( false ) );
- assertEquals( "A value-containing element should have no child
nodes", 0, conf.getChild("elements-c").getChildren().length );
- }
+ assertEquals( "When a non-existent child is requested, a blank node
should be created",
+ "nonexistent", conf.getChild( "nonexistent" ).getName( ) );
+ assertEquals( "When a non-existent child is requested, a blank node
should be created",
+ "baz",
+ conf.getChild( "foo" ).getChild( "bar" ).getChild( "baz"
).getName( ) );

-
- public DefaultConfigurationBuilderTestCase()
- {
- this("DefaultConfigurationBuilder Test Case");
- }
-
- public DefaultConfigurationBuilderTestCase( final String name )
- {
- super( name );
- File basedir = getWorkDir();
- m_testDirectory = (new File( basedir, TEST_PATH )).getAbsoluteFile();
- if( !m_testDirectory.exists() )
+ try
{
- m_testDirectory.mkdirs();
+ conf.getChild( "nonexistent" ).getValue( );
+ fail( "Auto-created child nodes should not have a value" );
}
+ catch( ConfigurationException e )
+ {
+ }
+
+ assertEquals( "Turning auto-node-creation off failed", null,
+ conf.getChild( "nonexistent", false ) );
+ assertEquals( "Standard getChild() lookup failed", "elements-b",
+ conf.getChild( "elements-b", false ).getName( ) );
+ assertEquals( "Boolean value surrounded by whitespace failed", true,
+ conf.getChild( "elements-c" ).getValueAsBoolean( false ) );
+ assertEquals( "A value-containing element should have no child
nodes",
+ 0, conf.getChild( "elements-c" ).getChildren( ).length );
}

- private File getWorkDir()
+ private File getWorkDir( )
{
String path = System.getProperty( "project.test.dir" );
+
if( null != path )
{
return new File( path );
@@ -297,64 +330,83 @@
else
{
path = System.getProperty( "basedir" );
+
File root = new File( path );
+
return new File( root, "target/test" );
}
}

-
- protected void setUp()
- throws Exception
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ protected void setUp( ) throws Exception
{
m_file = new File( m_testDirectory, SIMPLE_FILE_NAME );
m_nsFile = new File( m_testDirectory, NS_FILE_NAME );
m_fileWithExternalEntity = new File( m_testDirectory,
EXTERNAL_FILE_NAME );
m_innerXmlFile = new File( m_testDirectory, INNER_FILE_NAME );
-
+
FileWriter writer = new FileWriter( m_file );
writer.write( SIMPLE_XML );
- writer.close();
+ writer.close( );
writer = new FileWriter( m_nsFile );
writer.write( NS_XML );
- writer.close();
+ writer.close( );
writer = new FileWriter( m_fileWithExternalEntity );
writer.write( XML_WITH_EXTERNAL_ENTITY );
- writer.close();
+ writer.close( );
writer = new FileWriter( m_innerXmlFile );
writer.write( INNER_XML );
- writer.close();
+ writer.close( );
}

- protected void tearDown()
- throws Exception
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ protected void tearDown( ) throws Exception
{
m_builder = null;
m_nsBuilder = null;
}

- public void testBuildFromFileName()
- throws Exception
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testBuildFromFileName( ) throws Exception
{
- m_builder = new DefaultConfigurationBuilder();
- m_nsBuilder = new DefaultConfigurationBuilder(true); // switch on
namespace support
- File basedir = getWorkDir();
- File testFile = new File( basedir, TEST_PATH );
- File simple = new File( testFile, SIMPLE_FILE_NAME );
+ m_builder = new DefaultConfigurationBuilder( );
+ m_nsBuilder = new DefaultConfigurationBuilder( true ); // switch on
namespace support

- Configuration conf = m_builder.buildFromFile( simple.toString() );
- simpleAssertions( conf );
- conf = m_builder.buildFromFile( new File( testFile, NS_FILE_NAME
).toString() );
- simpleAssertionsNS( conf );
- conf = m_nsBuilder.buildFromFile( new File( testFile, NS_FILE_NAME
).toString() );
- nsAssertions( conf );
+ File basedir = getWorkDir( );
+ File testFile = new File( basedir, TEST_PATH );
+ File simple = new File( testFile, SIMPLE_FILE_NAME );
+
+ Configuration conf = m_builder.buildFromFile( simple.toString( ) );
+ simpleAssertions( conf );
+ conf = m_builder.buildFromFile( new File( testFile, NS_FILE_NAME
).toString( ) );
+ simpleAssertionsNS( conf );
+ conf = m_nsBuilder.buildFromFile( new File( testFile, NS_FILE_NAME
).toString( ) );
+ nsAssertions( conf );
}

- public void testBuildFromFile()
- throws Exception
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testBuildFromFile( ) throws Exception
{
- m_builder = new DefaultConfigurationBuilder();
- m_nsBuilder = new DefaultConfigurationBuilder(true); // switch on
namespace support
- Configuration conf = m_builder.buildFromFile( m_file );
+ m_builder = new DefaultConfigurationBuilder( );
+ m_nsBuilder = new DefaultConfigurationBuilder( true ); // switch on
namespace support
+
+ Configuration conf = m_builder.buildFromFile( m_file );
simpleAssertions( conf );
conf = m_builder.buildFromFile( m_nsFile );
simpleAssertionsNS( conf );
@@ -362,12 +414,17 @@
nsAssertions( conf );
}

- public void testBuild()
- throws Exception
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testBuild( ) throws Exception
{
- m_builder = new DefaultConfigurationBuilder();
- m_nsBuilder = new DefaultConfigurationBuilder(true); // switch on
namespace support
- Configuration conf = m_builder.build( m_file.toURL().toString() );
+ m_builder = new DefaultConfigurationBuilder( );
+ m_nsBuilder = new DefaultConfigurationBuilder( true ); // switch on
namespace support
+
+ Configuration conf = m_builder.build( m_file.toURL( ).toString( )
);
simpleAssertions( conf );
conf = m_builder.buildFromFile( m_nsFile );
simpleAssertionsNS( conf );
@@ -375,111 +432,90 @@
nsAssertions( conf );
}

- private final String spaceTrimmingCheckXML =
- "<?xml version=\"1.0\" ?>"+
- " <config>"+
- " <trimmed-item>\n"+
- " value \n"+
- " </trimmed-item>\n"+
- " <preserved-item xml:space='preserve'>\n"+
- " a space&#13; a CR, then a trailing space </preserved-item>\n"+
- " <first-level-item xml:space='preserve'>\n"+
- " <second-level-preserved> whitespace around
</second-level-preserved>\n"+
- " </first-level-item>\n"+
- " <trimmed-again-item>\n"+
- " value \n"+
- " </trimmed-again-item>\n"+
- "</config>";
-
/**
* Checks that whitespace is normally stripped but preserved if
* space preserving processing instructions are present.
*/
- public void testSpaceTrimming()
- throws Exception
+ public void testSpaceTrimming( ) throws Exception
{
- DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
- InputStream in = new ByteArrayInputStream(
spaceTrimmingCheckXML.getBytes() );
+ DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder( );
+ InputStream in = new ByteArrayInputStream(
spaceTrimmingCheckXML.getBytes( ) );
Configuration conf = builder.build( in );
- assertEquals( "Value is trimmed by default",
- "value",
- conf.getChild( "trimmed-item" ).getValue() );
+ assertEquals( "Value is trimmed by default", "value",
+ conf.getChild( "trimmed-item" ).getValue( ) );
assertEquals( "After trimming turned off value is preserved",
- "\n a space\r a CR, then a trailing space ",
- conf.getChild( "preserved-item" ).getValue() );
+ "\n a space\r a CR, then a trailing space ",
+ conf.getChild( "preserved-item" ).getValue( ) );
assertEquals( "Trimming two levels deep works too",
- " whitespace around ",
- conf.getChild( "first-level-item" )
- .getChild( "second-level-preserved" ).getValue() );
- assertEquals( "Trimming turned back on",
- "value",
- conf.getChild( "trimmed-again-item" ).getValue() );
+ " whitespace around ",
+ conf.getChild( "first-level-item" )
+ .getChild( "second-level-preserved" ).getValue( ) );
+ assertEquals( "Trimming turned back on", "value",
+ conf.getChild( "trimmed-again-item" ).getValue( ) );
}

-
- private final String mixedContentXML =
- "<?xml version=\"1.0\" ?>"+
- "<a>a<a/></a>"
- ;
- public void testMixedContentDetection()
- throws Exception
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testMixedContentDetection( ) throws Exception
{
- DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
- InputStream in = new ByteArrayInputStream(
mixedContentXML.getBytes() );
+ DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder( );
+ InputStream in = new ByteArrayInputStream( mixedContentXML.getBytes(
) );
+
try
{
builder.build( in );
- fail ("Must fail on mixed content");
- } catch ( SAXException e )
- {}
+ fail( "Must fail on mixed content" );
+ }
+ catch( SAXException e )
+ {
+ }
}

- private final String XML_WITH_EXTERNAL_ENTITY =
- "<?xml version=\"1.0\" ?>"+
- "<!DOCTYPE document"+
- "["+
- "<!ENTITY config SYSTEM \"inner.xml\">"+
- "]>"+
- "<config boolAttr=\"true\" floatAttr=\"1.32\">"+
- " &config; "+
- "</config>";
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testExternalEntity( ) throws Exception
+ {
+ DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder( );

- private final String INNER_XML =
- " <elements-a>"+
- " <element name=\"a\"/>"+
- " </elements-a>"+
- " <elements-b>"+
- " <element name=\"b\"/> "+
- " </elements-b>"+
- " <elements-b type=\"type-b\"/>"+
- " <elements-c>"+
- " true"+
- " </elements-c>";
-
- public void testExternalEntity() throws Exception
- {
- DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
-
- MyEntityResolver customResolver = new MyEntityResolver();
-
+ MyEntityResolver customResolver = new MyEntityResolver( );
+
builder.setEntityResolver( customResolver );
- File basedir = getWorkDir();
+
+ File basedir = getWorkDir( );
File testFile = new File( basedir, TEST_PATH );
File external = new File( testFile, EXTERNAL_FILE_NAME );
- Configuration conf = builder.buildFromFile( external );
+ Configuration conf = builder.buildFromFile( external );
simpleAssertions( conf );
}
-
+
/**
* Mock implementation for EntityResolver
*/
class MyEntityResolver implements EntityResolver
{
- public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
+ /**
+ * DOCUMENT ME!
+ *
+ * @param publicId DOCUMENT ME!
+ * @param systemId DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws SAXException DOCUMENT ME!
+ * @throws IOException DOCUMENT ME!
+ */
+ public InputSource resolveEntity( String publicId, String systemId )
+ throws SAXException, IOException
{
Reader reader = new FileReader( m_innerXmlFile );
-
- return new InputSource(reader);
+
+ return new InputSource( reader );
}
}
}

Modified:
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationSerializerTestCase.java
===================================================================
---
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationSerializerTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationSerializerTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -5,9 +5,9 @@
* 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.
@@ -16,13 +16,13 @@
*/
package net.dpml.configuration.test;

-import java.io.File;
-
import junit.framework.TestCase;

import net.dpml.configuration.impl.DefaultConfiguration;
import net.dpml.configuration.impl.DefaultConfigurationSerializer;

+import java.io.File;
+
/**
* Test the basic public methods of DefaultConfigurationSerializer.
*
@@ -32,36 +32,47 @@
{
private File testDirectory;
private File testDirectory2;
-
- public DefaultConfigurationSerializerTestCase()
+
+ /**
+ * Creates a new DefaultConfigurationSerializerTestCase object.
+ */
+ public DefaultConfigurationSerializerTestCase( )
{
- this("DefaultConfigurationSerializer Test Case ");
+ this( "DefaultConfigurationSerializer Test Case " );
}

+ /**
+ * Creates a new DefaultConfigurationSerializerTestCase object.
+ *
+ * @param name DOCUMENT ME!
+ */
public DefaultConfigurationSerializerTestCase( final String name )
{
super( name );
}
-
- public void setUp() {
- File basedir = getWorkDir();
- testDirectory = (new File( basedir, "io" ) ).getAbsoluteFile();
- testDirectory2 =
- new File(
- basedir,
- "DefaultConfigurationSerializerTestCase" ).getAbsoluteFile();

- if( !testDirectory.exists() )
+ /**
+ * DOCUMENT ME!
+ */
+ public void setUp( )
+ {
+ File basedir = getWorkDir( );
+ testDirectory = ( new File( basedir, "io" ) ).getAbsoluteFile( );
+ testDirectory2 = new File( basedir,
+ "DefaultConfigurationSerializerTestCase" ).getAbsoluteFile(
);
+
+ if( !testDirectory.exists( ) )
{
- testDirectory.mkdirs();
+ testDirectory.mkdirs( );
}
-
- assertTrue ( !testDirectory2.exists() );
+
+ assertTrue( !testDirectory2.exists( ) );
}

- private File getWorkDir()
+ private File getWorkDir( )
{
String path = System.getProperty( "project.test.dir" );
+
if( null != path )
{
return new File( path );
@@ -69,7 +80,9 @@
else
{
path = System.getProperty( "basedir" );
+
File root = new File( path );
+
return new File( root, "target/test" );
}
}
@@ -78,27 +91,23 @@
* Checks that the <code>serializeToFile</code> method closes the output
stream
* when it is done.
*/
- public void testSerializeToFile() throws Exception
+ public void testSerializeToFile( ) throws Exception
{
- DefaultConfiguration config = new DefaultConfiguration("root", "");
+ DefaultConfiguration config = new DefaultConfiguration( "root", "" );
config.setAttribute( "attribute", "value" );
-
- File file = new File( testDirectory,
"DefaultConfigurationSerializerTestCase.xml" );
-
- DefaultConfigurationSerializer serializer = new
DefaultConfigurationSerializer();
+
+ File file = new File( testDirectory,
+ "DefaultConfigurationSerializerTestCase.xml" );
+
+ DefaultConfigurationSerializer serializer = new
DefaultConfigurationSerializer( );
serializer.serializeToFile( file, config );
-
+
//
// This will not work if the serializeToFile method keeps the stream
open.
//
assertTrue( testDirectory.renameTo( testDirectory2 ) );
assertTrue( testDirectory2.renameTo( testDirectory ) );
-
- file.delete();
+
+ file.delete( );
}
}
-
-
-
-
-

Modified:
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationTestCase.java
===================================================================
---
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/DefaultConfigurationTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -5,9 +5,9 @@
* 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.
@@ -32,71 +32,105 @@
public final class DefaultConfigurationTestCase extends TestCase
{
private DefaultConfiguration m_configuration;
-
- public DefaultConfigurationTestCase()
+
+ /**
+ * Creates a new DefaultConfigurationTestCase object.
+ */
+ public DefaultConfigurationTestCase( )
{
- this("DefaultConfiguration Test Case");
+ this( "DefaultConfiguration Test Case" );
}
-
+
+ /**
+ * Creates a new DefaultConfigurationTestCase object.
+ *
+ * @param name DOCUMENT ME!
+ */
public DefaultConfigurationTestCase( String name )
{
super( name );
}
-
- public void setUp()
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void setUp( )
{
m_configuration = new DefaultConfiguration( "a", "b" );
}
-
- public void tearDowm()
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void tearDowm( )
{
m_configuration = null;
}
-
- public void testGetValue()
- throws Exception
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testGetValue( ) throws Exception
{
final String orgValue = "Original String";
m_configuration.setValue( orgValue );
- assertEquals( orgValue, m_configuration.getValue() );
+ assertEquals( orgValue, m_configuration.getValue( ) );
}
-
- public void testGetValueAsInteger()
- throws Exception
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testGetValueAsInteger( ) throws Exception
{
final int orgValue = 55;
final String strValue = Integer.toHexString( orgValue );
m_configuration.setValue( "0x" + strValue );
- assertEquals( orgValue, m_configuration.getValueAsInteger() );
+ assertEquals( orgValue, m_configuration.getValueAsInteger( ) );
}
-
- public void testGetValueAsBoolen()
- throws Exception
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testGetValueAsBoolen( ) throws Exception
{
final boolean b = true;
- m_configuration.setValue("TrUe");
- assertEquals( b, m_configuration.getValueAsBoolean() );
+ m_configuration.setValue( "TrUe" );
+ assertEquals( b, m_configuration.getValueAsBoolean( ) );
}
-
- public void testGetAttribute()
- throws Exception
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testGetAttribute( ) throws Exception
{
final String key = "key";
final String value = "original value";
final String defaultStr = "default";
m_configuration.setAttribute( key, value );
assertEquals( value, m_configuration.getAttribute( key, defaultStr )
);
- assertEquals(defaultStr , m_configuration.getAttribute( "newKey",
defaultStr ) );
+ assertEquals( defaultStr,
+ m_configuration.getAttribute( "newKey", defaultStr ) );
}
-
- public void testMakeReadOnly()
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testMakeReadOnly( )
{
final String key = "key";
final String value = "original value";
String exception = "exception not thrown";
- final String exceptionStr ="Configuration is read only";
- m_configuration.makeReadOnly();
-
+ final String exceptionStr = "Configuration is read only";
+ m_configuration.makeReadOnly( );
+
try
{
m_configuration.setAttribute( key, value );
@@ -105,178 +139,228 @@
{
exception = exceptionStr;
}
-
+
assertEquals( exception, exceptionStr );
}
-
- public void testAddRemoveChild()
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void testAddRemoveChild( )
{
final String childName = "child";
- final Configuration child = new DefaultConfiguration( childName,
"child location" );
-
+ final Configuration child = new DefaultConfiguration( childName,
+ "child location" );
+
m_configuration.addChild( child );
assertEquals( child, m_configuration.getChild( childName ) );
-
+
m_configuration.removeChild( child );
assertEquals( null, m_configuration.getChild( childName, false ) );
}
-
- public void testCopying() throws Exception
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testCopying( ) throws Exception
{
- DefaultConfiguration root = new DefaultConfiguration( "root", "0:0",
"http://root";, "root" );
+ DefaultConfiguration root = new DefaultConfiguration( "root", "0:0",
+ "http://root";, "root" );
root.setAttribute( "attr1", "1" );
root.setAttribute( "attr2", "2" );
-
- DefaultConfiguration child1 = new DefaultConfiguration( "child1",
"0:1", "http://root/child1";, "child1" );
- DefaultConfiguration child2 = new DefaultConfiguration( "child2",
"0:2", "http://root/child2";, "child2" );
-
+
+ DefaultConfiguration child1 = new DefaultConfiguration( "child1",
+ "0:1", "http://root/child1";, "child1" );
+ DefaultConfiguration child2 = new DefaultConfiguration( "child2",
+ "0:2", "http://root/child2";, "child2" );
+
root.addChild( child1 );
root.addChild( child2 );
-
- root.makeReadOnly();
-
+
+ root.makeReadOnly( );
+
DefaultConfiguration modifiableRoot = new DefaultConfiguration( root
);
assertTrue( ConfigurationUtil.equals( root, modifiableRoot ) );
-
+
modifiableRoot.setAttribute( "attr1", "0" );
-
+
assertEquals( "0", modifiableRoot.getAttribute( "attr1" ) );
-
- DefaultConfiguration modifiableChild1 = new DefaultConfiguration(
root.getChild("child1") );
+
+ DefaultConfiguration modifiableChild1 = new DefaultConfiguration(
root.getChild(
+ "child1" ) );
modifiableChild1.setValue( "1" );
-
- modifiableRoot.removeChild( modifiableRoot.getChild("child1") );
+
+ modifiableRoot.removeChild( modifiableRoot.getChild( "child1" ) );
modifiableRoot.addChild( modifiableChild1 );
-
- assertEquals( "1", modifiableRoot.getChild( "child1" ).getValue() );
+
+ assertEquals( "1", modifiableRoot.getChild( "child1" ).getValue( )
);
}
-
- public void testConvenienceSetters() throws Exception
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testConvenienceSetters( ) throws Exception
{
- DefaultConfiguration config = new DefaultConfiguration( "root",
"0:0", "http://root";, "root" );
+ DefaultConfiguration config = new DefaultConfiguration( "root",
"0:0",
+ "http://root";, "root" );
config.setAttribute( "integer", 12 );
config.setAttribute( "long", 8000000000L );
config.setAttribute( "float", 1.23f );
config.setAttribute( "boolean", true );
config.setAttribute( "string", "string" );
-
- assertEquals( "12", config.getAttribute("integer") );
- assertEquals( "8000000000", config.getAttribute("long") );
- assertEquals( 1.23, config.getAttributeAsFloat("float"), 0.01 );
- assertEquals( "string", config.getAttribute("string") );
- assertEquals( "true", config.getAttribute("boolean") );
-
- assertEquals( 12, config.getAttributeAsInteger("integer") );
- assertEquals( 8000000000L, config.getAttributeAsLong("long") );
- assertEquals( "string", config.getAttribute("string") );
- assertEquals( true, config.getAttributeAsBoolean("boolean") );
+
+ assertEquals( "12", config.getAttribute( "integer" ) );
+ assertEquals( "8000000000", config.getAttribute( "long" ) );
+ assertEquals( 1.23, config.getAttributeAsFloat( "float" ), 0.01 );
+ assertEquals( "string", config.getAttribute( "string" ) );
+ assertEquals( "true", config.getAttribute( "boolean" ) );
+
+ assertEquals( 12, config.getAttributeAsInteger( "integer" ) );
+ assertEquals( 8000000000L, config.getAttributeAsLong( "long" ) );
+ assertEquals( "string", config.getAttribute( "string" ) );
+ assertEquals( true, config.getAttributeAsBoolean( "boolean" ) );
}
-
- public void testSetToNull() throws Exception
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testSetToNull( ) throws Exception
{
- DefaultConfiguration config = new DefaultConfiguration( "root",
"0:0", "http://root";, "root" );
+ DefaultConfiguration config = new DefaultConfiguration( "root",
"0:0",
+ "http://root";, "root" );
config.setAttribute( "integer", "12" );
- assertEquals( "12", config.getAttribute("integer") );
-
+ assertEquals( "12", config.getAttribute( "integer" ) );
+
config.setAttribute( "integer", null );
- try
+
+ try
{
- config.getAttribute("integer");
- fail( "attribute 'integer' was present despite it being set to
null" );
- }
+ config.getAttribute( "integer" );
+ fail(
+ "attribute 'integer' was present despite it being set to
null" );
+ }
catch( ConfigurationException e )
{
// OK, this is what we expect - the attribute wasn't found.
}
}
-
- public void testMutable() throws Exception
- {
- MutableConfiguration root = new DefaultConfiguration( "root", "-" );

- root.setAttribute( "root1", "root1" );
- root.setAttribute( "root2", "root2" );
- root.getMutableChild( "child1" ).setAttribute( "child1-attr1",
"child1-attr1" );
- root.getMutableChild( "child1" ).setAttribute( "child1-attr2",
"child1-attr2" );
- root.getMutableChild( "child2" ).setAttribute( "child2-attr1",
"child2-attr1" );
- root.getMutableChild( "child2" ).setAttribute( "child2-attr2",
"child2-attr2" );
-
- assertEquals( "root1", root.getAttribute( "root1" ) );
- assertEquals( "root2", root.getAttribute( "root2" ) );
- assertEquals( "child1-attr1", root.getChild( "child1"
).getAttribute( "child1-attr1" ) );
- assertEquals( "child1-attr2", root.getChild( "child1"
).getAttribute( "child1-attr2" ) );
- assertEquals( "child2-attr1", root.getChild( "child2"
).getAttribute( "child2-attr1" ) );
- assertEquals( "child2-attr2", root.getChild( "child2"
).getAttribute( "child2-attr2" ) );
-
- assertEquals( null, root.getMutableChild( "child3", false ) );
-
- assertEquals( 2, root.getChildren().length );
-
- assertEquals( 2, root.getMutableChildren().length );
- assertEquals( 1, root.getMutableChildren( "child1" ).length );
- assertEquals( 1, root.getMutableChildren( "child2" ).length );
- assertTrue( root.getMutableChildren( "child1" )[0] == root.getChild(
"child1" ) );
-
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testMutable( ) throws Exception
+ {
+ MutableConfiguration root = new DefaultConfiguration( "root", "-" );
+ root.setAttribute( "root1", "root1" );
+ root.setAttribute( "root2", "root2" );
+ root.getMutableChild( "child1" )
+ .setAttribute( "child1-attr1", "child1-attr1" );
+ root.getMutableChild( "child1" )
+ .setAttribute( "child1-attr2", "child1-attr2" );
+ root.getMutableChild( "child2" )
+ .setAttribute( "child2-attr1", "child2-attr1" );
+ root.getMutableChild( "child2" )
+ .setAttribute( "child2-attr2", "child2-attr2" );
+
+ assertEquals( "root1", root.getAttribute( "root1" ) );
+ assertEquals( "root2", root.getAttribute( "root2" ) );
+ assertEquals( "child1-attr1",
+ root.getChild( "child1" ).getAttribute( "child1-attr1" ) );
+ assertEquals( "child1-attr2",
+ root.getChild( "child1" ).getAttribute( "child1-attr2" ) );
+ assertEquals( "child2-attr1",
+ root.getChild( "child2" ).getAttribute( "child2-attr1" ) );
+ assertEquals( "child2-attr2",
+ root.getChild( "child2" ).getAttribute( "child2-attr2" ) );
+
+ assertEquals( null, root.getMutableChild( "child3", false ) );
+
+ assertEquals( 2, root.getChildren( ).length );
+
+ assertEquals( 2, root.getMutableChildren( ).length );
+ assertEquals( 1, root.getMutableChildren( "child1" ).length );
+ assertEquals( 1, root.getMutableChildren( "child2" ).length );
+ assertTrue( root.getMutableChildren( "child1" )[0] == root.getChild(
+ "child1" ) );
+
// Add an immutable child.
- DefaultConfiguration immutableChild = new DefaultConfiguration(
"immutable-child", "-" );
- immutableChild.makeReadOnly();
-
- try
- {
- immutableChild.setAttribute( "attr", "attr" );
- fail( "Read-only DefaultConfiguration wasn't read-only!" );
- }
- catch (IllegalStateException ise)
- {
+ DefaultConfiguration immutableChild = new DefaultConfiguration(
"immutable-child",
+ "-" );
+ immutableChild.makeReadOnly( );
+
+ try
+ {
+ immutableChild.setAttribute( "attr", "attr" );
+ fail( "Read-only DefaultConfiguration wasn't read-only!" );
+ }
+ catch( IllegalStateException ise )
+ {
// expected
- }
-
- root.addChild( immutableChild );
-
+ }
+
+ root.addChild( immutableChild );
+
// OK, ask to have it back.
- root.getMutableChild( "immutable-child" ).setAttribute( "attr",
"attr" );
-
- assertEquals( 1, root.getChildren( "immutable-child" ).length );
- assertEquals( "attr", root.getChild( "immutable-child"
).getAttribute( "attr" ) );
- }
-
- public void testEquals()
- throws Exception
+ root.getMutableChild( "immutable-child" ).setAttribute( "attr",
"attr" );
+
+ assertEquals( 1, root.getChildren( "immutable-child" ).length );
+ assertEquals( "attr",
+ root.getChild( "immutable-child" ).getAttribute( "attr" ) );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testEquals( ) throws Exception
{
DefaultConfiguration a = createSimple( "a1", "a2" );
DefaultConfiguration b = createSimple( "a1", "a2" );
-
+
assertEquals( "equal test", a, b );
-
- String value1 = a.getChild( "child" ).getValue();
- String value2 = b.getChild( "child" ).getValue();
-
+
+ String value1 = a.getChild( "child" ).getValue( );
+ String value2 = b.getChild( "child" ).getValue( );
+
assertEquals( "value equality", value1, value2 );
-
+
a = createSimple( "a1", "a2" );
b = createSimple( "a2", "a1" );
-
- assertTrue( "order test", ! a.equals( b ) );
-
- value1 = a.getChild( "child" ).getValue();
- value2 = b.getChild( "child" ).getValue();
-
+
+ assertTrue( "order test", !a.equals( b ) );
+
+ value1 = a.getChild( "child" ).getValue( );
+ value2 = b.getChild( "child" ).getValue( );
+
assertEquals( "value equality", "a1", value1 );
assertEquals( "value equality", "a2", value2 );
}
-
+
private DefaultConfiguration createSimple( String value1, String value2 )
throws Exception
{
- DefaultConfiguration conf = new DefaultConfiguration( "root", "0:0",
"http://root";, "root" );
- DefaultConfiguration child1 = new DefaultConfiguration( "child",
"0:1", "http://root/child";, "child" );
+ DefaultConfiguration conf = new DefaultConfiguration( "root", "0:0",
+ "http://root";, "root" );
+ DefaultConfiguration child1 = new DefaultConfiguration( "child",
"0:1",
+ "http://root/child";, "child" );
child1.setValue( value1 );
child1.setAttribute( value1, value1 );
child1.setAttribute( value2, value2 );
child1.setAttribute( value1, value2 );
child1.setAttribute( value2, value1 );
conf.addChild( child1 );
-
- DefaultConfiguration child2 = new DefaultConfiguration( "child",
"0:2", "http://root/child";, "child" );
+
+ DefaultConfiguration child2 = new DefaultConfiguration( "child",
"0:2",
+ "http://root/child";, "child" );
child2.setValue( value2 );
child1.setAttribute( value2, value2 );
child1.setAttribute( value1, value1 );
@@ -284,9 +368,9 @@
child1.setAttribute( value1, value2 );
child2.setAttribute( value2, value2 );
conf.addChild( child2 );
-
- conf.makeReadOnly();
+
+ conf.makeReadOnly( );
+
return conf;
}
}
-

Modified:
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/SAXConfigurationHandlerTestCase.java
===================================================================
---
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/SAXConfigurationHandlerTestCase.java
2006-01-08 23:19:24 UTC (rev 887)
+++
trunk/main/util/configuration/impl/src/test/net/dpml/configuration/test/SAXConfigurationHandlerTestCase.java
2006-01-09 02:12:59 UTC (rev 888)
@@ -5,9 +5,9 @@
* 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.
@@ -31,11 +31,19 @@
*/
public final class SAXConfigurationHandlerTestCase extends TestCase
{
- public SAXConfigurationHandlerTestCase()
+ /**
+ * Creates a new SAXConfigurationHandlerTestCase object.
+ */
+ public SAXConfigurationHandlerTestCase( )
{
- this("SAXConfigurationHandler Test Case ");
+ this( "SAXConfigurationHandler Test Case " );
}

+ /**
+ * Creates a new SAXConfigurationHandlerTestCase object.
+ *
+ * @param name DOCUMENT ME!
+ */
public SAXConfigurationHandlerTestCase( final String name )
{
super( name );
@@ -51,9 +59,9 @@
* &lt;/rawName&gt;
* </pre>
*/
- public void testDefaultHandling() throws Exception
+ public void testDefaultHandling( ) throws Exception
{
- SAXConfigurationHandler handler = new SAXConfigurationHandler( );
+ SAXConfigurationHandler handler = new SAXConfigurationHandler( );

final String rootURI = "";
final String rootlocal = "rawName";
@@ -66,43 +74,47 @@
final String attValue = "attValue";
final String emptylocal = "emptyElement";
final String emptyraw = emptylocal;
-
- final AttributesImpl emptyAttributes = new AttributesImpl();

- final AttributesImpl attributes = new AttributesImpl();
- attributes.addAttribute("",attqName,attqName,
- "CDATA",attValue);
+ final AttributesImpl emptyAttributes = new AttributesImpl( );

- final AttributesImpl childAttributes = new AttributesImpl();
- childAttributes.addAttribute("", "child", "xmlns:child", "CDATA",
childURI);
+ final AttributesImpl attributes = new AttributesImpl( );
+ attributes.addAttribute( "", attqName, attqName, "CDATA", attValue );

- handler.startDocument();
+ final AttributesImpl childAttributes = new AttributesImpl( );
+ childAttributes.addAttribute( "", "child", "xmlns:child", "CDATA",
+ childURI );
+
+ handler.startDocument( );
handler.startPrefixMapping( "child", childURI );
handler.startElement( rootURI, rootlocal, rootraw, attributes );
- handler.startElement( childURI,
- childlocal,
- childraw,
- childAttributes );
+ handler.startElement( childURI, childlocal, childraw,
childAttributes );

- handler.characters( childvalue.toCharArray(), 0, childvalue.length()
);
+ handler.characters( childvalue.toCharArray( ), 0,
childvalue.length( ) );
handler.endElement( childURI, childlocal, childraw );
handler.startElement( rootURI, emptylocal, emptyraw, emptyAttributes
);
handler.endElement( rootURI, emptylocal, emptyraw );
- handler.endElement( null, null, rootraw);
+ handler.endElement( null, null, rootraw );
handler.endPrefixMapping( "child" );
- handler.endDocument();
+ handler.endDocument( );

- final Configuration configuration = handler.getConfiguration();
- assertEquals( attValue, configuration.getAttribute(attqName));
- assertEquals( childvalue,
configuration.getChild(childraw).getValue());
- assertEquals( "", configuration.getChild(childraw).getNamespace() );
- assertEquals( rootraw, configuration.getName());
- assertEquals( "test", configuration.getChild(emptyraw).getValue(
"test" ) );
+ final Configuration configuration = handler.getConfiguration( );
+ assertEquals( attValue, configuration.getAttribute( attqName ) );
+ assertEquals( childvalue,
+ configuration.getChild( childraw ).getValue( ) );
+ assertEquals( "", configuration.getChild( childraw ).getNamespace(
) );
+ assertEquals( rootraw, configuration.getName( ) );
+ assertEquals( "test",
+ configuration.getChild( emptyraw ).getValue( "test" ) );
}

- public void testNamespaceHandling() throws Exception
+ /**
+ * DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public void testNamespaceHandling( ) throws Exception
{
- SAXConfigurationHandler handler = new
NamespacedSAXConfigurationHandler( );
+ SAXConfigurationHandler handler = new
NamespacedSAXConfigurationHandler( );

final String rootURI = "";
final String rootlocal = "rawName";
@@ -114,36 +126,30 @@
final String attqName = "attqName";
final String attValue = "attValue";

- final AttributesImpl attributes = new AttributesImpl();
- attributes.addAttribute("",attqName,attqName,
- "CDATA",attValue);
+ final AttributesImpl attributes = new AttributesImpl( );
+ attributes.addAttribute( "", attqName, attqName, "CDATA", attValue );

- final AttributesImpl childAttributes = new AttributesImpl();
- childAttributes.addAttribute("", "child", "xmlns:child", "CDATA",
childURI);
+ final AttributesImpl childAttributes = new AttributesImpl( );
+ childAttributes.addAttribute( "", "child", "xmlns:child", "CDATA",
+ childURI );

- handler.startDocument();
+ handler.startDocument( );
handler.startPrefixMapping( "child", childURI );
handler.startElement( rootURI, rootlocal, rootraw, attributes );
- handler.startElement( childURI,
- childlocal,
- childraw,
- childAttributes );
+ handler.startElement( childURI, childlocal, childraw,
childAttributes );

- handler.characters( childvalue.toCharArray(), 0, childvalue.length()
);
+ handler.characters( childvalue.toCharArray( ), 0,
childvalue.length( ) );
handler.endElement( childURI, childlocal, childraw );
- handler.endElement( null, null, rootraw);
+ handler.endElement( null, null, rootraw );
handler.endPrefixMapping( "child" );
- handler.endDocument();
+ handler.endDocument( );

- final Configuration configuration = handler.getConfiguration();
- assertEquals( attValue, configuration.getAttribute(attqName));
- assertEquals( childvalue,
configuration.getChild(childlocal).getValue());
- assertEquals( childURI,
configuration.getChild(childlocal).getNamespace() );
- assertEquals( rootraw, configuration.getName());
+ final Configuration configuration = handler.getConfiguration( );
+ assertEquals( attValue, configuration.getAttribute( attqName ) );
+ assertEquals( childvalue,
+ configuration.getChild( childlocal ).getValue( ) );
+ assertEquals( childURI,
+ configuration.getChild( childlocal ).getNamespace( ) );
+ assertEquals( rootraw, configuration.getName( ) );
}
}
-
-
-
-
-




  • r888 - in trunk/main/util: cli/src/test/net/dpml/cli cli/src/test/net/dpml/cli/application cli/src/test/net/dpml/cli/bug cli/src/test/net/dpml/cli/builder cli/src/test/net/dpml/cli/commandline cli/src/test/net/dpml/cli/option cli/src/test/net/dpml/cli/resource cli/src/test/net/dpml/cli/util cli/src/test/net/dpml/cli/validation cli/src/test/net/dpml/cli/validation/protect configuration/impl/src/test/net/dpml/configuration/test, mcconnell at BerliOS, 01/08/2006

Archive powered by MHonArc 2.6.24.

Top of Page