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: TestXml2ElementInfo.java 3693 2007-03-14 10:55:56Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import com.uwyn.rife.database.Datasources;
011: import com.uwyn.rife.engine.exceptions.ParsingErrorException;
012: import com.uwyn.rife.engine.exceptions.PropertyValueRetrievalException;
013: import com.uwyn.rife.ioc.exceptions.ParticipantUnknownException;
014: import com.uwyn.rife.ioc.exceptions.TemplateFactoryUnknownException;
015: import com.uwyn.rife.rep.Rep;
016: import com.uwyn.rife.resources.ResourceFinderClasspath;
017: import com.uwyn.rife.template.Template;
018: import com.uwyn.rife.template.TemplateFactory;
019: import java.util.LinkedHashMap;
020: import junit.framework.TestCase;
021:
022: public class TestXml2ElementInfo extends TestCase {
023: public TestXml2ElementInfo(String name) {
024: super (name);
025: }
026:
027: public void testInstantiation() {
028: SiteBuilder site_builder = new SiteBuilder("test",
029: ResourceFinderClasspath.getInstance());
030: ElementInfoBuilder elementinfo_builder = site_builder
031: .enterElement("manual://test");
032:
033: assertNotNull(elementinfo_builder);
034: }
035:
036: public void testParser() {
037: SiteBuilder site_builder = new SiteBuilder("test",
038: ResourceFinderClasspath.getInstance());
039: ElementInfoBuilder elementinfo_builder = site_builder
040: .enterElement("xml:xml/test_xml2elementinfo1.xml");
041:
042: elementinfo_builder.process();
043:
044: ElementInfo elementinfo = elementinfo_builder
045: .createElementInfo(
046: new LinkedHashMap<String, GlobalExit>(),
047: new LinkedHashMap<String, GlobalVar>(),
048: new LinkedHashMap<String, String>(),
049: new LinkedHashMap<String, BeanDeclaration>());
050:
051: assertEquals(elementinfo.getPropertyNames().size(), 7 + Rep
052: .getProperties().size());
053: assertTrue(elementinfo.containsProperty("property1"));
054: assertTrue(elementinfo.containsProperty("property2"));
055: assertTrue(elementinfo.containsProperty("property3"));
056: assertTrue(elementinfo.containsProperty("property4"));
057: assertEquals("value1", elementinfo.getProperty("property1"));
058: assertTrue(elementinfo.getProperty("property2") instanceof Template);
059: assertEquals(((Template) elementinfo.getProperty("property2"))
060: .getContent(), TemplateFactory.ENGINEHTML.get(
061: "noblocks_in").getContent());
062: assertEquals("the value 3", elementinfo
063: .getProperty("property3"));
064: assertSame(Datasources.getRepInstance().getDatasource(
065: "unittestspgsql"), elementinfo.getProperty("property4"));
066: assertEquals("unittests\n pgsql", elementinfo
067: .getProperty("property5"));
068: try {
069: elementinfo.getProperty("property6");
070: fail("exception wasn't thrown");
071: } catch (PropertyValueRetrievalException e) {
072: assertTrue(e.getCause() instanceof ParticipantUnknownException);
073: assertEquals("doesntexist",
074: ((ParticipantUnknownException) e.getCause())
075: .getName());
076: }
077: try {
078: elementinfo.getProperty("property7");
079: fail("exception wasn't thrown");
080: } catch (PropertyValueRetrievalException e) {
081: assertTrue(e.getCause() instanceof TemplateFactoryUnknownException);
082: assertEquals("unknowntype",
083: ((TemplateFactoryUnknownException) e.getCause())
084: .getType());
085: }
086:
087: assertEquals(elementinfo.getInputNames().size(), 26);
088: assertTrue(elementinfo.containsInput("input1"));
089: assertTrue(elementinfo.containsInput("input2"));
090: assertTrue(elementinfo.containsInput("input3"));
091: assertTrue(elementinfo.containsInput("string1"));
092: assertTrue(elementinfo.containsInput("string2"));
093: assertTrue(elementinfo.containsInput("string3"));
094: assertTrue(elementinfo.containsInput("enum4"));
095: assertTrue(elementinfo.containsInput("date5"));
096: assertTrue(elementinfo.containsInput("string6"));
097: assertTrue(elementinfo.containsInput("string7"));
098: assertTrue(elementinfo.containsInput("string8"));
099: assertTrue(elementinfo.containsInput("prefix_string1"));
100: assertTrue(elementinfo.containsInput("prefix_string2"));
101: assertTrue(elementinfo.containsInput("prefix_string3"));
102: assertTrue(elementinfo.containsInput("prefix_enum4"));
103: assertTrue(elementinfo.containsInput("prefix_date5"));
104: assertTrue(elementinfo.containsInput("prefixgroup_enum"));
105: assertTrue(elementinfo.containsInput("prefixgroup_string"));
106: assertTrue(elementinfo.containsInput("prefixgroup_int"));
107: assertTrue(elementinfo.containsInput("prefixgroup_longObject"));
108: assertTrue(elementinfo.containsInput("prefixgroup_short"));
109: assertTrue(elementinfo.containsInput("enum"));
110: assertTrue(elementinfo.containsInput("string"));
111: assertTrue(elementinfo.containsInput("int"));
112: assertTrue(elementinfo.containsInput("longObject"));
113: assertTrue(elementinfo.containsInput("short"));
114:
115: assertEquals(elementinfo.getOutputNames().size(), 27);
116: assertTrue(elementinfo.containsOutput("output1"));
117: assertTrue(elementinfo.containsOutput("output2"));
118: assertTrue(elementinfo.containsOutput("output3"));
119: assertTrue(elementinfo.containsOutput("output4"));
120: assertTrue(elementinfo.containsOutput("string1"));
121: assertTrue(elementinfo.containsOutput("string2"));
122: assertTrue(elementinfo.containsOutput("string3"));
123: assertTrue(elementinfo.containsOutput("enum4"));
124: assertTrue(elementinfo.containsOutput("date5"));
125: assertTrue(elementinfo.containsOutput("string6"));
126: assertTrue(elementinfo.containsOutput("string7"));
127: assertTrue(elementinfo.containsOutput("string8"));
128: assertTrue(elementinfo.containsOutput("prefix_enum4"));
129: assertTrue(elementinfo.containsOutput("prefix_date5"));
130: assertTrue(elementinfo.containsOutput("prefix_string6"));
131: assertTrue(elementinfo.containsOutput("prefix_string7"));
132: assertTrue(elementinfo.containsOutput("prefix_string8"));
133: assertTrue(elementinfo.containsOutput("prefixgroup_enum"));
134: assertTrue(elementinfo.containsOutput("prefixgroup_string"));
135: assertTrue(elementinfo.containsOutput("prefixgroup_int"));
136: assertTrue(elementinfo.containsOutput("prefixgroup_longObject"));
137: assertTrue(elementinfo.containsOutput("prefixgroup_short"));
138: assertTrue(elementinfo.containsOutput("enum"));
139: assertTrue(elementinfo.containsOutput("string"));
140: assertTrue(elementinfo.containsOutput("int"));
141: assertTrue(elementinfo.containsOutput("longObject"));
142: assertTrue(elementinfo.containsOutput("short"));
143:
144: assertEquals(elementinfo.getIncookieNames().size(), 2);
145: assertTrue(elementinfo.containsIncookie("incookie1"));
146: assertTrue(elementinfo.containsIncookie("incookie2"));
147:
148: assertEquals(elementinfo.getOutcookieNames().size(), 4);
149: assertTrue(elementinfo.containsOutcookie("outcookie1"));
150: assertTrue(elementinfo.containsOutcookie("outcookie2"));
151: assertTrue(elementinfo.containsOutcookie("outcookie3"));
152: assertTrue(elementinfo.containsOutcookie("outcookie4"));
153:
154: assertEquals(elementinfo.getNamedInbeanNames().size(), 2);
155: assertTrue(elementinfo.containsNamedInbean("inbean1"));
156: assertEquals(elementinfo.getNamedInbeanInfo("inbean1")
157: .getClassname(),
158: "com.uwyn.rife.engine.testelements.exits.BeanImpl1");
159: assertEquals(elementinfo.getNamedInbeanInfo("inbean1")
160: .getPrefix(), null);
161: assertEquals(elementinfo.getNamedInbeanInfo("inbean1")
162: .getGroupName(), null);
163: assertTrue(elementinfo.containsNamedInbean("inbean2"));
164: assertEquals(elementinfo.getNamedInbeanInfo("inbean2")
165: .getClassname(),
166: "com.uwyn.rife.engine.testelements.submission.BeanImpl");
167: assertEquals(elementinfo.getNamedInbeanInfo("inbean2")
168: .getPrefix(), "prefixgroup_");
169: assertEquals(elementinfo.getNamedInbeanInfo("inbean2")
170: .getGroupName(), "somegroup");
171:
172: assertEquals(elementinfo.getNamedOutbeanNames().size(), 2);
173: assertTrue(elementinfo.containsNamedOutbean("outbean1"));
174: assertEquals(elementinfo.getNamedOutbeanInfo("outbean1")
175: .getClassname(),
176: "com.uwyn.rife.engine.testelements.exits.BeanImpl2");
177: assertEquals(elementinfo.getNamedOutbeanInfo("outbean1")
178: .getPrefix(), "prefix_");
179: assertEquals(elementinfo.getNamedOutbeanInfo("outbean1")
180: .getGroupName(), null);
181: assertTrue(elementinfo.containsNamedOutbean("outbean2"));
182: assertEquals(elementinfo.getNamedOutbeanInfo("outbean2")
183: .getClassname(),
184: "com.uwyn.rife.engine.testelements.submission.BeanImpl");
185: assertEquals(elementinfo.getNamedOutbeanInfo("outbean2")
186: .getPrefix(), null);
187: assertEquals(elementinfo.getNamedOutbeanInfo("outbean2")
188: .getGroupName(), "somegroup");
189:
190: assertEquals(elementinfo.getChildTriggerNames().size(), 2);
191: assertTrue(elementinfo.containsChildTrigger("input1"));
192: assertTrue(elementinfo.containsChildTrigger("input2"));
193:
194: assertEquals(elementinfo.getExitNames().size(), 4);
195: assertTrue(elementinfo.containsExit("exit1"));
196: assertTrue(elementinfo.containsExit("exit2"));
197: assertTrue(elementinfo.containsExit("exit3"));
198: assertTrue(elementinfo.containsExit("exit4"));
199:
200: assertEquals(elementinfo.getSubmissionNames().size(), 2);
201: assertTrue(elementinfo.containsSubmission("submission1"));
202: assertTrue(elementinfo.containsSubmission("submission2"));
203:
204: assertNotNull(elementinfo.getSubmission("submission1"));
205: assertNotNull(elementinfo.getSubmission("submission2"));
206:
207: assertEquals(elementinfo.getSubmission("submission1")
208: .getParameterNames().size(), 3);
209: assertTrue(elementinfo.getSubmission("submission1")
210: .containsParameter("param1"));
211: assertTrue(elementinfo.getSubmission("submission1")
212: .containsParameter("param2"));
213: assertTrue(elementinfo.getSubmission("submission1")
214: .containsParameter("param3"));
215: assertEquals(elementinfo.getSubmission("submission1")
216: .getParameterRegexps().size(), 2);
217: assertTrue(elementinfo.getSubmission("submission1")
218: .containsParameter("paramA1"));
219: assertTrue(elementinfo.getSubmission("submission1")
220: .containsParameter("paramA2"));
221: assertTrue(elementinfo.getSubmission("submission1")
222: .containsParameter("paramB1"));
223: assertTrue(elementinfo.getSubmission("submission1")
224: .containsParameter("paramB2"));
225: assertEquals(elementinfo.getSubmission("submission1")
226: .getFileNames().size(), 2);
227: assertTrue(elementinfo.getSubmission("submission1")
228: .containsFile("file1"));
229: assertTrue(elementinfo.getSubmission("submission1")
230: .containsFile("file2"));
231:
232: assertEquals(elementinfo.getSubmission("submission2")
233: .getParameterNames().size(), 2);
234: assertTrue(elementinfo.getSubmission("submission2")
235: .containsParameter("param1"));
236: assertTrue(elementinfo.getSubmission("submission2")
237: .containsParameter("param2"));
238: assertEquals(elementinfo.getSubmission("submission2")
239: .getParameterRegexps().size(), 1);
240: assertTrue(elementinfo.getSubmission("submission2")
241: .containsParameter("paramC1"));
242: assertTrue(elementinfo.getSubmission("submission2")
243: .containsParameter("paramC2"));
244: assertEquals(elementinfo.getSubmission("submission2")
245: .getFileNames().size(), 1);
246: assertTrue(elementinfo.getSubmission("submission2")
247: .containsFile("file1"));
248: }
249:
250: public void testFlawedSubmissionParamRegexpname() {
251: SiteBuilder site_builder = new SiteBuilder("test",
252: ResourceFinderClasspath.getInstance());
253: ElementInfoBuilder elementinfo_builder = site_builder
254: .enterElement("element/flawed/submission_param_regexpname.xml");
255:
256: try {
257: elementinfo_builder.process();
258: fail();
259: } catch (ParsingErrorException e) {
260: assertTrue(true);
261: }
262: }
263:
264: public void testFlawedSubmissionParamRegexpdefaults() {
265: SiteBuilder site_builder = new SiteBuilder("test",
266: ResourceFinderClasspath.getInstance());
267: ElementInfoBuilder elementinfo_builder = site_builder
268: .enterElement("element/flawed/submission_param_regexpdefaults.xml");
269:
270: try {
271: elementinfo_builder.process();
272: fail();
273: } catch (ParsingErrorException e) {
274: assertTrue(true);
275: }
276: }
277: }
|