Source Code Cross Referenced for CommandLineParserTest.java in  » ESB » celtix-1.0 » org » objectweb » celtix » tools » common » toolspec » parser » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » celtix 1.0 » org.objectweb.celtix.tools.common.toolspec.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.tools.common.toolspec.parser;
002:
003:        import junit.framework.TestCase;
004:
005:        import org.objectweb.celtix.tools.common.toolspec.ToolSpec;
006:
007:        public class CommandLineParserTest extends TestCase {
008:            private CommandLineParser parser;
009:
010:            public CommandLineParserTest(String name) {
011:                super (name);
012:            }
013:
014:            public static void main(String[] args) {
015:                junit.textui.TestRunner.run(CommandLineParserTest.class);
016:            }
017:
018:            public void setUp() throws Exception {
019:                String tsSource = "/org/objectweb/celtix/tools/common/toolspec/parser/resources/testtool.xml";
020:                ToolSpec toolspec = new ToolSpec(getClass()
021:                        .getResourceAsStream(tsSource), true);
022:
023:                parser = new CommandLineParser(toolspec);
024:            }
025:
026:            public void testValidArguments() throws Exception {
027:                String[] args = new String[] { "-r", "-n", "test", "arg1" };
028:                CommandDocument result = parser.parseArguments(args);
029:
030:                assertEquals("testValidArguments Failed", "test", result
031:                        .getParameter("namespace"));
032:            }
033:
034:            public void testInvalidArgumentValue() throws Exception {
035:                try {
036:                    String[] args = new String[] { "-n", "test@", "arg1" };
037:                    parser.parseArguments(args);
038:                    fail("testInvalidArgumentValue failed");
039:                } catch (BadUsageException ex) {
040:                    Object[] errors = ex.getErrors().toArray();
041:                    assertEquals("testInvalidArgumentValue failed", 1,
042:                            errors.length);
043:                    CommandLineError error = (CommandLineError) errors[0];
044:                    assertTrue("Expected InvalidArgumentValue error",
045:                            error instanceof  ErrorVisitor.UserError);
046:                    ErrorVisitor.UserError userError = (ErrorVisitor.UserError) error;
047:                    assertEquals("Invalid argument value message incorrect",
048:                            "-n has invalid character!", userError.toString());
049:                }
050:            }
051:
052:            public void testValidArgumentEnumValue() throws Exception {
053:                String[] args = new String[] { "-r", "-e", "true", "arg1" };
054:                CommandDocument result = parser.parseArguments(args);
055:                assertEquals("testValidArguments Failed", "true", result
056:                        .getParameter("enum"));
057:            }
058:
059:            public void testInvalidArgumentEnumValue() throws Exception {
060:                try {
061:                    String[] args = new String[] { "-e", "wrongvalue" };
062:                    parser.parseArguments(args);
063:                    fail("testInvalidArgumentEnumValue failed");
064:                } catch (BadUsageException ex) {
065:                    Object[] errors = ex.getErrors().toArray();
066:                    assertEquals("testInvalidArgumentEnumValu failed", 1,
067:                            errors.length);
068:                    CommandLineError error = (CommandLineError) errors[0];
069:                    assertTrue("Expected InvalidArgumentEnumValu error",
070:                            error instanceof  ErrorVisitor.UserError);
071:                    ErrorVisitor.UserError userError = (ErrorVisitor.UserError) error;
072:                    assertEquals(
073:                            "Invalid enum argument value message incorrect",
074:                            "-e wrongvalue not in the enumeration value list!",
075:                            userError.toString());
076:                }
077:            }
078:
079:            public void testValidMixedArguments() throws Exception {
080:                String[] args = new String[] { "-v", "-r", "-n", "test", "arg1" };
081:                CommandDocument result = parser.parseArguments(args);
082:
083:                assertEquals("testValidMissedArguments Failed", "test", result
084:                        .getParameter("namespace"));
085:            }
086:
087:            public void testInvalidOption() {
088:                try {
089:                    String[] args = new String[] { "-n", "-r", "arg1" };
090:                    parser.parseArguments(args);
091:
092:                    fail("testInvalidOption failed");
093:                } catch (BadUsageException ex) {
094:                    Object[] errors = ex.getErrors().toArray();
095:
096:                    assertEquals("testInvalidOption failed", 1, errors.length);
097:                    CommandLineError error = (CommandLineError) errors[0];
098:
099:                    assertTrue("Expected InvalidOption error",
100:                            error instanceof  ErrorVisitor.InvalidOption);
101:                    ErrorVisitor.InvalidOption option = (ErrorVisitor.InvalidOption) error;
102:
103:                    assertEquals("Invalid option incorrect", "-n", option
104:                            .getOptionSwitch());
105:                    assertEquals(
106:                            "Invalid option message incorrect",
107:                            "Invalid option: -n is missing its associated argument",
108:                            option.toString());
109:                }
110:            }
111:
112:            public void testMissingOption() {
113:                try {
114:                    String[] args = new String[] { "-n", "test", "arg1" };
115:                    parser.parseArguments(args);
116:                    fail("testMissingOption failed");
117:                } catch (BadUsageException ex) {
118:                    Object[] errors = ex.getErrors().toArray();
119:
120:                    assertEquals("testInvalidOption failed", 1, errors.length);
121:                    CommandLineError error = (CommandLineError) errors[0];
122:
123:                    assertTrue("Expected MissingOption error",
124:                            error instanceof  ErrorVisitor.MissingOption);
125:                    ErrorVisitor.MissingOption option = (ErrorVisitor.MissingOption) error;
126:
127:                    assertEquals("Missing option incorrect", "r", option
128:                            .getOptionSwitch());
129:                }
130:            }
131:
132:            public void testMissingArgument() {
133:                try {
134:                    String[] args = new String[] { "-n", "test", "-r" };
135:                    parser.parseArguments(args);
136:                    fail("testMissingArgument failed");
137:                } catch (BadUsageException ex) {
138:                    Object[] errors = ex.getErrors().toArray();
139:
140:                    assertEquals("testInvalidOption failed", 1, errors.length);
141:                    CommandLineError error = (CommandLineError) errors[0];
142:
143:                    assertTrue("Expected MissingArgument error",
144:                            error instanceof  ErrorVisitor.MissingArgument);
145:                    ErrorVisitor.MissingArgument arg = (ErrorVisitor.MissingArgument) error;
146:
147:                    assertEquals("MissingArgument incorrect", "wsdlurl", arg
148:                            .getArgument());
149:                }
150:            }
151:
152:            public void testDuplicateArgument() {
153:                try {
154:                    String[] args = new String[] { "-n", "test", "-r", "arg1",
155:                            "arg2" };
156:                    parser.parseArguments(args);
157:                    fail("testUnexpectedArgument failed");
158:                } catch (BadUsageException ex) {
159:                    Object[] errors = ex.getErrors().toArray();
160:                    assertEquals("testInvalidOption failed", 1, errors.length);
161:                    CommandLineError error = (CommandLineError) errors[0];
162:                    assertTrue("Expected UnexpectedArgument error",
163:                            error instanceof  ErrorVisitor.UnexpectedArgument);
164:                }
165:            }
166:
167:            public void testUnexpectedOption() {
168:                try {
169:                    String[] args = new String[] { "-n", "test", "-r",
170:                            "-unknown" };
171:                    parser.parseArguments(args);
172:                    fail("testUnexpectedOption failed");
173:                } catch (BadUsageException ex) {
174:                    Object[] errors = ex.getErrors().toArray();
175:
176:                    assertEquals("testInvalidOption failed", 1, errors.length);
177:                    CommandLineError error = (CommandLineError) errors[0];
178:
179:                    assertTrue("Expected UnexpectedOption error",
180:                            error instanceof  ErrorVisitor.UnexpectedOption);
181:                    ErrorVisitor.UnexpectedOption option = (ErrorVisitor.UnexpectedOption) error;
182:
183:                    assertEquals("UnexpectedOption incorrect", "-unknown",
184:                            option.getOptionSwitch());
185:                }
186:            }
187:
188:            public void testInvalidPackageName() {
189:
190:                try {
191:                    String[] args = new String[] { "-p", "/test", "arg1" };
192:                    parser.parseArguments(args);
193:                    fail("testInvalidPackageName failed");
194:                } catch (BadUsageException ex) {
195:                    Object[] errors = ex.getErrors().toArray();
196:                    assertEquals("testInvalidPackageName failed", 1,
197:                            errors.length);
198:                    CommandLineError error = (CommandLineError) errors[0];
199:                    assertTrue("Expected InvalidArgumentValue error",
200:                            error instanceof  ErrorVisitor.UserError);
201:                    ErrorVisitor.UserError userError = (ErrorVisitor.UserError) error;
202:                    assertEquals("Invalid argument value message incorrect",
203:                            "-p has invalid character!", userError.toString());
204:                }
205:
206:            }
207:
208:            public void testvalidPackageName() throws Exception {
209:
210:                String[] args = new String[] { "-p",
211:                        "http://www.iona.com/hello_world_soap_http=com.iona",
212:                        "-r", "arg1" };
213:                CommandDocument result = parser.parseArguments(args);
214:                assertEquals("testValidPackageName Failed",
215:                        "http://www.iona.com/hello_world_soap_http=com.iona",
216:                        result.getParameter("packagename"));
217:
218:            }
219:
220:            public void testUsage() throws Exception {
221:                String usage = "[ -n <C++ Namespace> ] [ -impl ] [ -e <Enum Value> ] -r "
222:                        + "[ -p <[wsdl namespace =]Package Name> ]* [ -? ] [ -v ] <wsdlurl> ";
223:                String pUsage = parser.getUsage();
224:                assertEquals("testUsage failed", usage, pUsage);
225:            }
226:
227:            public void testDetailedUsage() throws Exception {
228:                String lineSeparator = System.getProperty("line.separator");
229:                String usage = "[ -n <C++ Namespace> ]" + lineSeparator;
230:                usage += "Namespace" + lineSeparator + lineSeparator;
231:                usage += "[ -impl ]" + lineSeparator;
232:                usage += "impl" + lineSeparator + lineSeparator;
233:                usage += "[ -e <Enum Value> ]" + lineSeparator;
234:                usage += "enum" + lineSeparator + lineSeparator;
235:                usage += "-r" + lineSeparator;
236:                usage += "required" + lineSeparator + lineSeparator;
237:                usage += "[ -p <[wsdl namespace =]Package Name> ]*"
238:                        + lineSeparator;
239:                usage += "The java package name to use for the generated code."
240:                        + "Also, optionally specify the wsdl namespace mapping to a particular java packagename."
241:                        + lineSeparator + lineSeparator;
242:                usage += "[ -? ]" + lineSeparator;
243:                usage += "help" + lineSeparator + lineSeparator;
244:                usage += "[ -v ]" + lineSeparator;
245:                usage += "version" + lineSeparator + lineSeparator;
246:                usage += "<wsdlurl>" + lineSeparator;
247:                usage += "WSDL/SCHEMA URL" + lineSeparator + lineSeparator;
248:                assertEquals("testUsage failed", usage, parser
249:                        .getDetailedUsage());
250:            }
251:
252:            public void testOtherMethods() throws Exception {
253:                String tsSource = "/org/objectweb/celtix/tools/common/toolspec/parser/resources/testtool.xml";
254:                ToolSpec toolspec = new ToolSpec(getClass()
255:                        .getResourceAsStream(tsSource), false);
256:                CommandLineParser commandLineParser = new CommandLineParser(
257:                        null);
258:                commandLineParser.setToolSpec(toolspec);
259:                CommandDocument commandDocument = commandLineParser
260:                        .parseArguments("-r unknown");
261:                assertTrue(commandDocument != null);
262:            }
263:
264:            public void testGetDetailedUsage() {
265:                assertTrue("Namespace".equals(parser
266:                        .getDetailedUsage("namespace")));
267:            }
268:
269:        }
w_w_w.___j___a_v___a2_s.c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.