001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestJanino2ElementInfo.java 3693 2007-03-14 10:55:56Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import com.uwyn.rife.rep.Rep;
011: import com.uwyn.rife.resources.ResourceFinderClasspath;
012: import java.util.LinkedHashMap;
013: import junit.framework.TestCase;
014:
015: public class TestJanino2ElementInfo extends TestCase {
016: public TestJanino2ElementInfo(String name) {
017: super (name);
018: }
019:
020: public void testParser() {
021: SiteBuilder site_builder = new SiteBuilder("test",
022: ResourceFinderClasspath.getInstance());
023: ElementInfoBuilder elementinfo_builder = site_builder
024: .enterElement("janino:janino/test_janino2elementinfo1.janino");
025:
026: elementinfo_builder.process();
027:
028: ElementInfo elementinfo = elementinfo_builder
029: .createElementInfo(
030: new LinkedHashMap<String, GlobalExit>(),
031: new LinkedHashMap<String, GlobalVar>(),
032: new LinkedHashMap<String, String>(),
033: new LinkedHashMap<String, BeanDeclaration>());
034:
035: assertEquals(elementinfo.getPropertyNames().size(), 4 + Rep
036: .getProperties().size());
037: assertTrue(elementinfo.containsProperty("property1"));
038: assertTrue(elementinfo.containsProperty("property2"));
039: assertTrue(elementinfo.containsProperty("property3"));
040: assertTrue(elementinfo.containsProperty("property4"));
041: assertEquals("value1", elementinfo.getProperty("property1"));
042: assertEquals("value2", elementinfo.getProperty("property2"));
043: assertEquals("value3", elementinfo.getProperty("property3"));
044: assertEquals("value4", elementinfo.getProperty("property4"));
045:
046: assertEquals(elementinfo.getInputNames().size(), 26);
047: assertTrue(elementinfo.containsInput("input1"));
048: assertTrue(elementinfo.containsInput("input2"));
049: assertTrue(elementinfo.containsInput("input3"));
050: assertTrue(elementinfo.containsInput("string1"));
051: assertTrue(elementinfo.containsInput("string2"));
052: assertTrue(elementinfo.containsInput("string3"));
053: assertTrue(elementinfo.containsInput("enum4"));
054: assertTrue(elementinfo.containsInput("date5"));
055: assertTrue(elementinfo.containsInput("string6"));
056: assertTrue(elementinfo.containsInput("string7"));
057: assertTrue(elementinfo.containsInput("string8"));
058: assertTrue(elementinfo.containsInput("prefix_string1"));
059: assertTrue(elementinfo.containsInput("prefix_string2"));
060: assertTrue(elementinfo.containsInput("prefix_string3"));
061: assertTrue(elementinfo.containsInput("prefix_enum4"));
062: assertTrue(elementinfo.containsInput("prefix_date5"));
063: assertTrue(elementinfo.containsInput("prefixgroup_enum"));
064: assertTrue(elementinfo.containsInput("prefixgroup_string"));
065: assertTrue(elementinfo.containsInput("prefixgroup_int"));
066: assertTrue(elementinfo.containsInput("prefixgroup_longObject"));
067: assertTrue(elementinfo.containsInput("prefixgroup_short"));
068: assertTrue(elementinfo.containsInput("enum"));
069: assertTrue(elementinfo.containsInput("string"));
070: assertTrue(elementinfo.containsInput("int"));
071: assertTrue(elementinfo.containsInput("longObject"));
072: assertTrue(elementinfo.containsInput("short"));
073:
074: assertEquals(elementinfo.getOutputNames().size(), 27);
075: assertTrue(elementinfo.containsOutput("output1"));
076: assertTrue(elementinfo.containsOutput("output2"));
077: assertTrue(elementinfo.containsOutput("output3"));
078: assertTrue(elementinfo.containsOutput("output4"));
079: assertTrue(elementinfo.containsOutput("string1"));
080: assertTrue(elementinfo.containsOutput("string2"));
081: assertTrue(elementinfo.containsOutput("string3"));
082: assertTrue(elementinfo.containsOutput("enum4"));
083: assertTrue(elementinfo.containsOutput("date5"));
084: assertTrue(elementinfo.containsOutput("string6"));
085: assertTrue(elementinfo.containsOutput("string7"));
086: assertTrue(elementinfo.containsOutput("string8"));
087: assertTrue(elementinfo.containsOutput("prefix_enum4"));
088: assertTrue(elementinfo.containsOutput("prefix_date5"));
089: assertTrue(elementinfo.containsOutput("prefix_string6"));
090: assertTrue(elementinfo.containsOutput("prefix_string7"));
091: assertTrue(elementinfo.containsOutput("prefix_string8"));
092: assertTrue(elementinfo.containsOutput("prefixgroup_enum"));
093: assertTrue(elementinfo.containsOutput("prefixgroup_string"));
094: assertTrue(elementinfo.containsOutput("prefixgroup_int"));
095: assertTrue(elementinfo.containsOutput("prefixgroup_longObject"));
096: assertTrue(elementinfo.containsOutput("prefixgroup_short"));
097: assertTrue(elementinfo.containsOutput("enum"));
098: assertTrue(elementinfo.containsOutput("string"));
099: assertTrue(elementinfo.containsOutput("int"));
100: assertTrue(elementinfo.containsOutput("longObject"));
101: assertTrue(elementinfo.containsOutput("short"));
102:
103: assertEquals(elementinfo.getIncookieNames().size(), 2);
104: assertTrue(elementinfo.containsIncookie("incookie1"));
105: assertTrue(elementinfo.containsIncookie("incookie2"));
106:
107: assertEquals(elementinfo.getOutcookieNames().size(), 4);
108: assertTrue(elementinfo.containsOutcookie("outcookie1"));
109: assertTrue(elementinfo.containsOutcookie("outcookie2"));
110: assertTrue(elementinfo.containsOutcookie("outcookie3"));
111: assertTrue(elementinfo.containsOutcookie("outcookie4"));
112:
113: assertEquals(elementinfo.getNamedInbeanNames().size(), 2);
114: assertTrue(elementinfo.containsNamedInbean("inbean1"));
115: assertEquals(elementinfo.getNamedInbeanInfo("inbean1")
116: .getClassname(),
117: "com.uwyn.rife.engine.testelements.exits.BeanImpl1");
118: assertEquals(elementinfo.getNamedInbeanInfo("inbean1")
119: .getPrefix(), null);
120: assertEquals(elementinfo.getNamedInbeanInfo("inbean1")
121: .getGroupName(), null);
122: assertTrue(elementinfo.containsNamedInbean("inbean2"));
123: assertEquals(elementinfo.getNamedInbeanInfo("inbean2")
124: .getClassname(),
125: "com.uwyn.rife.engine.testelements.submission.BeanImpl");
126: assertEquals(elementinfo.getNamedInbeanInfo("inbean2")
127: .getPrefix(), "prefixgroup_");
128: assertEquals(elementinfo.getNamedInbeanInfo("inbean2")
129: .getGroupName(), "somegroup");
130:
131: assertEquals(elementinfo.getNamedOutbeanNames().size(), 2);
132: assertTrue(elementinfo.containsNamedOutbean("outbean1"));
133: assertEquals(elementinfo.getNamedOutbeanInfo("outbean1")
134: .getClassname(),
135: "com.uwyn.rife.engine.testelements.exits.BeanImpl2");
136: assertEquals(elementinfo.getNamedOutbeanInfo("outbean1")
137: .getPrefix(), "prefix_");
138: assertEquals(elementinfo.getNamedOutbeanInfo("outbean1")
139: .getGroupName(), null);
140: assertTrue(elementinfo.containsNamedOutbean("outbean2"));
141: assertEquals(elementinfo.getNamedOutbeanInfo("outbean2")
142: .getClassname(),
143: "com.uwyn.rife.engine.testelements.submission.BeanImpl");
144: assertEquals(elementinfo.getNamedOutbeanInfo("outbean2")
145: .getPrefix(), null);
146: assertEquals(elementinfo.getNamedOutbeanInfo("outbean2")
147: .getGroupName(), "somegroup");
148:
149: assertEquals(elementinfo.getChildTriggerNames().size(), 2);
150: assertTrue(elementinfo.containsChildTrigger("input1"));
151: assertTrue(elementinfo.containsChildTrigger("input2"));
152:
153: assertEquals(elementinfo.getExitNames().size(), 4);
154: assertTrue(elementinfo.containsExit("exit1"));
155: assertTrue(elementinfo.containsExit("exit2"));
156: assertTrue(elementinfo.containsExit("exit3"));
157: assertTrue(elementinfo.containsExit("exit4"));
158:
159: assertEquals(elementinfo.getSubmissionNames().size(), 2);
160: assertTrue(elementinfo.containsSubmission("submission1"));
161: assertTrue(elementinfo.containsSubmission("submission2"));
162:
163: assertNotNull(elementinfo.getSubmission("submission1"));
164: assertNotNull(elementinfo.getSubmission("submission2"));
165:
166: assertEquals(elementinfo.getSubmission("submission1")
167: .getParameterNames().size(), 3);
168: assertTrue(elementinfo.getSubmission("submission1")
169: .containsParameter("param1"));
170: assertTrue(elementinfo.getSubmission("submission1")
171: .containsParameter("param2"));
172: assertTrue(elementinfo.getSubmission("submission1")
173: .containsParameter("param3"));
174: assertEquals(elementinfo.getSubmission("submission1")
175: .getParameterRegexps().size(), 2);
176: assertTrue(elementinfo.getSubmission("submission1")
177: .containsParameter("paramA1"));
178: assertTrue(elementinfo.getSubmission("submission1")
179: .containsParameter("paramA2"));
180: assertTrue(elementinfo.getSubmission("submission1")
181: .containsParameter("paramB1"));
182: assertTrue(elementinfo.getSubmission("submission1")
183: .containsParameter("paramB2"));
184: assertEquals(elementinfo.getSubmission("submission1")
185: .getFileNames().size(), 2);
186: assertTrue(elementinfo.getSubmission("submission1")
187: .containsFile("file1"));
188: assertTrue(elementinfo.getSubmission("submission1")
189: .containsFile("file2"));
190:
191: assertEquals(elementinfo.getSubmission("submission2")
192: .getParameterNames().size(), 2);
193: assertTrue(elementinfo.getSubmission("submission2")
194: .containsParameter("param1"));
195: assertTrue(elementinfo.getSubmission("submission2")
196: .containsParameter("param2"));
197: assertEquals(elementinfo.getSubmission("submission2")
198: .getParameterRegexps().size(), 1);
199: assertTrue(elementinfo.getSubmission("submission2")
200: .containsParameter("paramC1"));
201: assertTrue(elementinfo.getSubmission("submission2")
202: .containsParameter("paramC2"));
203: assertEquals(elementinfo.getSubmission("submission2")
204: .getFileNames().size(), 1);
205: assertTrue(elementinfo.getSubmission("submission2")
206: .containsFile("file1"));
207:
208: assertEquals(elementinfo.getSubmission("submission2")
209: .getParameterDefaultValues("param1")[0], "default1");
210: assertEquals(elementinfo.getSubmission("submission2")
211: .getParameterDefaultValues("param1")[1], "default2");
212: }
213: }
|