KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > config > test > VergeConfigMediatorTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.config.test;
8
9
10 import java.util.ResourceBundle JavaDoc;
11
12 import com.inversoft.config.ConfigFactoryRegistry;
13 import com.inversoft.config.ConfigurationException;
14 import com.inversoft.junit.WebTestCase;
15 import com.inversoft.verge.config.VergeConfigConstants;
16 import com.inversoft.verge.config.VergeConfigMediator;
17
18
19 /**
20  * <p>
21  * This class contains the TestCases for the config mediator
22  * </p>
23  *
24  * @author Brian Pontarelli
25  * @since 1.0
26  * @version 1.0
27  */

28 public class VergeConfigMediatorTest extends WebTestCase {
29
30     /**
31      * Constructs a new <code>VergeConfigMediatorTest</code> TestCase instance
32      */

33     public VergeConfigMediatorTest(String JavaDoc name) {
34         super(name);
35         setLocal(true);
36     }
37
38
39     /**
40      * Tests that the mediator works
41      */

42     public void testMediate() {
43
44         getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM,
45             "src/com/inversoft/verge/config/test/test.xml," +
46             "src/com/inversoft/verge/config/test/test2.xml");
47
48         VergeConfigMediator mediator = new VergeConfigMediator();
49         try {
50             ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
51                 "com.inversoft.verge.config.test.ConfigBundle");
52             ConfigFactoryRegistry.load(bundle);
53
54             TestConfigBuilder.built = false;
55             TestConfigBuilder.validated = false;
56             TestConfigBuilder.commited = false;
57             mediator.mediate(getContext());
58
59             assertTrue(TestConfigBuilder.built);
60             assertTrue(TestConfigBuilder.validated);
61             assertTrue(TestConfigBuilder.commited);
62         } catch (ConfigurationException e) {
63             fail(e.toString());
64         }
65     }
66
67     /**
68      * Tests that the mediator works with no files
69      */

70     public void testMediateNone() {
71
72         VergeConfigMediator mediator = new VergeConfigMediator();
73         try {
74             ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
75                 "com.inversoft.verge.config.test.ConfigBundle");
76             ConfigFactoryRegistry.load(bundle);
77
78             TestConfigBuilder.built = false;
79             TestConfigBuilder.validated = false;
80             TestConfigBuilder.commited = false;
81             mediator.mediate(getContext());
82
83             assertFalse(TestConfigBuilder.built);
84             assertFalse(TestConfigBuilder.validated);
85             assertFalse(TestConfigBuilder.commited);
86         } catch (ConfigurationException e) {
87             fail(e.toString());
88         }
89     }
90
91     /**
92      * Tests that the mediator fails
93      */

94     public void testMediateFailure() {
95
96         getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM,
97             "src/com/inversoft/verge/config/test/test.xml," +
98             "src/com/inversoft/verge/config/test/test2.xml," +
99             "src/com/inversoft/verge/config/test/test-bad.xml");
100
101         VergeConfigMediator mediator = new VergeConfigMediator();
102         try {
103             ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
104                 "com.inversoft.verge.config.test.ConfigBundle");
105             ConfigFactoryRegistry.load(bundle);
106             mediator.mediate(getContext());
107             fail("Should have failed");
108         } catch (ConfigurationException e) {
109             // SMOTHER
110
}
111     }
112
113     /**
114      * Tests that the mediator works with the default factories
115      */

116     public void testMediateDefaultFactories() {
117
118         getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM,
119             "src/com/inversoft/verge/config/test/default-forms.xml");
120
121         VergeConfigMediator mediator = new VergeConfigMediator();
122         try {
123             ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
124                 "com.inversoft.verge.config.test.ConfigBundle");
125             ConfigFactoryRegistry.load(bundle);
126             mediator.mediate(getContext());
127         } catch (ConfigurationException e) {
128             fail("Should not have thrown exception! - " + e.toString());
129         }
130     }
131 }
Popular Tags