1 package org.apache.turbine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.commons.configuration.Configuration;
26
27 import org.apache.turbine.test.BaseTestCase;
28 import org.apache.turbine.util.TurbineConfig;
29 import org.apache.turbine.util.TurbineXmlConfig;
30
31 /***
32 * Tests that the ConfigurationFactory and regular old properties methods both work.
33 * Verify the overriding of properties.
34 *
35 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
36 * @version $Id: ConfigurationTest.java 534527 2007-05-02 16:10:59Z tv $
37 */
38 public class ConfigurationTest extends BaseTestCase
39 {
40 public static final String SERVICE_PREFIX = "services.";
41
42 /***
43 * A <code>Service</code> property determining its implementing
44 * class name .
45 */
46 public static final String CLASSNAME_SUFFIX = ".classname";
47
48 private static TurbineConfig tc = null;
49 private static TurbineXmlConfig txc = null;
50
51 public ConfigurationTest(String name) throws Exception
52 {
53 super(name);
54 }
55
56 public static Test suite()
57 {
58 return new TestSuite(ConfigurationTest.class);
59 }
60
61 public void testCreateTurbineWithConfigurationXML() throws Exception
62 {
63 txc = new TurbineXmlConfig(".", "/conf/test/TurbineConfiguration.xml");
64
65 try
66 {
67 txc.initialize();
68
69 Configuration configuration = Turbine.getConfiguration();
70 assertNotNull("No Configuration Object found!", configuration);
71 assertFalse("Make sure we have values", configuration.isEmpty());
72
73
74 String key = "module.cache";
75
76 assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "true", configuration.getString(key));
77
78
79 key = "scheduledjob.cache.size";
80 assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "10", configuration.getString(key));
81 }
82 catch (Exception e)
83 {
84 throw e;
85 }
86 finally
87 {
88 txc.dispose();
89 }
90 }
91
92 public void testCreateTurbineWithConfiguration() throws Exception
93 {
94 tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
95
96 try
97 {
98 tc.initialize();
99
100 Configuration configuration = Turbine.getConfiguration();
101 assertNotNull("No Configuration Object found!", configuration);
102 assertFalse("Make sure we have values", configuration.isEmpty());
103
104 String key = "scheduledjob.cache.size";
105 assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "10", configuration.getString(key));
106 }
107 catch (Exception e)
108 {
109 throw e;
110 }
111 finally
112 {
113 tc.dispose();
114 }
115 }
116
117 }