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.io.ByteArrayInputStream;
20 import java.io.ByteArrayOutputStream;
21 import java.io.ObjectInputStream;
22 import java.io.ObjectOutputStream;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import org.apache.shale.clay.config.beans.AttributeBean;
28 import org.apache.shale.clay.config.beans.ComponentBean;
29 import org.apache.shale.clay.config.beans.ComponentConfigBean;
30 import org.apache.shale.clay.config.beans.SymbolBean;
31
32 public class DesigntimeTestCase extends AbstractTestCaseConfig {
33
34
35 public DesigntimeTestCase(String name) {
36 super(name);
37 }
38
39
40 public static Test suite() {
41
42 return (new TestSuite(DesigntimeTestCase.class));
43
44 }
45
46 protected void setUp() throws Exception {
47 super.setUp();
48 }
49
50 public void testDesigntimeOn() {
51 ((ComponentConfigBean) standardConfigBean).setDesigntime(true);
52 loadConfigFiles(null, null);
53
54 ComponentBean bean = standardConfigBean.getElement("clay");
55 assertNotNull(bean);
56
57 String description = bean.getDescription();
58 assertNotNull(description);
59
60 assertTrue(description.startsWith("This component builds a sub component tree and attaches"));
61
62 AttributeBean attr = bean.getAttribute("managedBeanName");
63 assertNotNull(attr);
64
65 description = attr.getDescription();
66 assertEquals("A symbol that is used to alias the bound backing bean.", description);
67
68
69 bean = standardConfigBean.getElement("baseHtml");
70 assertNotNull(bean);
71
72 description = bean.getDescription();
73 assertNotNull(description);
74
75 assertTrue(description.startsWith("Abstract base component definition"));
76
77 SymbolBean symbol = (SymbolBean) bean.getSymbols().get("@class");
78 assertNotNull(symbol);
79
80 description = symbol.getDescription();
81 assertNotNull(description);
82
83 assertEquals("The default value of the styleClass attribute.", description);
84
85
86 }
87
88
89 public void testDesigntimeOff() {
90 ((ComponentConfigBean) standardConfigBean).setDesigntime(false);
91 loadConfigFiles(null, null);
92
93 ComponentBean bean = standardConfigBean.getElement("clay");
94 assertNotNull(bean);
95
96 String description = bean.getDescription();
97 assertNull(description);
98
99 AttributeBean attr = bean.getAttribute("managedBeanName");
100 assertNotNull(attr);
101
102 description = attr.getDescription();
103 assertNull(description);
104
105 bean = standardConfigBean.getElement("baseHtml");
106 assertNotNull(bean);
107
108 description = bean.getDescription();
109 assertNull(description);
110
111 SymbolBean symbol = (SymbolBean) bean.getSymbols().get("@class");
112 assertNotNull(symbol);
113
114 description = symbol.getDescription();
115 assertNull(description);
116
117 }
118
119
120 public void testDesigntimeOnInheritance() {
121 ((ComponentConfigBean) standardConfigBean).setDesigntime(true);
122 loadConfigFiles(null, null);
123
124 ComponentBean bean1 = standardConfigBean.getElement("f:converter");
125 assertNotNull(bean1);
126
127 assertNotNull(bean1.getDescription());
128
129 ComponentBean bean2 = standardConfigBean.getElement(bean1.getExtends());
130 assertNotNull(bean2);
131
132 assertNotNull(bean2.getDescription());
133 assertEquals(bean2.getDescription(), bean1.getDescription());
134
135 }
136
137
138 public void testSerializable() throws Exception {
139
140
141 ((ComponentConfigBean) standardConfigBean).setDesigntime(true);
142 loadConfigFiles(null, null);
143
144 ComponentBean live = standardConfigBean.getElement("h:outputText");
145 assertNotNull(live);
146
147 ByteArrayOutputStream os = new ByteArrayOutputStream();
148 ObjectOutputStream out = new ObjectOutputStream(os);
149 out.writeObject(live);
150 out.close();
151
152
153 ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
154 ObjectInputStream in = new ObjectInputStream(is);
155
156 ComponentBean memorex = (ComponentBean) in.readObject();
157 in.close();
158
159 assertNotNull(memorex);
160
161 assertEquals(live.getDescription(), memorex.getDescription());
162 assertEquals(live.getJsfid(), memorex.getJsfid());
163 assertEquals(live.getAttribute("styleClass").getValue(), memorex.getAttribute("styleClass").getValue());
164 assertEquals(live.getSymbol("class").getValue(), memorex.getSymbol("class").getValue());
165
166 }
167 }