Index: maven-commandline-plugin/src/test/org/codelutin/util/GeneratorTest.java diff -u /dev/null maven-commandline-plugin/src/test/org/codelutin/util/GeneratorTest.java:1.1 --- /dev/null Thu Nov 29 10:32:30 2007 +++ maven-commandline-plugin/src/test/org/codelutin/util/GeneratorTest.java Thu Nov 29 10:32:25 2007 @@ -0,0 +1,120 @@ +package org.codelutin.util; + +import junit.framework.TestCase; +import org.codelutin.i18n.I18n; + +import java.io.File; +import java.io.StringWriter; +import java.io.Writer; + +/** + * OptionDefinitionParser Tester. + * + * @author chemit + * @version 1.0 + * @since
11/16/2007+ */ +public class GeneratorTest extends TestCase { + + private static final String PROJECT_NAME = GeneratorTest.class.getSimpleName(); + private static final String HERE = new File("").getAbsolutePath(); + private static final String OUT_PATH = new File(HERE, "target/gen/classes").getAbsolutePath(); + private static final String PARSER_NAME = "org.codelutin.util.CodeLutinUtilOptionParser"; + private static final String PROPERTIES_FILE_PATH = HERE + "/src/test/testOptions.properties"; + private static final String RST_FILE_NAME = HERE + "/target/gen/site/fr/rst/GeneratorTest.rst"; + + static boolean first = false; + + static { + initI18n(); + } + + static void initI18n() { + if (!first) { + String language = System.getProperty("user.language"); + I18n.setRecordFilePath("/tmp/language.properties"); + I18n.init(language, "fr"); + first = true; + } + } + + public void testLaunch() throws Exception { + + Generator goal = new Generator(); + + goal.propertiesFile = new File(PROPERTIES_FILE_PATH); + goal.parserFullyQualifiedName = PARSER_NAME; + goal.projectName = PROJECT_NAME; + goal.out = new File(OUT_PATH); + goal.rstFilePath = new File(RST_FILE_NAME); + goal.execute(); + + assertNotNull(goal.parser); + //todo make asserts on parser + + } + + public void testLaunchWithDetails() throws Exception { + + Generator goal = new Generator(); + + goal.propertiesFile = new File(PROPERTIES_FILE_PATH); + goal.parserFullyQualifiedName = PARSER_NAME + "_details"; + goal.projectName = PROJECT_NAME + "_details"; + goal.showDetails = true; + goal.out = new File(OUT_PATH); + goal.rstFilePath = new File(RST_FILE_NAME + "_details"); + goal.execute(); + + assertNotNull(goal.parser); + //todo make asserts on parser + + } + + public void testLaunchWithDetailsAndErrors() throws Exception { + + Generator goal = new Generator(); + + goal.propertiesFile = new File(PROPERTIES_FILE_PATH); + //goal.factoryFullyQualifiedName = FACTORY_NAME + "_detailsAndErrors"; + goal.parserFullyQualifiedName = PARSER_NAME + "_detailsAndErrors"; + goal.projectName = PROJECT_NAME + "_detailsAndErrors"; + goal.showDetails = true; + goal.showErrors = true; + goal.out = new File(OUT_PATH); + goal.rstFilePath = new File(RST_FILE_NAME + "_detailsAndErrors"); + goal.execute(); + + assertNotNull(goal.parser); + //todo make asserts on parser + } + + public void testReloadParser() throws Exception { + + OptionParser parser; + + parser = org.codelutin.util.OptionParser.newParser(PARSER_NAME, getClass().getClassLoader()); + + System.out.println(parser); + + + assertNotNull(parser); + + OptionParserAnnotationHelper.OptionParserA annotation; + annotation = parser.getClass().getAnnotation(OptionParserAnnotationHelper.OptionParserA.class); + assertNotNull(annotation); + Writer writer = new StringWriter(); + parser.printUsage(writer, parser.getClass().getSimpleName()); + System.out.println(writer); + writer.flush(); + writer.close(); + System.out.println(annotation); + + writer = new StringWriter(); + parser.printDetails(writer); + System.out.println(writer); + writer.flush(); + writer.close(); + } + +}