1 package org.apache.fulcrum.yaafi.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import org.apache.avalon.framework.service.ServiceException;
25 import org.apache.fulcrum.yaafi.TestComponent;
26
27 /**
28 * Test suite for exercising the command line integration.
29 *
30 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
31 */
32
33 public class MainTest extends TestCase
34 {
35 private Main main;
36
37 /**
38 * Constructor
39 * @param name the name of the test case
40 */
41 public MainTest( String name )
42 {
43 super(name);
44 }
45
46 /**
47 * @see junit.framework.TestCase#tearDown()
48 */
49 protected void tearDown() throws Exception
50 {
51 this.main.dispose();
52 super.tearDown();
53 }
54
55 /**
56 * @return get our simple test component
57 */
58 private TestComponent getTestComponent() throws ServiceException
59 {
60 return (TestComponent) main.getServiceManager().lookup(
61 TestComponent.ROLE
62 );
63 }
64
65 /**
66 * Initialize the CLI using a valid container configuration
67 */
68 public void testValidContainerConfiguration() throws Exception
69 {
70 String[] args = {
71 "--yaafi.cli.config",
72 "./src/test/TestYaafiContainerConfig.xml"
73 };
74
75 this.main = new Main(args);
76 this.main.run();
77
78 this.getTestComponent();
79 }
80
81 /**
82 * Test the toString() method provding diagnostic information
83 */
84 public void testToString() throws Exception
85 {
86 String[] args = {
87 "--yaafi.cli.applicationHome",
88 ".",
89 "--yaafi.cli.config",
90 "./src/test/TestYaafiContainerConfig.xml"
91 };
92
93 this.main = new Main(args);
94 System.out.println(this.main.toString());
95 return;
96 }
97
98 /**
99 * Initialize the CLI using an invalid container configuration
100 */
101 public void testInvlidContainerConfiguration() throws Exception
102 {
103 String[] args = {
104 "--yaafi.cli.config",
105 " ./src/test/foo.xml"
106 };
107
108 this.main = new Main(args);
109
110 try
111 {
112 this.main.run();
113 }
114 catch (RuntimeException e)
115 {
116
117 return;
118 }
119
120 TestCase.fail("The YAAFI CLI should throw an exception");
121 }
122 }