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.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 import org.apache.shale.clay.config.beans.AttributeBean;
27 import org.apache.shale.clay.config.beans.ComponentBean;
28 import org.apache.shale.clay.config.beans.SymbolBean;
29
30 public class LimitedJspxTestCase extends AbstractTestCaseConfig {
31
32
33 public LimitedJspxTestCase(String name) {
34 super(name);
35 }
36
37
38 public static Test suite() {
39
40 return (new TestSuite(LimitedJspxTestCase.class));
41 }
42
43 public void testJpx() {
44 loadConfigFile(null);
45
46 ComponentBean document = htmlTemplateConfigBean.getElement("/org/apache/shale/clay/config/limited-jspx.html");
47 assertNotNull(document);
48
49 assertEquals("void component count", 2, countVoidComponents(document));
50
51 List clayIncludes = findClayJspxInclude(document);
52 assertEquals("includes", 2, clayIncludes.size());
53
54 Iterator ci = clayIncludes.iterator();
55 while (ci.hasNext()) {
56 ComponentBean clayInclude = (ComponentBean) ci.next();
57 if (clayInclude.getSymbol("@file") != null) {
58
59 SymbolBean symbol = clayInclude.getSymbol("@file");
60 assertNotNull("file symbol", symbol);
61 assertEquals("/org/apache/shale/clay/config/address1.html", symbol.getValue());
62
63 AttributeBean attr = clayInclude.getAttribute("clayJsfid");
64 assertNotNull("clayJsfid", attr);
65 assertEquals("@file", attr.getValue());
66
67
68 } else if (clayInclude.getSymbol("@page") != null) {
69
70 SymbolBean symbol = clayInclude.getSymbol("@page");
71 assertNotNull("file symbol", symbol);
72 assertEquals("/org/apache/shale/clay/config/address1.html", symbol.getValue());
73
74 AttributeBean attr = clayInclude.getAttribute("clayJsfid");
75 assertNotNull("clayJsfid", attr);
76 assertEquals("@page", attr.getValue());
77
78 for (int i = 0; i < 5; i++) {
79 symbol = clayInclude.getSymbol("@symbol" + i);
80 assertNotNull("@symbol" + i, symbol);
81 assertEquals("value" + i, symbol.getValue());
82 }
83
84 } else {
85 assertFalse("invalid include mapping", true);
86 }
87 }
88
89 }
90
91
92 public int countVoidComponents(ComponentBean bean) {
93 int voidcnt = 0;
94
95 if (bean.getJsfid().equals("void")) {
96 voidcnt++;
97 }
98
99 Iterator ci = bean.getChildren().iterator();
100 while (ci.hasNext()) {
101 ComponentBean child = (ComponentBean) ci.next();
102 voidcnt += countVoidComponents(child);
103 }
104
105 return voidcnt;
106 }
107
108
109 public List findClayJspxInclude(ComponentBean bean) {
110 List beans = new ArrayList();
111
112 if (bean.getJsfid().equals("clay")) {
113 beans.add(bean);
114 }
115 Iterator ci = bean.getChildren().iterator();
116 while (ci.hasNext()) {
117 beans.addAll(findClayJspxInclude((ComponentBean) ci.next()));
118 }
119
120 return beans;
121 }
122 }