1   package org.apache.fulcrum.yaafi.cli;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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             // that's what we expect
117             return;
118         }
119 
120         TestCase.fail("The YAAFI CLI should throw an exception");
121     }
122 }