+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2008 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// XerialJ\r
-//\r
-// OptionSchemaTest.java\r
-// Since: Oct 29, 2008 12:49:36 PM\r
-//\r
-// $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/test/java/org/xerial/util/opt/OptionSchemaTest.java $\r
-// $Author: leo $\r
-//--------------------------------------\r
-package org.xerial.util.opt;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-\r
-import java.io.IOException;\r
-import java.io.StringWriter;\r
-import java.util.List;\r
-\r
-import org.junit.After;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.xerial.util.log.LogLevel;\r
-import org.xerial.util.log.Logger;\r
-\r
-public class OptionSchemaTest\r
-{\r
- private static Logger _logger = Logger.getLogger(OptionSchemaTest.class);\r
-\r
- @Before\r
- public void setUp() throws Exception\r
- {}\r
-\r
- @After\r
- public void tearDown() throws Exception\r
- {}\r
-\r
- @Usage(command = "> java -jar MyProg [option ..]", description = "sample program")\r
- class MyOption\r
- {\r
- @Option(symbol = "h", longName = "help", description = "display help message")\r
- boolean displayHelp;\r
-\r
- @Option(longName = "verbose", description = "output verbose messages")\r
- boolean verbose;\r
-\r
- @Option(symbol = "l", longName = "loglevel", varName = "LOG_LEVEL", description = "set log level: ERROR, DEBUG, WARN")\r
- LogLevel logLevel;\r
-\r
- @Option(symbol = "o", varName = "FILE", description = "output file")\r
- String outputFile;\r
-\r
- @Argument(name = "file", index = 1, required = false)\r
- List<String> fileList;\r
-\r
- @Argument(index = 0)\r
- String subCommand;\r
-\r
- }\r
-\r
- @Test\r
- public void testPrintUsage() throws IOException\r
- {\r
- OptionSchema schema = OptionSchema.newOptionSchema(MyOption.class);\r
-\r
- assertEquals(4, schema.getOptionItemList().size());\r
- assertEquals(2, schema.getArgumentItemList().size());\r
- assertNotNull(schema.getUsage());\r
-\r
- StringWriter out = new StringWriter();\r
- out.append("\n");\r
- schema.printUsage(out);\r
- _logger.debug(out.toString());\r
- }\r
-\r
- @Usage(command = "> java -jar MyProg [option ..]", description = "sample program", templatePath = "org/xerial/util/opt/help-message-alt.template")\r
- class MyOption2\r
- {\r
- @Option(symbol = "h", longName = "help", description = "display help message")\r
- boolean displayHelp;\r
-\r
- @Option(longName = "verbose", description = "output verbose messages")\r
- boolean verbose;\r
-\r
- @Option(symbol = "l", longName = "loglevel", varName = "LOG_LEVEL", description = "set log level: ERROR, DEBUG, WARN")\r
- LogLevel logLevel;\r
-\r
- @Option(symbol = "o", varName = "FILE", description = "output file")\r
- String outputFile;\r
-\r
- @Argument(name = "file", index = 1, required = false)\r
- List<String> fileList;\r
-\r
- @Argument(name = "sub_command", index = 0)\r
- String subCommand;\r
- }\r
-\r
- @Test\r
- public void alternativeTemplate() throws IOException\r
- {\r
- OptionSchema schema = OptionSchema.newOptionSchema(MyOption2.class);\r
-\r
- assertEquals(4, schema.getOptionItemList().size());\r
- assertEquals(2, schema.getArgumentItemList().size());\r
- assertNotNull(schema.getUsage());\r
-\r
- StringWriter out = new StringWriter();\r
- out.append("\n");\r
- schema.printUsage(out);\r
- _logger.debug(out.toString());\r
- }\r
-\r
-}\r