1 package org.codehaus.plexus.configuration.xml;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import junit.framework.TestCase;
20 import org.codehaus.plexus.configuration.ConfigurationTestHelper;
21 import org.codehaus.plexus.configuration.PlexusConfiguration;
22
23
24
25
26 public final class XmlPlexusConfigurationTest extends TestCase {
27 private XmlPlexusConfiguration configuration;
28
29 public void setUp() {
30 configuration = new XmlPlexusConfiguration("a");
31 }
32
33 public void testWithHelper() throws Exception {
34 PlexusConfiguration c = ConfigurationTestHelper.getTestConfiguration();
35
36 ConfigurationTestHelper.testConfiguration(c);
37 }
38
39 public void testGetValue() throws Exception {
40 String orgValue = "Original String";
41 configuration.setValue(orgValue);
42 assertEquals(orgValue, configuration.getValue());
43 }
44
45 public void testGetAttribute() throws Exception {
46 String key = "key";
47 String value = "original value";
48 String defaultStr = "default";
49 configuration.setAttribute(key, value);
50 assertEquals(value, configuration.getAttribute(key, defaultStr));
51 assertEquals(defaultStr, configuration.getAttribute("newKey", defaultStr));
52 }
53
54 public void testGetChild() throws Exception {
55 PlexusConfiguration child = (XmlPlexusConfiguration) configuration.getChild("child");
56
57 assertNotNull(child);
58
59 child.setValue("child value");
60
61 assertEquals(1, configuration.getChildCount());
62
63 child = (XmlPlexusConfiguration) configuration.getChild("child");
64
65 assertNotNull(child);
66
67 assertEquals("child value", child.getValue());
68
69 assertEquals(1, configuration.getChildCount());
70 }
71
72 public void testToString() throws Exception {
73 PlexusConfiguration c = ConfigurationTestHelper.getTestConfiguration();
74
75 assertEquals(
76 "<string string=\"string\">string</string>\n",
77 c.getChild("string").toString());
78
79
80
81 }
82
83 public void testProgrammaticConfigurationCreation() throws Exception {
84 String viewRoot = "/path/to/viewRoot";
85
86 PlexusConfiguration c = new XmlPlexusConfiguration("configuration").addChild("viewRoot", viewRoot);
87
88 assertEquals(viewRoot, c.getChild("viewRoot").getValue());
89 }
90 }