1   /*
2    * 
3    * $Revision: 1.2 $
4    * $Date: 2004/06/20 12:18:40 $
5    *
6    * ====================================================================
7    * struts-it
8    * Copyright (C) 2004 - strutsit community
9    * 
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   * 
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   * 
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   *
22   * created: 2004-06-05  Manfred Wolff
23   */
24  package org.strutsit.chain;
25  
26  import junit.framework.Test;
27  import junit.framework.TestCase;
28  import junit.framework.TestSuite;
29  
30  import org.apache.commons.chain.Command;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  import org.strutsit.chain.configuration.ChainXMLConfiguration;
34  import org.strutsit.chain.interfaces.ChainConfiguration;
35  
36  /***
37   * This Unit-Test test the several configuration classes.
38   * 
39   * @author <a href="mailto:wolff@struts-it.de">Manfred Wolff </a>
40   * @since JDK 1.4
41   * @version $Revision: 1.2 $
42   */
43  public class TestConfiguration extends TestCase {
44  
45      /***
46       * The logger for this class (commons-logging).
47       */
48      private static Log log = LogFactory.getLog(TestConfiguration.class);
49  
50      /***
51       * Defines the testcase name for JUnit.
52       * 
53       * @param theName the testcase's name.
54       */
55      public TestConfiguration(String theName) {
56          super(theName);
57          if (log.isTraceEnabled()) {
58              log.trace("TestConfiguration -> START");
59          }
60          if (log.isTraceEnabled()) {
61              log.trace("TestConfiguration -> END");
62          }
63      }
64  
65      /***
66       * Start the tests.
67       * 
68       * @param theArgs the arguments. Not used
69       */
70      public static void main(String[] theArgs) {
71          if (log.isTraceEnabled()) {
72              log.trace("main -> START");
73          }
74          junit.awtui.TestRunner.main(new String[] { TestConfiguration.class
75                  .getName() });
76          if (log.isTraceEnabled()) {
77              log.trace("main -> END");
78          }
79      }
80  
81      /***
82       * @return a test suite (<code>TestSuite</code>) that includes all
83       *         methods starting with "test"
84       */
85      public static Test suite() {
86          // All methods starting with "test" will be executed in the test suite.
87          if (log.isTraceEnabled()) {
88              log.trace("suite -> START");
89          }
90          if (log.isTraceEnabled()) {
91              log.trace("suite -> END");
92          }
93          return new TestSuite(TestConfiguration.class);
94      }
95  
96      /***
97       * Nothing to be done.
98       */
99      public void setUp() {
100         if (log.isTraceEnabled()) {
101             log.trace("setUp -> START");
102         }
103         if (log.isTraceEnabled()) {
104             log.trace("setUp -> END");
105         }
106     }
107 
108     /***
109      * Nothing to be done.
110      */
111     public void tearDown() {
112         if (log.isTraceEnabled()) {
113             log.trace("tearDown -> START");
114         }
115         if (log.isTraceEnabled()) {
116             log.trace("tearDown -> END");
117         }
118     }
119 
120     /***
121      * Tests the configuration.
122      */
123     public void testLoadXMLConfiguration() {
124 
125         if (log.isTraceEnabled()) {
126             log.trace("testLoadXMLConfiguration -> START");
127         }
128         ChainConfiguration config = new ChainXMLConfiguration();
129         try {
130             config.init();
131         } catch (Exception e) {
132             log.error("Exception while init the configuration.");
133             if (log.isDebugEnabled()) {
134                 log.debug("testLoadXMLConfiguration -> " + e);
135             }
136         }
137 
138         Command testCommand = config.getCatalog().getCommand("Test-Command");
139 
140         assertNotNull("Error getting command out of XML Configuration",
141                 testCommand);
142     }
143 }