1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
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 }