001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2005 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: Factory.java,v 1.11 2007/03/29 11:45:42 schnelle Exp $
021: *
022: * $Log: Factory.java,v $
023: * Revision 1.11 2007/03/29 11:45:42 schnelle
024: * Code cleanup.
025: *
026: * Revision 1.10 2007/03/27 21:59:42 mlipp
027: * Fixed lots of checkstyle warnings.
028: *
029: * Revision 1.9 2007/03/01 12:29:30 schnelle
030: * Enhanced Instance.SetProperties to process ContextData.
031: *
032: * Revision 1.8 2007/02/02 08:18:29 schnelle
033: * Prepared tests with an Umlaut.
034: *
035: * Revision 1.7 2007/02/01 12:39:13 schnelle
036: * Use of receiver toool to keep the first activity running.
037: *
038: * Revision 1.6 2007/02/01 08:49:23 drmlipp
039: * Fixed.
040: *
041: * Revision 1.5 2007/01/31 15:13:20 schnelle
042: * Unified method to create the base url.
043: *
044: * Revision 1.4 2007/01/31 13:39:45 schnelle
045: * Implemented setUp of test cases.
046: *
047: * Revision 1.3 2007/01/31 10:57:36 schnelle
048: * Adapted to change in receiver key.
049: *
050: * Revision 1.2 2007/01/30 11:56:15 drmlipp
051: * Merged Wf-XML branch.
052: *
053: * Revision 1.1.2.6 2006/12/20 14:38:33 schnelle
054: * Implemented Factory GetDefinition.
055: *
056: * Revision 1.1.2.5 2006/12/19 14:44:12 schnelle
057: * Implementation of GetProperties for ServiceRegistry and Factory.
058: *
059: * Revision 1.1.2.4 2006/12/14 08:51:05 schnelle
060: * Implemented CompleteActivity.
061: *
062: * Revision 1.1.2.3 2006/12/12 09:35:19 schnelle
063: * Implemented ChangeState for Instance.
064: *
065: * Revision 1.1.2.2 2006/12/11 12:22:31 schnelle
066: * Support of process creation with a later start.
067: *
068: * Revision 1.1.2.1 2006/12/01 15:31:28 schnelle
069: * Separation of test cases dependend on the role.
070: *
071: * Revision 1.4.6.7 2006/12/01 14:18:00 schnelle
072: * Added support for schema type for data in create process
073: *
074: * Revision 1.4.6.6 2006/12/01 12:50:11 schnelle
075: * Basic import of context data for process creation.
076: *
077: * Revision 1.4.6.5 2006/11/30 12:45:20 schnelle
078: * Basic implementation of Factory CreateInstance.
079: *
080: * Revision 1.4.6.4 2006/11/30 10:38:21 schnelle
081: * Implementation of Factory ListInstance.
082: *
083: * Revision 1.4.6.3 2006/11/29 14:13:03 schnelle
084: * Take respect to namespaces of asap requests and responses.
085: *
086: * Revision 1.4.6.2 2006/11/29 11:05:40 schnelle
087: * Full implementation of the request and response headers.
088: *
089: * Revision 1.4.6.1 2006/11/28 15:32:35 schnelle
090: * Proper selection of the response generator.
091: *
092: * Revision 1.4 2006/09/29 12:32:11 drmlipp
093: * Consistently using WfMOpen as projct name now.
094: *
095: * Revision 1.3 2005/01/24 21:11:39 mlipp
096: * Extended.
097: *
098: * Revision 1.2 2005/01/24 20:26:01 mlipp
099: * Reverted saaj back to 1.1 to fit Axis version.
100: *
101: * Revision 1.1 2005/01/23 21:44:23 mlipp
102: * Initial version.
103: *
104: */
105: package wfxml;
106:
107: import java.util.Iterator;
108:
109: import javax.xml.soap.Name;
110: import javax.xml.soap.SOAPBodyElement;
111: import javax.xml.soap.SOAPElement;
112: import javax.xml.soap.SOAPException;
113: import javax.xml.soap.SOAPMessage;
114:
115: import junit.framework.Test;
116: import junit.framework.TestCase;
117: import junit.framework.TestSuite;
118: import de.danet.an.util.XMLUtil;
119:
120: /**
121: * Test WfXML factory resource.
122: * @author Dirk Schnelle
123: */
124: public class Factory extends TestCase {
125: /** The factory resource. */
126: private String factory;
127:
128: private String timestamp;
129:
130: /**
131: * Constructor of this TestCase.
132: * @param name name of this test case.
133: */
134: public Factory(String name) {
135: super (name);
136: }
137:
138: /**
139: * Creates this test suite.
140: * @return created test suite.
141: */
142: public static Test suite() {
143: TestSuite suite = new TestSuite();
144: suite
145: .addTest(new Factory(
146: "createProcInstanceStartImmediately"));
147: suite.addTest(new Factory("createProcInstanceStartLater"));
148: suite.addTest(new Factory("getDefinition"));
149: suite.addTest(new Factory("getProperties"));
150: suite.addTest(new Factory("listProcInstances"));
151: return suite;
152: }
153:
154: /* (non-Javadoc)
155: * @see junit.framework.TestCase#setUp()
156: */
157: protected void setUp() throws Exception {
158: // String sender = Factory.class.getName() + "/setUp";
159: // String id = "43";
160:
161: // ServiceRegistry.importDefinition(sender, id);
162: factory = ServiceRegistry.getTestProcessFactory();
163:
164: timestamp = XMLUtil.toXsdLocalDateTime(new java.util.Date());
165:
166: super .setUp();
167: }
168:
169: /**
170: * Test Factory ListInstances.
171: * @exception Exception
172: * Test failed.
173: */
174: public void listProcInstances() throws Exception {
175: String sender = Factory.class.getName() + "/listProcInstances";
176: String id = "43";
177:
178: SOAPMessage message = Basic.createMessage();
179: Basic.fillRequestHeadet(message, factory, sender, id);
180: Basic.createActionElement(message, "ListInstancesRq");
181:
182: SOAPMessage response = Basic.call(message);
183: response.writeTo(System.out);
184:
185: Basic.checkNoFault(response);
186:
187: assertEquals(sender, Basic.getHeaderValue(response,
188: "ReceiverKey"));
189: assertEquals(factory, Basic.getHeaderValue(response,
190: "SenderKey"));
191: assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
192:
193: SOAPBodyElement processlist = Basic
194: .getFirstBodyElement(response);
195: Name answerName = processlist.getElementName();
196: assertEquals(Basic.ASAP_NS, answerName.getURI());
197: assertEquals("ListInstancesRs", answerName.getLocalName());
198: for (Iterator processIterator = processlist.getChildElements(); processIterator
199: .hasNext();) {
200:
201: SOAPElement child = (SOAPElement) processIterator.next();
202: Name childName = child.getElementName();
203: assertEquals("as", childName.getPrefix());
204: assertEquals("Instance", childName.getLocalName());
205:
206: String instanceKey = Basic.getChildTextContent(child,
207: "InstanceKey");
208: assertFalse(instanceKey.equals(""));
209: String instanceName = Basic.getChildTextContent(child,
210: "Name");
211: assertFalse(instanceName.equals(""));
212: }
213: }
214:
215: /**
216: * Test Factory create instance and start it automatically.
217: * @exception Exception
218: * Test failed.
219: */
220: public void createProcInstanceStartImmediately() throws Exception {
221: String sender = Factory.class.getName()
222: + "/createProcInstanceStartImmediately";
223: String id = "43";
224:
225: SOAPMessage message = Basic.createMessage();
226: Basic.fillRequestHeadet(message, factory, sender, id);
227: SOAPElement action = Basic.createActionElement(message,
228: "CreateInstanceRq");
229:
230: SOAPElement name = action.addChildElement("Name", "as");
231: name.addTextNode("wfxmltest factory " + timestamp);
232: SOAPElement cd = action.addChildElement("ContextData", "as");
233: cd.addNamespaceDeclaration("pd",
234: "http://localhost:8080/wfxml/dummy-pd.xsd");
235:
236: SOAPElement stringdata = cd.addChildElement(
237: "newpkg_wp1_string", "pd");
238: stringdata.addTextNode("text content " + timestamp);
239: SOAPElement intdata = cd.addChildElement("newpkg_wp1_integer",
240: "pd");
241: intdata.addTextNode("42");
242: SOAPElement floatdata = cd.addChildElement("newpkg_wp1_float",
243: "pd");
244: floatdata.addTextNode("42.42");
245: SOAPElement booldata = cd.addChildElement("newpkg_wp1_boolean",
246: "pd");
247: booldata.addTextNode("true");
248: SOAPElement datedata = cd.addChildElement("newpkg_wp1_date",
249: "pd");
250: datedata.addTextNode(timestamp);
251: SOAPElement schemadata = cd.addChildElement(
252: "newpkg_wp1_schema", "pd");
253: SOAPElement order = schemadata.addChildElement("order");
254: order.setAttribute("id", "08/15");
255: SOAPElement position1 = order.addChildElement("position");
256: position1.setAttribute("pos", "1");
257: SOAPElement position2 = order.addChildElement("position");
258: position2.setAttribute("pos", "2");
259:
260: SOAPMessage response = Basic.call(message);
261:
262: Basic.checkNoFault(response);
263:
264: assertEquals(sender, Basic.getHeaderValue(response,
265: "ReceiverKey"));
266: assertEquals(factory, Basic.getHeaderValue(response,
267: "SenderKey"));
268: assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
269:
270: SOAPBodyElement processlist = Basic
271: .getFirstBodyElement(response);
272: Name answerName = processlist.getElementName();
273: assertEquals(Basic.ASAP_NS, answerName.getURI());
274: assertEquals("CreateInstanceRs", answerName.getLocalName());
275: Iterator processIterator = processlist.getChildElements();
276: assertTrue(processIterator.hasNext());
277: SOAPElement child = (SOAPElement) processIterator.next();
278: Name childName = child.getElementName();
279: assertEquals("as", childName.getPrefix());
280: assertEquals("InstanceKey", childName.getLocalName());
281:
282: String instanceKey = XMLUtil.getFirstLevelTextContent(child);
283: assertFalse(instanceKey.equals(""));
284: assertFalse(processIterator.hasNext());
285: }
286:
287: /**
288: * Test Factory create instance and start it later.
289: * @exception Exception
290: * Test failed.
291: */
292: public void createProcInstanceStartLater() throws Exception {
293: String sender = Factory.class.getName() + "/createProcInstance";
294: String id = "43";
295:
296: SOAPMessage message = Basic.createMessage();
297: Basic.fillRequestHeadet(message, factory, sender, id);
298: SOAPElement action = Basic.createActionElement(message,
299: "CreateInstanceRq");
300: SOAPElement start = action.addChildElement("StartImmediately",
301: "as");
302: start.addTextNode("NO");
303:
304: SOAPElement cd = action.addChildElement("ContextData", "as");
305: cd.addNamespaceDeclaration("pd",
306: "http://localhost:8080/wfxml/dummy-pd.xsd");
307:
308: SOAPElement name = action.addChildElement("Name", "as");
309: name.addTextNode("wfxmltest factory " + timestamp);
310: SOAPElement stringdata = cd.addChildElement(
311: "newpkg_wp1_string", "pd");
312: stringdata.addTextNode("text content " + timestamp);
313: SOAPElement intdata = cd.addChildElement("newpkg_wp1_integer",
314: "pd");
315: intdata.addTextNode("43");
316: SOAPElement floatdata = cd.addChildElement("newpkg_wp1_float",
317: "pd");
318: floatdata.addTextNode("43.43");
319: SOAPElement booldata = cd.addChildElement("newpkg_wp1_boolean",
320: "pd");
321: booldata.addTextNode("true");
322: SOAPElement datedata = cd.addChildElement("newpkg_wp1_date",
323: "pd");
324: datedata.addTextNode(timestamp);
325: SOAPElement schemadata = cd.addChildElement(
326: "newpkg_wp1_schema", "pd");
327: SOAPElement order = schemadata.addChildElement("order");
328: order.setAttribute("id", "08/16");
329: SOAPElement position1 = order.addChildElement("position");
330: position1.setAttribute("pos", "1");
331: SOAPElement position2 = order.addChildElement("position");
332: position2.setAttribute("pos", "2");
333:
334: SOAPMessage response = Basic.call(message);
335:
336: Basic.checkNoFault(response);
337:
338: assertEquals(sender, Basic.getHeaderValue(response,
339: "ReceiverKey"));
340: assertEquals(factory, Basic.getHeaderValue(response,
341: "SenderKey"));
342: assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
343:
344: SOAPBodyElement processlist = Basic
345: .getFirstBodyElement(response);
346: Name answerName = processlist.getElementName();
347: assertEquals(Basic.ASAP_NS, answerName.getURI());
348: assertEquals("CreateInstanceRs", answerName.getLocalName());
349: Iterator processIterator = processlist.getChildElements();
350: assertTrue(processIterator.hasNext());
351: SOAPElement child = (SOAPElement) processIterator.next();
352: Name childName = child.getElementName();
353: assertEquals("as", childName.getPrefix());
354: assertEquals("InstanceKey", childName.getLocalName());
355:
356: String instanceKey = XMLUtil.getFirstLevelTextContent(child);
357: assertFalse(instanceKey.equals(""));
358: assertFalse(processIterator.hasNext());
359: }
360:
361: /**
362: * Test Factory getProperties.
363: */
364: public void getDefinition() throws Exception {
365: String sender = Factory.class.getName() + "/getDefinition";
366: String id = "44";
367:
368: SOAPMessage message = Basic.createMessage();
369: Basic.fillRequestHeadet(message, factory, sender, id);
370: SOAPBodyElement action = Basic.createActionElement(message,
371: "GetDefinitionRq");
372: SOAPElement language = action.addChildElement(
373: "ProcessLanguage", "wfxml");
374: language.addTextNode("XPDL");
375:
376: SOAPMessage response = Basic.call(message);
377:
378: Basic.checkNoFault(response);
379:
380: assertEquals(sender, Basic.getHeaderValue(response,
381: "ReceiverKey"));
382: assertEquals(factory, Basic.getHeaderValue(response,
383: "SenderKey"));
384: assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
385:
386: SOAPBodyElement processlist = Basic
387: .getFirstBodyElement(response);
388: Name answerName = processlist.getElementName();
389: assertEquals(Basic.WFXML_NS, answerName.getURI());
390: assertEquals("GetDefinitionRs", answerName.getLocalName());
391: }
392:
393: /**
394: * Test Factory getProperties.
395: */
396: public void getProperties() throws Exception {
397: String sender = Factory.class.getName() + "/getProperties";
398: String id = "45";
399:
400: SOAPMessage message = Basic.createMessage();
401: Basic.fillRequestHeadet(message, factory, sender, id);
402: Basic.createActionElement(message, "GetPropertiesRq");
403:
404: SOAPMessage response = Basic.call(message);
405:
406: Basic.checkNoFault(response);
407:
408: assertEquals(sender, Basic.getHeaderValue(response,
409: "ReceiverKey"));
410: assertEquals(factory, Basic.getHeaderValue(response,
411: "SenderKey"));
412: assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
413:
414: SOAPBodyElement processlist = Basic
415: .getFirstBodyElement(response);
416: Name answerName = processlist.getElementName();
417: assertEquals(Basic.ASAP_NS, answerName.getURI());
418: assertEquals("GetPropertiesRs", answerName.getLocalName());
419: }
420:
421: /**
422: * Creates a process without starting it and returns the instance key.
423: * @param testFactory the factory resource
424: * @param procName the name of the new process
425: * @return key of the created instance.
426: * @throws SOAPException
427: * Error in the SOAP message.
428: */
429: static String startTestProcess(String testFactory, String procName)
430: throws SOAPException {
431: String sender = Factory.class.getName() + "/startTestProcess";
432: String id = "43";
433: String time = XMLUtil.toXsdLocalDateTime(new java.util.Date());
434:
435: SOAPMessage message = Basic.createMessage();
436: Basic.fillRequestHeadet(message, testFactory, sender, id);
437: SOAPElement action = Basic.createActionElement(message,
438: "CreateInstanceRq");
439: SOAPElement cd = action.addChildElement("ContextData", "as");
440: cd.addNamespaceDeclaration("pd",
441: "http://localhost:8080/wfxml/dummy-pd.xsd");
442:
443: SOAPElement start = action.addChildElement("StartImmediately",
444: "as");
445: start.addTextNode("YES");
446: SOAPElement name = action.addChildElement("Name", "as");
447: name.addTextNode(procName);
448: SOAPElement stringdata = cd.addChildElement(
449: "newpkg_wp1_string", "pd");
450: stringdata.addTextNode("text content " + time);
451: SOAPElement intdata = cd.addChildElement("newpkg_wp1_integer",
452: "pd");
453: intdata.addTextNode("43");
454: SOAPElement floatdata = cd.addChildElement("newpkg_wp1_float",
455: "pd");
456: floatdata.addTextNode("43.43");
457: SOAPElement booldata = cd.addChildElement("newpkg_wp1_boolean",
458: "pd");
459: booldata.addTextNode("true");
460: SOAPElement datedata = cd.addChildElement("newpkg_wp1_date",
461: "pd");
462: datedata.addTextNode(time);
463: SOAPElement schemadata = cd.addChildElement(
464: "newpkg_wp1_schema", "pd");
465: SOAPElement order = schemadata.addChildElement("order");
466: order.setAttribute("id", "08/16");
467: SOAPElement position1 = order.addChildElement("position");
468: position1.setAttribute("pos", "1");
469: SOAPElement position2 = order.addChildElement("position");
470: position2.setAttribute("pos", "2");
471:
472: SOAPMessage response = Basic.call(message);
473:
474: SOAPBodyElement processlist = Basic
475: .getFirstBodyElement(response);
476: Iterator processIterator = processlist.getChildElements();
477: SOAPElement child = (SOAPElement) processIterator.next();
478:
479: return XMLUtil.getFirstLevelTextContent(child);
480: }
481: }
|