001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 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: Import.java,v 1.5 2007/03/27 21:59:42 mlipp Exp $
021: *
022: * $Log: Import.java,v $
023: * Revision 1.5 2007/03/27 21:59:42 mlipp
024: * Fixed lots of checkstyle warnings.
025: *
026: * Revision 1.4 2007/02/27 14:34:18 drmlipp
027: * Some refactoring to reduce cyclic dependencies.
028: *
029: * Revision 1.3 2006/09/29 12:32:09 drmlipp
030: * Consistently using WfMOpen as projct name now.
031: *
032: * Revision 1.2 2006/03/08 14:46:41 drmlipp
033: * Synchronized with 1.3.3p5.
034: *
035: * Revision 1.1.1.3.6.1 2005/12/19 10:36:38 drmlipp
036: * Added support for cleanup mode COMPLETED.
037: *
038: * Revision 1.1.1.3 2003/12/19 13:01:44 drmlipp
039: * Updated to 1.1rc1
040: *
041: * Revision 1.24 2003/10/21 21:00:45 lipp
042: * Moved EJBClientTest to new junit sub-package.
043: *
044: * Revision 1.23 2003/10/08 12:39:40 huaiyang
045: * make test weblogic compatible.
046: *
047: * Revision 1.22 2003/07/10 14:34:32 huaiyang
048: * Fix the tip error of the key transition in the ProcDefValidator.
049: *
050: * Revision 1.21 2003/06/27 09:44:03 lipp
051: * Fixed copyright/license information.
052: *
053: * Revision 1.20 2003/06/04 07:49:07 schlue
054: * PR48 fixed.
055: *
056: * Revision 1.19 2003/06/02 15:20:02 schlue
057: * PR53 fixed.
058: *
059: * Revision 1.18 2003/06/02 15:03:37 schlue
060: * PR47 fixed.
061: *
062: * Revision 1.17 2003/05/16 09:32:27 schlue
063: * Script tests added.
064: *
065: * Revision 1.16 2003/05/14 09:30:27 schlue
066: * Package names for minimal and full changed due to modified import behaviour.
067: *
068: * Revision 1.15 2003/05/13 16:04:23 schlue
069: * Comments and new test cases for parameter matching added.
070: *
071: * Revision 1.14 2003/05/13 15:32:31 schlue
072: * More parameter test cases added.
073: *
074: * Revision 1.13 2003/05/13 13:23:41 schlue
075: * More import tests added.
076: *
077: * Revision 1.12 2003/05/09 09:42:46 schlue
078: * Test for exception added.
079: *
080: * Revision 1.11 2003/04/23 14:28:00 lipp
081: * Improved modelling of header data.
082: *
083: * Revision 1.10 2003/04/16 14:06:26 schlue
084: * Some renames.
085: *
086: * Revision 1.9 2003/04/15 14:17:22 schlue
087: * Cleanup added.
088: *
089: * Revision 1.8 2003/04/15 12:57:25 schlue
090: * Static tests of process and activity (definitions) moved to directory process.
091: * More test cases for block activities added.
092: *
093: * Revision 1.7 2003/04/10 09:44:08 schlue
094: * Test cases for process data added.
095: *
096: * Revision 1.6 2003/03/21 10:00:28 schlue
097: * PR6 fixed.
098: *
099: * Revision 1.5 2003/03/12 11:46:54 schlue
100: * IPR5: timeEstimated activated
101: *
102: * Revision 1.4 2003/03/12 11:36:58 schlue
103: * IPR3: BlockID test enabled.
104: *
105: * Revision 1.3 2003/03/12 11:22:15 schlue
106: * IPR2: Modification acc. to PrioritizedMessage
107: *
108: * Revision 1.2 2003/03/03 14:53:13 schlue
109: * IPR4 (no further use of removeDefinition test)
110: *
111: * Revision 1.1 2003/01/17 10:01:19 schlue
112: * Initial version.
113: *
114: *
115: *
116: */
117: package procdef;
118:
119: import junit.framework.Test;
120: import junit.framework.TestSuite;
121:
122: import java.io.BufferedReader;
123: import java.io.InputStream;
124: import java.io.InputStreamReader;
125: import java.io.ByteArrayOutputStream;
126: import java.rmi.RemoteException;
127: import java.util.Iterator;
128:
129: import de.danet.an.util.junit.EJBClientTest;
130: import de.danet.an.workflow.api.Participant;
131: import de.danet.an.workflow.api.WorkflowServiceFactory;
132: import de.danet.an.workflow.api.WorkflowService;
133: import de.danet.an.workflow.api.Application;
134: import de.danet.an.workflow.api.ProcessDefinitionDirectory;
135: import de.danet.an.workflow.api.ProcessDefinition;
136: import de.danet.an.workflow.api.InvalidKeyException;
137: import de.danet.an.workflow.api.InvalidIdException;
138: import de.danet.an.workflow.api.ImportException;
139: import de.danet.an.workflow.api.PrioritizedMessage;
140:
141: import process.WfMOpenTestCase;
142:
143: /**
144: * Test import of process definitions.
145: * Afterwards, process descriptions of "minimal" and full are imported
146: * and can be used for following test cases.
147: * @author <a href="mailto:schlueter@danet.de">Holger Schlueter</a>
148: * @version 1.0
149: */
150: public class Import extends WfMOpenTestCase {
151: /**
152: * Access to process definition directory (singleton)
153: */
154: private ProcessDefinitionDirectory defDir = null;
155:
156: /**
157: * Constructor of this TestCase
158: * @param name a <code>String</code> value
159: */
160: public Import(String name) {
161: super (name);
162: }
163:
164: /**
165: * Construct this test suite.
166: * @return a <code>Test</code> value
167: */
168: public static Test suite() {
169: TestSuite suite = new TestSuite();
170: suite.addTest(new Import("readMinimal"));
171: suite.addTest(new Import("readImplementationIllegal"));
172: suite.addTest(new Import("readPerformerIllegal"));
173: suite.addTest(new Import("readActivityRefIllegal"));
174: suite.addTest(new Import("readTransitionRefIllegal"));
175: suite.addTest(new Import("readBlockIDRefIllegal"));
176: suite.addTest(new Import("testDataFields"));
177: suite.addTest(new Import("testScript"));
178: suite.addTest(new Import("checkImport"));
179: suite.addTest(new Create("cleanup"));
180: return new EJBClientTest(plc, suite);
181: }
182:
183: /**
184: * Test import of a minimal process definition.
185: * @exception Exception if an error occurs
186: */
187: public void readMinimal() throws Exception {
188: ByteArrayOutputStream processDefinition = new ByteArrayOutputStream();
189: // Read minimal (correct) process definition
190: InputStream is = getClass().getResourceAsStream(
191: "/procdef/minimal.xml");
192: BufferedReader in = new BufferedReader(new InputStreamReader(
193: is, "ISO-8859-1"));
194: int bt = -1;
195: while ((bt = in.read()) != -1) {
196: processDefinition.write(bt);
197: }
198: // Make sure that no such description exists yet
199: defDir.removeProcessDefinition("SystemTest_minimal", "minimal");
200: assertTrue(!defDir.processDefinitionExists(
201: "SystemTest_minimal", "minimal"));
202: // Import process definition (using byte[] signature)
203: defDir
204: .importProcessDefinitions(processDefinition
205: .toByteArray());
206: assertTrue(defDir.processDefinitionExists("SystemTest_minimal",
207: "minimal"));
208: }
209:
210: /**
211: * Test import of a process definition with illegal implementation
212: * declaration.
213: * @exception Exception if an error occurs
214: */
215: public void readImplementationIllegal() throws Exception {
216: StringBuffer processDefinition = new StringBuffer();
217: // Read incorrect process definition
218: InputStream is = getClass().getResourceAsStream(
219: "/procdef/implementation-illegal.xml");
220: BufferedReader in = new BufferedReader(new InputStreamReader(
221: is, "ISO-8859-1"));
222: String line = null;
223: while ((line = in.readLine()) != null) {
224: processDefinition.append(line + "\n");
225: }
226: defDir.removeProcessDefinition("SystemTest", "implementation");
227: assertTrue(!defDir.processDefinitionExists("SystemTest",
228: "implementation"));
229: // Try to import the process definition (should fail)
230: boolean gotException = false;
231: try {
232: defDir.importProcessDefinitions(processDefinition
233: .toString());
234: } catch (ImportException exc) {
235: assertTrue(exc.messages().size() == 1);
236: assertTrue(((PrioritizedMessage) exc.messages().get(0))
237: .priority().equals(
238: PrioritizedMessage.Priority.ERROR));
239: assertTrue(((PrioritizedMessage) exc.messages().get(0))
240: .unmappedMessage().equals(
241: "ImportMessages#procdef.tool.notfound"));
242: gotException = true;
243: }
244: assertTrue(gotException);
245: // Make sure that it has not been imported (due to errors)
246: assertTrue(!defDir.processDefinitionExists("SystemTest",
247: "implementation"));
248: // Read corrected process definition
249: is = getClass().getResourceAsStream(
250: "/procdef/implementation-correct.xml");
251: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
252: processDefinition.setLength(0);
253: while ((line = in.readLine()) != null) {
254: processDefinition.append(line + "\n");
255: }
256: // Import process definition
257: // Now it should work
258: defDir.importProcessDefinitions(processDefinition.toString());
259: assertTrue(defDir.processDefinitionExists("SystemTest",
260: "implementation"));
261: // Remove it again
262: defDir.removeProcessDefinition("SystemTest", "implementation");
263: assertTrue(!defDir.processDefinitionExists("SystemTest",
264: "implementation"));
265: }
266:
267: /**
268: * Test import of a process definition with illegal performer
269: * declaration.
270: * @exception Exception if an error occurs
271: */
272: public void readPerformerIllegal() throws Exception {
273: StringBuffer processDefinition = new StringBuffer();
274: // Read incorrect process definition
275: InputStream is = getClass().getResourceAsStream(
276: "/procdef/performer-illegal.xml");
277: BufferedReader in = new BufferedReader(new InputStreamReader(
278: is, "ISO-8859-1"));
279: String line = null;
280: while ((line = in.readLine()) != null) {
281: processDefinition.append(line + "\n");
282: }
283: defDir.removeProcessDefinition("SystemTest", "performer");
284: assertTrue(!defDir.processDefinitionExists("SystemTest",
285: "performer"));
286: // Try to import the process definition (should fail)
287: boolean gotException = false;
288: try {
289: defDir.importProcessDefinitions(processDefinition
290: .toString());
291: } catch (ImportException exc) {
292: assertTrue(exc.messages().size() == 1);
293: assertTrue(((PrioritizedMessage) exc.messages().get(0))
294: .priority().equals(
295: PrioritizedMessage.Priority.ERROR));
296: assertTrue(((PrioritizedMessage) exc.messages().get(0))
297: .unmappedMessage()
298: .equals("ImportMessages#procdef.performer.notfound"));
299: gotException = true;
300: }
301: assertTrue(gotException);
302: // Make sure that it has not been imported (due to errors)
303: assertTrue(!defDir.processDefinitionExists("SystemTest",
304: "performer"));
305: // Read corrected process definition
306: is = getClass().getResourceAsStream(
307: "/procdef/performer-correct.xml");
308: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
309: processDefinition.setLength(0);
310: while ((line = in.readLine()) != null) {
311: processDefinition.append(line + "\n");
312: }
313: // Import process definition
314: // Now it should work
315: defDir.importProcessDefinitions(processDefinition.toString());
316: assertTrue(defDir.processDefinitionExists("SystemTest",
317: "performer"));
318: // Remove it again
319: defDir.removeProcessDefinition("SystemTest", "performer");
320: assertTrue(!defDir.processDefinitionExists("SystemTest",
321: "performer"));
322: }
323:
324: /**
325: * Test import of a process definition with illegal activity reference
326: * within transition declaration.
327: * @exception Exception if an error occurs
328: */
329: public void readActivityRefIllegal() throws Exception {
330: StringBuffer processDefinition = new StringBuffer();
331: // Read incorrect process definition
332: InputStream is = getClass().getResourceAsStream(
333: "/procdef/activityRef-illegal.xml");
334: BufferedReader in = new BufferedReader(new InputStreamReader(
335: is, "ISO-8859-1"));
336: String line = null;
337: while ((line = in.readLine()) != null) {
338: processDefinition.append(line + "\n");
339: }
340: defDir.removeProcessDefinition("SystemTest", "activityRef");
341: assertTrue(!defDir.processDefinitionExists("SystemTest",
342: "activityRef"));
343: // Try to import the process definition (should fail)
344: boolean gotException = false;
345: try {
346: defDir.importProcessDefinitions(processDefinition
347: .toString());
348: } catch (ImportException exc) {
349: assertTrue(exc.messages().size() == 4);
350: assertTrue(((PrioritizedMessage) exc.messages().get(0))
351: .priority().equals(
352: PrioritizedMessage.Priority.ERROR));
353: assertTrue(((PrioritizedMessage) exc.messages().get(0))
354: .unmappedMessage().equals(
355: "ImportMessages#procdef.activity.ununique"));
356: assertTrue(((PrioritizedMessage) exc.messages().get(1))
357: .priority().equals(
358: PrioritizedMessage.Priority.ERROR));
359: assertTrue(((PrioritizedMessage) exc.messages().get(1))
360: .unmappedMessage()
361: .endsWith(
362: "ImportMessages#procdef.transition.activityid.notfound"));
363: assertTrue(((PrioritizedMessage) exc.messages().get(2))
364: .priority().equals(
365: PrioritizedMessage.Priority.ERROR));
366: assertTrue(((PrioritizedMessage) exc.messages().get(2))
367: .unmappedMessage()
368: .endsWith(
369: "ImportMessages#procdef.transition.activityid.notfound"));
370: assertTrue(((PrioritizedMessage) exc.messages().get(3))
371: .priority().equals(
372: PrioritizedMessage.Priority.ERROR));
373: assertTrue(((PrioritizedMessage) exc.messages().get(3))
374: .unmappedMessage()
375: .equals(
376: "ImportMessages#procdef.transition.ununique"));
377: gotException = true;
378: }
379: assertTrue(gotException);
380: // Make sure that it has not been imported (due to errors)
381: assertTrue(!defDir.processDefinitionExists("SystemTest",
382: "activityRef"));
383: // Read corrected process definition
384: is = getClass().getResourceAsStream(
385: "/procdef/activityRef-correct.xml");
386: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
387: processDefinition.setLength(0);
388: while ((line = in.readLine()) != null) {
389: processDefinition.append(line + "\n");
390: }
391: // Import process definition
392: // Now it should work
393: defDir.importProcessDefinitions(processDefinition.toString());
394: assertTrue(defDir.processDefinitionExists("SystemTest",
395: "activityRef"));
396: // Remove it again
397: defDir.removeProcessDefinition("SystemTest", "activityRef");
398: assertTrue(!defDir.processDefinitionExists("SystemTest",
399: "activityRef"));
400: }
401:
402: /**
403: * Test import of a process definition with illegal transition reference
404: * within activity declaration.
405: * @exception Exception if an error occurs
406: */
407: public void readTransitionRefIllegal() throws Exception {
408: StringBuffer processDefinition = new StringBuffer();
409: // Read incorrect process definition
410: InputStream is = getClass().getResourceAsStream(
411: "/procdef/transitionRef-illegal.xml");
412: BufferedReader in = new BufferedReader(new InputStreamReader(
413: is, "ISO-8859-1"));
414: String line = null;
415: while ((line = in.readLine()) != null) {
416: processDefinition.append(line + "\n");
417: }
418: defDir.removeProcessDefinition("SystemTest", "transitionRef");
419: assertTrue(!defDir.processDefinitionExists("SystemTest",
420: "transitionRef"));
421: // Try to import the process definition (should fail)
422: boolean gotException = false;
423: try {
424: defDir.importProcessDefinitions(processDefinition
425: .toString());
426: } catch (ImportException exc) {
427: assertTrue(exc.messages().size() == 1);
428: assertTrue(((PrioritizedMessage) exc.messages().get(0))
429: .priority().equals(
430: PrioritizedMessage.Priority.ERROR));
431: assertTrue(((PrioritizedMessage) exc.messages().get(0))
432: .unmappedMessage()
433: .equals(
434: "ImportMessages#procdef.transitionid.notfound"));
435: gotException = true;
436: }
437: assertTrue(gotException);
438: // Make sure that it has not been imported (due to errors)
439: assertTrue(!defDir.processDefinitionExists("SystemTest",
440: "transitionRef"));
441: // Read corrected process definition
442: is = getClass().getResourceAsStream(
443: "/procdef/transitionRef-correct.xml");
444: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
445: processDefinition.setLength(0);
446: while ((line = in.readLine()) != null) {
447: processDefinition.append(line + "\n");
448: }
449: // Import process definition
450: // Now it should work
451: defDir.importProcessDefinitions(processDefinition.toString());
452: assertTrue(defDir.processDefinitionExists("SystemTest",
453: "transitionRef"));
454: // Remove it again
455: defDir.removeProcessDefinition("SystemTest", "transitionRef");
456: assertTrue(!defDir.processDefinitionExists("SystemTest",
457: "transitionRef"));
458: }
459:
460: /**
461: * Test import of a process definition with illegal blockActivity reference
462: * within activity declaration.
463: * @exception Exception if an error occurs
464: */
465: public void readBlockIDRefIllegal() throws Exception {
466: StringBuffer processDefinition = new StringBuffer();
467: // Read incorrect process definition
468: InputStream is = getClass().getResourceAsStream(
469: "/procdef/blockActivityRef-illegal.xml");
470: BufferedReader in = new BufferedReader(new InputStreamReader(
471: is, "ISO-8859-1"));
472: String line = null;
473: while ((line = in.readLine()) != null) {
474: processDefinition.append(line + "\n");
475: }
476: defDir
477: .removeProcessDefinition("SystemTest",
478: "blockActivityRef");
479: assertTrue(!defDir.processDefinitionExists("SystemTest",
480: "blockActivityRef"));
481: // Try to import the process definition (should fail)
482: boolean gotException = false;
483: try {
484: defDir.importProcessDefinitions(processDefinition
485: .toString());
486: } catch (ImportException exc) {
487: Iterator msg = exc.messages().iterator();
488: assertTrue(exc.messages().size() == 1);
489: assertTrue(((PrioritizedMessage) exc.messages().get(0))
490: .priority().equals(
491: PrioritizedMessage.Priority.ERROR));
492: assertTrue(((PrioritizedMessage) exc.messages().get(0))
493: .unmappedMessage()
494: .equals(
495: "ImportMessages#procdef.activity.activityset.invalid"));
496: gotException = true;
497: }
498: assertTrue(gotException);
499: // Make sure that it has not been imported (due to errors)
500: assertTrue(!defDir.processDefinitionExists("SystemTest",
501: "blockActivityRef"));
502: // Read incorrect process definition
503: is = getClass().getResourceAsStream(
504: "/procdef/blockActivityRef-emtpyActivitySet.xml");
505: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
506: processDefinition.setLength(0);
507: while ((line = in.readLine()) != null) {
508: processDefinition.append(line + "\n");
509: }
510: // Try to import the process definition (should fail)
511: gotException = false;
512: try {
513: defDir.importProcessDefinitions(processDefinition
514: .toString());
515: } catch (ImportException exc) {
516: Iterator msg = exc.messages().iterator();
517: assertTrue(exc.messages().size() == 1);
518: assertTrue(((PrioritizedMessage) exc.messages().get(0))
519: .priority().equals(
520: PrioritizedMessage.Priority.ERROR));
521: assertTrue(((PrioritizedMessage) exc.messages().get(0))
522: .unmappedMessage()
523: .equals(
524: "ImportMessages#procdef.process.activityset.empty"));
525: gotException = true;
526: }
527: assertTrue(gotException);
528: // Make sure that it has not been imported (due to errors)
529: assertTrue(!defDir.processDefinitionExists("SystemTest",
530: "blockActivityRef"));
531: // Read corrected process definition
532: is = getClass().getResourceAsStream(
533: "/procdef/blockActivityRef-correct.xml");
534: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
535: processDefinition.setLength(0);
536: while ((line = in.readLine()) != null) {
537: processDefinition.append(line + "\n");
538: }
539: // Import process definition
540: // Now it should work
541: defDir.importProcessDefinitions(processDefinition.toString());
542: assertTrue(defDir.processDefinitionExists("SystemTest",
543: "blockActivityRef"));
544: // Remove it again
545: defDir
546: .removeProcessDefinition("SystemTest",
547: "blockActivityRef");
548: assertTrue(!defDir.processDefinitionExists("SystemTest",
549: "blockActivityRef"));
550: }
551:
552: /**
553: * Test rejection of illegal script declaration.
554: * @exception Exception if an error occurs
555: */
556: public void testScript() throws Exception {
557: StringBuffer processDefinition = new StringBuffer();
558: // Read incorrect process definition
559: InputStream is = getClass().getResourceAsStream(
560: "/procdef/illegalScriptType.xml");
561: BufferedReader in = new BufferedReader(new InputStreamReader(
562: is, "ISO-8859-1"));
563: String line = null;
564: while ((line = in.readLine()) != null) {
565: processDefinition.append(line + "\n");
566: }
567: // Try to import the process definition (should fail)
568: boolean gotException = false;
569: try {
570: defDir.importProcessDefinitions(processDefinition
571: .toString());
572: } catch (ImportException exc) {
573: Iterator msg = exc.messages().iterator();
574: assertTrue(exc.messages().size() == 1);
575: assertTrue(((PrioritizedMessage) exc.messages().get(0))
576: .priority().equals(
577: PrioritizedMessage.Priority.ERROR));
578: assertTrue(((PrioritizedMessage) exc.messages().get(0))
579: .unmappedMessage()
580: .equals(
581: "ImportMessages#package.script.type.unsupported"));
582: gotException = true;
583: }
584: assertTrue("PR53", gotException);
585:
586: is = getClass().getResourceAsStream(
587: "/procdef/illegalScriptVersion.xml");
588: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
589: processDefinition.setLength(0);
590: while ((line = in.readLine()) != null) {
591: processDefinition.append(line + "\n");
592: }
593: // Try to import the process definition (should fail)
594: gotException = false;
595: try {
596: defDir.importProcessDefinitions(processDefinition
597: .toString());
598: } catch (ImportException exc) {
599: Iterator msg = exc.messages().iterator();
600: assertTrue(exc.messages().size() == 1);
601: assertTrue(((PrioritizedMessage) exc.messages().get(0))
602: .priority().equals(
603: PrioritizedMessage.Priority.ERROR));
604: assertTrue(((PrioritizedMessage) exc.messages().get(0))
605: .unmappedMessage()
606: .equals(
607: "ImportMessages#package.script.version.unsupported"));
608: gotException = true;
609: }
610: assertTrue("PR53", gotException);
611: }
612:
613: /**
614: * Test that process definitions have been correctly imported
615: * @exception Exception if an error occurs
616: */
617: public void checkImport() throws Exception {
618: StringBuffer processDefinition = new StringBuffer();
619: // Read correct process definition
620: InputStream is = getClass().getResourceAsStream(
621: "/procdef/full.xml");
622: BufferedReader in = new BufferedReader(new InputStreamReader(
623: is, "ISO-8859-1"));
624: String line = null;
625: while ((line = in.readLine()) != null) {
626: processDefinition.append(line + "\n");
627: }
628: try {
629: defDir.importProcessDefinitions(processDefinition
630: .toString());
631: } catch (ImportException exc) {
632: Iterator msg = exc.messages().iterator();
633: while (msg.hasNext()) {
634: System.out.println(((PrioritizedMessage) msg.next())
635: .unmappedMessage());
636: }
637: }
638: // Test all attributes of process definition
639: ProcessDefinition procdef = defDir.lookupProcessDefinition(
640: "SystemTest_full", "full");
641: boolean gotException = false;
642: try {
643: procdef.applicationById("Dummy");
644: } catch (InvalidIdException exc) {
645: gotException = true;
646: }
647: assertTrue(gotException);
648: Application appl = procdef.applicationById("dummy");
649: assertTrue(appl.description().equals(
650: "Dummy application for testing" + " purposes only."));
651: assertTrue(appl.id().equals("dummy"));
652: assertTrue(procdef.applications().size() == 1);
653: assertTrue(((Application) procdef.applications().iterator()
654: .next()).id().equals("dummy"));
655: gotException = false;
656: try {
657: procdef.participantById("CurrentUser");
658: } catch (InvalidIdException exc) {
659: gotException = true;
660: }
661: assertTrue(gotException);
662: Participant part = procdef.participantById("currentUser");
663: assertTrue(part.getId().equals("currentUser"));
664: assertTrue(part.getName().equals("Aktueller Benutzer"));
665: assertTrue(part.getParticipantType().equals(
666: Participant.ParticipantType.HUMAN));
667: assertTrue(procdef.participants().size() == 1);
668: assertTrue(((Participant) procdef.participants().iterator()
669: .next()).getId().equals("currentUser"));
670: assertTrue(procdef.removeClosedProcess());
671: assertTrue(procdef.cleanupMode() == ProcessDefinition.REMOVE_AUTOMATIC);
672: assertTrue(procdef.packageId().equals("SystemTest_full"));
673: assertTrue(procdef.processId().equals("full"));
674: assertTrue(procdef.packageName()
675: .equals("System Test (procdef)"));
676: assertTrue(procdef.processName().equals(
677: "PROCESS_COMPLETE_ATTRIBUTES"));
678: assertTrue(procdef.mgrName().equals("SystemTest_full/full"));
679: ProcessDefinition.ProcessHeaderData hdr = procdef
680: .processHeader();
681: assertTrue(hdr.created()
682: .equals("Tue Jan 14 14:58:01 CEST 2003"));
683: assertTrue(hdr.description().equals(
684: "Description for test of all"
685: + " accessible attributes"));
686: assertTrue(hdr.priority().equals("5"));
687: assertTrue(hdr.limit().equals("3 days"));
688: assertTrue(hdr.validFrom().equals(
689: "Tue Jan 14 15:00:00 CEST 2003"));
690: assertTrue(hdr.validTo()
691: .equals("Tue Jan 14 15:59:59 CEST 2003"));
692: assertTrue(hdr.timeEstimationWaiting().equals("Wait"));
693: assertTrue(hdr.timeEstimationWorking().equals("Work"));
694: assertTrue(hdr.timeEstimationDuration().equals("Dur"));
695: ProcessDefinition.PackageHeaderData phdr = hdr.packageHeader();
696: assertTrue(phdr.xpdlVersion().equals("1.0"));
697: assertTrue(phdr.vendor().equals("Danet GmbH, GS AN"));
698: assertTrue(phdr.created().equals(
699: "Tue Jan 14 14:59:01 CEST 2003"));
700: assertTrue(phdr.description().equals("Package for system test"));
701: assertTrue(phdr.documentation().equals("C:/Workflow/help.xml"));
702: assertTrue(phdr.priorityUnit().equals("prio"));
703: assertTrue(phdr.costUnit().equals("cost"));
704:
705: // Make sure that processes exist
706: assertTrue(defDir.processDefinitionExists("SystemTest_minimal",
707: "minimal"));
708: assertTrue(defDir.processDefinitionExists("SystemTest_full",
709: "full"));
710: }
711:
712: /**
713: * Test references to data fields and/or formal parameters.
714: * @exception Exception if an error occurs
715: */
716: public void testDataFields() throws Exception {
717: StringBuffer processDefinition = new StringBuffer();
718: // Read process definition with parameter that has not been declared
719: InputStream is = getClass().getResourceAsStream(
720: "/procdef/paramNotDeclared.xml");
721: BufferedReader in = new BufferedReader(new InputStreamReader(
722: is, "ISO-8859-1"));
723: String line = null;
724: while ((line = in.readLine()) != null) {
725: processDefinition.append(line + "\n");
726: }
727: boolean gotException = false;
728: try {
729: defDir.importProcessDefinitions(processDefinition
730: .toString());
731: } catch (ImportException exc) {
732: assertTrue(exc.messages().size() == 1);
733: assertTrue(((PrioritizedMessage) exc.messages().get(0))
734: .priority().equals(
735: PrioritizedMessage.Priority.ERROR));
736: assertTrue(((PrioritizedMessage) exc.messages().get(0))
737: .unmappedMessage()
738: .equals(
739: "ImportMessages#procdef.activity.subflow.datanotfound"));
740: gotException = true;
741: }
742: assertTrue(gotException);
743:
744: // Read process definition with illegal subflow call
745: // (called subflow with less params than declared)
746: is = getClass().getResourceAsStream(
747: "/procdef/tooFewParameters.xml");
748: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
749: processDefinition.setLength(0);
750: while ((line = in.readLine()) != null) {
751: processDefinition.append(line + "\n");
752: }
753: gotException = false;
754: try {
755: defDir.importProcessDefinitions(processDefinition
756: .toString());
757: } catch (ImportException exc) {
758: assertTrue(exc.messages().size() == 1);
759: assertTrue(((PrioritizedMessage) exc.messages().get(0))
760: .priority().equals(
761: PrioritizedMessage.Priority.ERROR));
762: assertTrue(((PrioritizedMessage) exc.messages().get(0))
763: .unmappedMessage()
764: .equals(
765: "ImportMessages#procdef.activity.subflow.params.notmatched"));
766: gotException = true;
767: }
768: assertTrue(gotException);
769:
770: // Read process definition with illegal subflow call
771: // (called subflow with more params than declared)
772: is = getClass().getResourceAsStream(
773: "/procdef/tooManyParameters.xml");
774: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
775: processDefinition.setLength(0);
776: while ((line = in.readLine()) != null) {
777: processDefinition.append(line + "\n");
778: }
779: gotException = false;
780: try {
781: defDir.importProcessDefinitions(processDefinition
782: .toString());
783: } catch (ImportException exc) {
784: assertTrue(exc.messages().size() == 1);
785: assertTrue(((PrioritizedMessage) exc.messages().get(0))
786: .priority().equals(
787: PrioritizedMessage.Priority.ERROR));
788: assertTrue(((PrioritizedMessage) exc.messages().get(0))
789: .unmappedMessage()
790: .equals(
791: "ImportMessages#procdef.activity.subflow.params.notmatched"));
792: gotException = true;
793: }
794: assertTrue(gotException);
795:
796: // Read process definition with illegal subflow call
797: // (calling subflow with OUT param)
798: is = getClass().getResourceAsStream(
799: "/procdef/callingWithOUTParam.xml");
800: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
801: processDefinition.setLength(0);
802: while ((line = in.readLine()) != null) {
803: processDefinition.append(line + "\n");
804: }
805: gotException = false;
806: try {
807: defDir.importProcessDefinitions(processDefinition
808: .toString());
809: } catch (ImportException exc) {
810: assertTrue(exc.messages().size() == 1);
811: assertTrue(((PrioritizedMessage) exc.messages().get(0))
812: .priority().equals(
813: PrioritizedMessage.Priority.ERROR));
814: assertTrue(((PrioritizedMessage) exc.messages().get(0))
815: .unmappedMessage()
816: .equals(
817: "ImportMessages#procdef.activity.subflow.parammode.notmatched"));
818: gotException = true;
819: }
820: assertTrue(gotException);
821:
822: // Read process definition with illegal subflow call
823: // (calling subflow with constant as INOUT parameter)
824: is = getClass().getResourceAsStream(
825: "/procdef/callingOUTNotDeclared.xml");
826: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
827: processDefinition.setLength(0);
828: while ((line = in.readLine()) != null) {
829: processDefinition.append(line + "\n");
830: }
831: gotException = false;
832: try {
833: defDir.importProcessDefinitions(processDefinition
834: .toString());
835: } catch (ImportException exc) {
836: assertTrue(exc.messages().size() == 1);
837: assertTrue(((PrioritizedMessage) exc.messages().get(0))
838: .priority().equals(
839: PrioritizedMessage.Priority.ERROR));
840: assertTrue(((PrioritizedMessage) exc.messages().get(0))
841: .unmappedMessage()
842: .equals(
843: "ImportMessages#procdef.activity.subflow.datanotfound"));
844: gotException = true;
845: }
846: assertTrue(gotException);
847:
848: // Read process definition with illegal subflow call
849: // (param type mismatch)
850: is = getClass().getResourceAsStream(
851: "/procdef/paramTypeMismatch.xml");
852: in = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
853: processDefinition.setLength(0);
854: while ((line = in.readLine()) != null) {
855: processDefinition.append(line + "\n");
856: }
857: gotException = false;
858: try {
859: defDir.importProcessDefinitions(processDefinition
860: .toString());
861: } catch (ImportException exc) {
862: assertTrue(exc.messages().size() == 1);
863: assertTrue(((PrioritizedMessage) exc.messages().get(0))
864: .priority().equals(
865: PrioritizedMessage.Priority.ERROR));
866: assertTrue(((PrioritizedMessage) exc.messages().get(0))
867: .unmappedMessage()
868: .equals(
869: "ImportMessages#procdef.activity.subflow.paramdatatype.notmatched"));
870: gotException = true;
871: }
872: // s. PR 48: assertTrue(gotException);
873: }
874:
875: /**
876: * Remove all imported process definitions.
877: * @exception Exception if an error occurs
878: */
879: public void cleanup() throws Exception {
880: defDir.removeProcessDefinition("SystemTest_minimal", "minimal");
881: boolean procdefRemoved = false;
882: try {
883: defDir.processMgr("SystemTest_minimal", "minimal");
884: } catch (InvalidKeyException exc) {
885: procdefRemoved = true;
886: }
887: assertTrue(procdefRemoved);
888: defDir.removeProcessDefinition("SystemTest_full", "full");
889: procdefRemoved = false;
890: try {
891: defDir.processMgr("SystemTest_full", "full");
892: } catch (InvalidKeyException exc) {
893: procdefRemoved = true;
894: }
895: assertTrue(procdefRemoved);
896: }
897:
898: /**
899: * Initialisation.
900: * The <code>setUp</code> method defines the way a state change is
901: * realized. Override this method to change this way.
902: * @exception Exception if an error occurs
903: */
904: protected void setUp() throws Exception {
905: super .setUp();
906: WorkflowService wfs = WorkflowServiceFactory.newInstance()
907: .newWorkflowService();
908: try {
909: defDir = wfs.processDefinitionDirectory();
910: } catch (RemoteException exc) {
911: System.err
912: .println("Process definition directory not accessible: "
913: + exc.getMessage());
914: System.exit(-1);
915: }
916: }
917: }
|