2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.shale.clay.config;
18
19 import java.util.Iterator;
20
21 import javax.servlet.ServletContextEvent;
22 import javax.servlet.ServletContextListener;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import org.apache.commons.chain.web.ChainListener;
28 import org.apache.shale.clay.config.beans.AttributeBean;
29 import org.apache.shale.clay.config.beans.ComponentBean;
30
31
32 public class ConfigAltNsTestCase extends AbstractTestCaseConfig {
33
34
35 public ConfigAltNsTestCase(String name) {
36 super(name);
37 }
38
39
40 public static Test suite() {
41
42 return (new TestSuite(ConfigAltNsTestCase.class));
43
44 }
45
46 protected void setUp() throws Exception {
47 super.setUp();
48
49 }
50
51 public void testLoadBuilderNamespace() throws Exception {
52
53
54 loadConfigFiles("/org/apache/shale/clay/config/altns-config.xml", null);
55
56
57 servletContext.addInitParameter("org.apache.commons.chain.CONFIG_WEB_RESOURCE", "/org/apache/shale/clay/config/chain-config.xml");
58 ServletContextListener chainsListener = new ChainListener();
59 ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext);
60 chainsListener.contextInitialized(servletContextEvent);
61
62
63 ComponentBean configBean = standardConfigBean.getElement("acme:city");
64 assertNotNull("acme:city exists", configBean);
65 assertEquals("id", "city", configBean.getId());
66
67 AttributeBean size = configBean.getAttribute("size");
68 assertNotNull("size", size);
69 assertEquals("size", "20", size.getValue());
70
71 AttributeBean value = configBean.getAttribute("value");
72 assertNotNull("value", value);
73 assertEquals("value", "#{@managed-bean-name.city}", value.getValue());
74
75 AttributeBean maxlength = configBean.getAttribute("maxlength");
76 assertNotNull("maxlength", maxlength);
77 assertEquals("maxlength", "30", maxlength.getValue());
78
79 AttributeBean required = configBean.getAttribute("required");
80 assertNotNull("required", required);
81 assertEquals("required", "true", required.getValue());
82
83
84
85 ComponentBean templateRoot = htmlTemplateConfigBean.getElement("/org/apache/shale/clay/config/altns.html");
86 assertNotNull("/org/apache/shale/clay/config/altns.html", templateRoot);
87
88
89 ComponentBean cityConfigBean = findForId(configBean.getId(), templateRoot);
90 assertNotNull("city from html template", cityConfigBean);
91
92
93 assertEquals("id", "city", cityConfigBean.getId());
94
95
96 size = cityConfigBean.getAttribute("size");
97 assertNotNull("size", size);
98 assertEquals("size", "10", size.getValue());
99
100
101 value = cityConfigBean.getAttribute("value");
102 assertNotNull("value", value);
103 assertEquals("value", "#{@managed-bean-name.city}", value.getValue());
104
105
106 maxlength = cityConfigBean.getAttribute("maxlength");
107 assertNotNull("maxlength", maxlength);
108 assertEquals("maxlength", "100", maxlength.getValue());
109
110
111 required = cityConfigBean.getAttribute("required");
112 assertNotNull("required", required);
113 assertEquals("required", "false", required.getValue());
114
115
116 chainsListener.contextDestroyed(servletContextEvent);
117 }
118
119 private ComponentBean findForId(String id, ComponentBean root) {
120 if (root.getId() != null && root.getId().equals(id)) {
121 return root;
122 }
123 Iterator ci = root.getChildren().iterator();
124 while (ci.hasNext()) {
125 ComponentBean child = (ComponentBean) ci.next();
126 ComponentBean target = findForId(id, child);
127 if (target != null) {
128 return target;
129 }
130 }
131
132 return null;
133 }
134
135 }