Source Code Cross Referenced for WMClientTest.java in  » Workflow-Engines » obe-1.0 » org » obe » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » obe 1.0 » org.obe.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*--
0002:
0003:         Copyright (C) 2002-2005 Adrian Price.
0004:         All rights reserved.
0005:
0006:         Redistribution and use in source and binary forms, with or without
0007:         modification, are permitted provided that the following conditions
0008:         are met:
0009:
0010:         1. Redistributions of source code must retain the above copyright
0011:            notice, this list of conditions, and the following disclaimer.
0012:
0013:         2. Redistributions in binary form must reproduce the above copyright
0014:            notice, this list of conditions, and the disclaimer that follows
0015:            these conditions in the documentation and/or other materials
0016:            provided with the distribution.
0017:
0018:         3. The names "OBE" and "Open Business Engine" must not be used to
0019:         	endorse or promote products derived from this software without prior
0020:         	written permission.  For written permission, please contact
0021:         	adrianprice@sourceforge.net.
0022:
0023:         4. Products derived from this software may not be called "OBE" or
0024:         	"Open Business Engine", nor may "OBE" or "Open Business Engine"
0025:         	appear in their name, without prior written permission from
0026:         	Adrian Price (adrianprice@users.sourceforge.net).
0027:
0028:         THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0029:         WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0030:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0031:         DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
0032:         INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0033:         (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0034:         SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0035:         HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
0036:         STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
0037:         IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0038:         POSSIBILITY OF SUCH DAMAGE.
0039:
0040:         For more information on OBE, please see
0041:         <http://obe.sourceforge.net/>.
0042:
0043:         */
0044:
0045:        package org.obe.test;
0046:
0047:        import org.obe.client.api.WMClient;
0048:        import org.obe.client.api.model.ActivityInstanceAttributes;
0049:        import org.obe.client.api.model.ProcessInstanceAttributes;
0050:        import org.obe.client.api.model.WorkItemAttributes;
0051:        import org.obe.xpdl.model.pkg.XPDLPackage;
0052:        import org.obe.xpdl.parser.XPDLParserException;
0053:        import org.wfmc.wapi.*;
0054:
0055:        import java.io.IOException;
0056:        import java.util.HashSet;
0057:        import java.util.Iterator;
0058:        import java.util.Set;
0059:
0060:        /**
0061:         * JUnit tests for the OBE WAPI API. N.B. This test must be run from the
0062:         * $OBE_DEV_HOME/obe/obetest directory in order to pick up the package files.
0063:         * TODO: test filtering in all methods which accept a filter.
0064:         *
0065:         * @author Adrian Price
0066:         */
0067:        public abstract class WMClientTest extends OBEClientTest {
0068:            protected static final String[] TESTS = { "testConnect",
0069:                    "testPurge", "testCreatePackage", "testGetPackageContent",
0070:                    "testSetPackageContent", "testListProcessDefinitions",
0071:                    "testListProcessDefinitionStates",
0072:                    "testChangeProcessDefinitionState",
0073:                    "testCreateProcessInstance", "testStartProcess",
0074:                    "testGetProcessInstance", "testListProcessInstances",
0075:                    "testListProcessInstanceStates",
0076:                    "testChangeProcessInstanceState",
0077:                    "testChangeProcessInstancesState",
0078:                    "testListProcessInstanceAttributes",
0079:                    "testGetProcessInstanceAttributeValue",
0080:                    "testAssignProcessInstanceAttribute",
0081:                    "testAssignProcessInstancesAttribute",
0082:                    "testListActivityInstances", "testGetActivityInstance",
0083:                    "testListActivityInstanceStates",
0084:                    "testChangeActivityInstanceState",
0085:                    "testChangeActivityInstancesState",
0086:                    "testListActivityInstanceAttributes",
0087:                    "testGetActivityInstanceAttributeValue",
0088:                    "testAssignActivityInstanceAttribute",
0089:                    "testAssignActivityInstancesAttribute",
0090:                    "testListWorkItems", "testGetWorkItem",
0091:                    "testReassignWorkItem", "testCompleteWorkItem",
0092:                    "testListWorkItemAttributes",
0093:                    "testGetWorkItemAttributeValue",
0094:                    "testAssignWorkItemAttribute", "testAbortProcessInstance",
0095:                    "testTerminateProcessInstance",
0096:                    "testAbortProcessInstances",
0097:                    "testTerminateProcessInstances",
0098:                    "testDeleteProcessInstance", "testDeleteProcessInstances",
0099:                    "testDeletePackage", "testDisconnect" };
0100:            protected static final String TEST_PACKAGE_1 = "/org/obe/test/WMClientTest1.xpdl";
0101:            private static final String TEST_PACKAGE_2 = "/org/obe/test/WMClientTest2.xpdl";
0102:            private static String pkgContent;
0103:            private static String pkgId1 = "tpkg-1";
0104:            private static String procDefId1 = "twf-1";
0105:            private static String procDefId2 = "twf-2";
0106:            private static String procInstName1 = "ProcessInstance-1";
0107:            private static String procInstName2 = "ProcessInstance-2";
0108:            private static String procInstName3 = "ProcessInstance-3";
0109:            private static String procInstName4 = "ProcessInstance-4";
0110:            private static String procInstName5 = "ProcessInstance-5";
0111:            private static String procInstName6 = "ProcessInstance-6";
0112:            private static String procInstId1;
0113:            private static String procInstId2;
0114:            private static String procInstId3;
0115:            private static String procInstId4;
0116:            private static String procInstId5;
0117:            private static String procInstId6;
0118:            private static String actDefId1 = "ta-1";
0119:            private static String actInstId1;
0120:            private static String workItemId1;
0121:            private static boolean testChangeProcessDefinitionStatePassed;
0122:            private static boolean testAbortProcessInstancePassed;
0123:            private static boolean testTerminateProcessInstancePassed;
0124:            private static boolean testAbortProcessInstancesPassed;
0125:            private static boolean testTerminateProcessInstancesPassed;
0126:            private static boolean testDeleteProcessInstancesPassed;
0127:
0128:            protected WMClientTest(String name, String protocol) {
0129:                super (name, protocol);
0130:            }
0131:
0132:            public void testConnect() throws WMWorkflowException {
0133:                connect();
0134:                try {
0135:                    _client.connect(null);
0136:                    fail("Invalid connect did not throw exception.");
0137:                } catch (WMConnectException e) {
0138:                    // This is the correct behaviour.
0139:                } catch (Exception e) {
0140:                    fail("Invalid connect threw the wrong exception: " + e);
0141:                }
0142:                getLogger().info("testConnect passed");
0143:            }
0144:
0145:            public void testPurge() throws WMWorkflowException {
0146:                WMProcessInstanceIterator pii = _client.listProcessInstances(
0147:                        null, false);
0148:                while (pii.hasNext()) {
0149:                    WMProcessInstance procInst = pii.tsNext();
0150:                    _client.deleteProcessInstance(procInst.getId());
0151:                }
0152:                Set packages = new HashSet();
0153:                WMProcessDefinitionIterator pdi = _client
0154:                        .listProcessDefinitions(null, false);
0155:                while (pdi.hasNext()) {
0156:                    WMProcessDefinition procDef = pdi.tsNext();
0157:                    packages.add(procDef.getPackageId());
0158:                }
0159:                Iterator pi = packages.iterator();
0160:                while (pi.hasNext()) {
0161:                    _client.deletePackage((String) pi.next());
0162:                }
0163:                getLogger().info("testPurge passed");
0164:            }
0165:
0166:            public void testCreatePackage() throws IOException,
0167:                    XPDLParserException, WMWorkflowException {
0168:
0169:                pkgContent = readFile(TEST_PACKAGE_1);
0170:                pkgId1 = readPackage(pkgContent).getId();
0171:                String pkgId1 = _client
0172:                        .createPackage(pkgContent, WMClient.XPDL);
0173:                assertEquals("Package ID is wrong;", WMClientTest.pkgId1,
0174:                        pkgId1);
0175:                getLogger().info("testCreatePackage passed");
0176:            }
0177:
0178:            public void testGetPackageContent() throws WMWorkflowException,
0179:                    XPDLParserException, IOException {
0180:
0181:                String pkgContent1 = _client.getPackageContent(pkgId1,
0182:                        WMClient.XPDL);
0183:                checkPackageId(pkgId1, pkgContent1);
0184:                getLogger().info("testGetPackageContent passed");
0185:            }
0186:
0187:            public void testSetPackageContent() throws WMWorkflowException,
0188:                    XPDLParserException, IOException {
0189:
0190:                _client.setPackageContent(pkgId1, pkgContent, WMClient.XPDL);
0191:                String pkgContent3 = _client.getPackageContent(pkgId1,
0192:                        WMClient.XPDL);
0193:                checkPackageId(pkgId1, pkgContent3);
0194:
0195:                // Negative test - pass the wrong package ID.
0196:                String pkgContent2 = readFile(TEST_PACKAGE_2);
0197:                try {
0198:                    _client.setPackageContent(pkgId1, pkgContent2,
0199:                            WMClient.XPDL);
0200:                    fail("Failed to detect invalid package ID");
0201:                } catch (WMWorkflowException e) {
0202:                    getLogger().info(
0203:                            "Invalid package correctly threw exception: "
0204:                                    + e.getCause());
0205:                }
0206:
0207:                getLogger().info("testSetPackageContent passed");
0208:            }
0209:
0210:            public void testListProcessDefinitions() throws WMWorkflowException {
0211:                WMProcessDefinitionIterator iter = _client
0212:                        .listProcessDefinitions(null, false);
0213:                assertEquals("Process definition count is wrong;", 2, iter
0214:                        .getCount());
0215:                WMFilter filter = new WMFilter("packageId", WMFilter.EQ, pkgId1);
0216:                iter = _client.listProcessDefinitions(filter, false);
0217:                assertEquals("Process definition count is wrong;", 2, iter
0218:                        .getCount());
0219:                boolean b1 = false, b2 = false;
0220:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0221:                    WMProcessDefinition procDef = iter.tsNext();
0222:                    assertNotNull("Process definition was null;", procDef);
0223:                    String procDefId = procDef.getId();
0224:                    if (procDefId1.equals(procDefId))
0225:                        b1 = true;
0226:                    if (procDefId2.equals(procDefId))
0227:                        b2 = true;
0228:                }
0229:                assertTrue("Process definition ID is wrong: " + procDefId1, b1);
0230:                assertTrue("Process definition ID is wrong: " + procDefId2, b2);
0231:                try {
0232:                    iter.tsNext();
0233:                    fail("Fetch past end of data did not throw exception.");
0234:                } catch (WMWorkflowException e) {
0235:                    assertEquals("Error code for NoMoreData is wrong;",
0236:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0237:                }
0238:                getLogger().info("testListProcessDefinitions passed");
0239:            }
0240:
0241:            public void testListProcessDefinitionStates()
0242:                    throws WMWorkflowException {
0243:                WMProcessDefinitionStateIterator iter = _client
0244:                        .listProcessDefinitionStates(procDefId1, null, true);
0245:                assertEquals("Process definition states count is wrong;", 2,
0246:                        iter.getCount());
0247:                iter = _client.listProcessDefinitionStates(procDefId1, null,
0248:                        false);
0249:                assertEquals("Process definition states count is wrong;", 2,
0250:                        iter.getCount());
0251:                boolean b1 = false, b2 = false;
0252:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0253:                    WMProcessDefinitionState procDefState = iter.tsNext();
0254:                    assertNotNull("Process definition state is null;",
0255:                            procDefState);
0256:                    if (procDefState == WMProcessDefinitionState.ENABLED)
0257:                        b1 = true;
0258:                    else if (procDefState == WMProcessDefinitionState.DISABLED)
0259:                        b2 = true;
0260:                }
0261:                assertTrue("ProcesDefinitionState.ENABLED not returned;", b1);
0262:                assertTrue("ProcesDefinitionState.DISABLED not returned;", b2);
0263:                try {
0264:                    iter.tsNext();
0265:                    fail("Fetch past end of data did not throw exception.");
0266:                } catch (WMWorkflowException e) {
0267:                    assertEquals("NoMoreData exception is wrong;",
0268:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0269:                }
0270:                getLogger().info("testListProcessDefinitionStates passed");
0271:            }
0272:
0273:            public void testChangeProcessDefinitionState() throws Exception {
0274:                _client.changeProcessDefinitionState(procDefId2,
0275:                        WMProcessDefinitionState.DISABLED);
0276:
0277:                WMFilter filter = new WMFilter("processDefinitionId",
0278:                        WMFilter.EQ, procDefId2);
0279:                WMProcessDefinitionIterator iter = _client
0280:                        .listProcessDefinitions(filter, true);
0281:                assertEquals("Process definition count is wrong;", 1, iter
0282:                        .getCount());
0283:                iter = _client.listProcessDefinitions(filter, false);
0284:                assertEquals("Process definition count is wrong;", 1, iter
0285:                        .getCount());
0286:                WMProcessDefinition procDef = iter.tsNext();
0287:                assertNotNull("Process definition is null;", procDef);
0288:                assertEquals("Process definition is wrong;", procDefId2,
0289:                        procDef.getId());
0290:                assertEquals("Process definition state is wrong",
0291:                        WMProcessDefinitionState.DISABLED, procDef.getState());
0292:                testChangeProcessDefinitionStatePassed = true;
0293:                getLogger().info("testChangeProcessDefinitionState passed");
0294:            }
0295:
0296:            public void testCreateProcessInstance() throws WMWorkflowException {
0297:                procInstId1 = createProcessInstance(procDefId1, procInstName1);
0298:                procInstId2 = createProcessInstance(procDefId1, procInstName2);
0299:                procInstId3 = createProcessInstance(procDefId1, procInstName3);
0300:                procInstId4 = createProcessInstance(procDefId1, procInstName4);
0301:                procInstId5 = createProcessInstance(procDefId1, procInstName5);
0302:                procInstId6 = createProcessInstance(procDefId1, procInstName6);
0303:
0304:                // Negative test, but only run it if we succeeded in disabling
0305:                // procDefId2 in the previous test (otherwise it will show a false
0306:                // failure for this test).
0307:                if (testChangeProcessDefinitionStatePassed) {
0308:                    try {
0309:                        _client.createProcessInstance(procDefId2,
0310:                                "createProcessInstance");
0311:                        fail("createProcessInstance from disabled process definition did not throw exception.");
0312:                    } catch (WMWorkflowException e) {
0313:                        assertEquals(
0314:                                "createProcessInstance from disabled process definition exception is wrong",
0315:                                WMError.WM_INVALID_PROCESS_DEFINITION, e
0316:                                        .getError().getMainCode());
0317:                    }
0318:                }
0319:                getLogger().info("testCreateProcessInstance passed");
0320:            }
0321:
0322:            public void testStartProcess() throws WMWorkflowException {
0323:                procInstId1 = _client.startProcess(procInstId1);
0324:                checkProcessInstanceState(procInstId1,
0325:                        WMProcessInstanceState.OPEN_RUNNING);
0326:                procInstId2 = _client.startProcess(procInstId2);
0327:                checkProcessInstanceState(procInstId2,
0328:                        WMProcessInstanceState.OPEN_RUNNING);
0329:                procInstId3 = _client.startProcess(procInstId3);
0330:                checkProcessInstanceState(procInstId3,
0331:                        WMProcessInstanceState.OPEN_RUNNING);
0332:                procInstId4 = _client.startProcess(procInstId4);
0333:                checkProcessInstanceState(procInstId4,
0334:                        WMProcessInstanceState.OPEN_RUNNING);
0335:                getLogger().info("testStartProcess passed");
0336:            }
0337:
0338:            public void testGetProcessInstance() throws WMWorkflowException {
0339:                WMProcessInstance procInst = _client
0340:                        .getProcessInstance(procInstId1);
0341:                assertEquals("Process instance ID is wrong;", procInstId1,
0342:                        procInst.getId());
0343:                assertEquals("Process instance name is wrong;", procInstName1,
0344:                        procInst.getName());
0345:                // TODO: re-enable when we understand process instance participants.
0346:                //        assertEquals("Process instance participant count is wrong;", 2,
0347:                //        procInst.getParticipant().length);
0348:                //        assertNotNull("Process instance participant is null;",
0349:                //        procInst.getParticipant()[0]);
0350:                assertEquals("Process instance priority is wrong;", 7, procInst
0351:                        .getPriority());
0352:                assertEquals("Process instance definition ID is wrong;",
0353:                        procDefId1, procInst.getProcessDefinitionId());
0354:                assertEquals("Process instance state is wrong;",
0355:                        WMProcessInstanceState.OPEN_RUNNING, procInst
0356:                                .getState());
0357:                WMProcessInstance procInst2 = _client
0358:                        .getProcessInstance(procInstId2);
0359:                assertEquals("Process instance ID is wrong;", procInstId2,
0360:                        procInst2.getId());
0361:                assertEquals("Process instance name is wrong;", procInstName2,
0362:                        procInst2.getName());
0363:                //        assertEquals(2, procInst2.getParticipant().length);
0364:                //        assertNotNull(procInst2.getParticipant()[0]);
0365:                assertEquals("Process instance priority is wrong;", 7,
0366:                        procInst2.getPriority());
0367:                assertEquals("Process instance definition ID is wrong;",
0368:                        procDefId1, procInst2.getProcessDefinitionId());
0369:                assertEquals("Process instance state is wrong;",
0370:                        WMProcessInstanceState.OPEN_RUNNING, procInst2
0371:                                .getState());
0372:                WMProcessInstance procInst5 = _client
0373:                        .getProcessInstance(procInstId5);
0374:                assertEquals("Process instance ID is wrong;", procInstId5,
0375:                        procInst5.getId());
0376:                assertEquals("Process instance state is wrong;",
0377:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED,
0378:                        procInst5.getState());
0379:                WMProcessInstance procInst6 = _client
0380:                        .getProcessInstance(procInstId6);
0381:                assertEquals("Process instance ID is wrong;", procInstId6,
0382:                        procInst6.getId());
0383:                assertEquals("Process instance state is wrong;",
0384:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED,
0385:                        procInst6.getState());
0386:                getLogger().info("testGetProcessInstance passed");
0387:            }
0388:
0389:            public void testListProcessInstances() throws WMWorkflowException {
0390:                WMProcessInstanceIterator iter = _client.listProcessInstances(
0391:                        null, true);
0392:                assertEquals("Process instance count is wrong;", 6, iter
0393:                        .getCount());
0394:                iter = _client.listProcessInstances(null, false);
0395:                assertEquals("Process instance count is wrong;", 6, iter
0396:                        .getCount());
0397:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0398:                    WMProcessInstance procInst = iter.tsNext();
0399:                    assertNotNull("Process instance is null;", procInst);
0400:                    assertEquals("Process instance definition ID is wrong;",
0401:                            procDefId1, procInst.getProcessDefinitionId());
0402:                    assertTrue("Process instance ID is wrong;", procInst
0403:                            .getId().equals(procInstId1)
0404:                            || procInst.getId().equals(procInstId2)
0405:                            || procInst.getId().equals(procInstId3)
0406:                            || procInst.getId().equals(procInstId4)
0407:                            || procInst.getId().equals(procInstId5)
0408:                            || procInst.getId().equals(procInstId6));
0409:                }
0410:                try {
0411:                    iter.tsNext();
0412:                    fail("Fetch past end of data did not throw exception.");
0413:                } catch (WMWorkflowException e) {
0414:                    assertEquals("NoMoreData exception is wrong;",
0415:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0416:                }
0417:                getLogger().info("testListProcessInstances passed");
0418:            }
0419:
0420:            public void testListProcessInstanceStates()
0421:                    throws WMWorkflowException {
0422:                final int[] validStates = {
0423:                        WMProcessInstanceState.OPEN_RUNNING_INT,
0424:                        WMProcessInstanceState.OPEN_NOTRUNNING_SUSPENDED_INT,
0425:                        WMProcessInstanceState.CLOSED_COMPLETED_INT,
0426:                        WMProcessInstanceState.CLOSED_ABORTED_INT,
0427:                        WMProcessInstanceState.CLOSED_TERMINATED_INT };
0428:                WMProcessInstanceStateIterator iter = _client
0429:                        .listProcessInstanceStates(procInstId1, null, true);
0430:                assertEquals("Process instance states count is wrong;",
0431:                        validStates.length, iter.getCount());
0432:                iter = _client.listProcessInstanceStates(procInstId1, null,
0433:                        false);
0434:                assertEquals("Process instance states count is wrong;",
0435:                        validStates.length, iter.getCount());
0436:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0437:                    WMProcessInstanceState procInstState = iter.tsNext();
0438:                    assertNotNull("Process instance state is null;",
0439:                            procInstState);
0440:                    int state = procInstState.value();
0441:                    boolean okay = false;
0442:                    for (int j = 0; j < validStates.length; j++) {
0443:                        if (state == validStates[j]) {
0444:                            okay = true;
0445:                            break;
0446:                        }
0447:                    }
0448:                    assertTrue("Process instance valid states list is wrong;",
0449:                            okay);
0450:                }
0451:                try {
0452:                    iter.tsNext();
0453:                    fail("Fetch past end of data did not throw exception.");
0454:                } catch (WMWorkflowException e) {
0455:                    assertEquals("NoMoreData exception is wrong;",
0456:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0457:                }
0458:                getLogger().info("testListProcessInstanceStates passed");
0459:            }
0460:
0461:            public void testChangeProcessInstanceState()
0462:                    throws WMWorkflowException {
0463:                _client.changeProcessInstanceState(procInstId1,
0464:                        WMProcessInstanceState.OPEN_NOTRUNNING_SUSPENDED);
0465:                checkProcessInstanceState(procInstId1,
0466:                        WMProcessInstanceState.OPEN_NOTRUNNING_SUSPENDED);
0467:                _client.changeProcessInstanceState(procInstId1,
0468:                        WMProcessInstanceState.OPEN_RUNNING);
0469:                checkProcessInstanceState(procInstId1,
0470:                        WMProcessInstanceState.OPEN_RUNNING);
0471:                getLogger().info("testChangeProcessInstanceState passed");
0472:            }
0473:
0474:            public void testChangeProcessInstancesState()
0475:                    throws WMWorkflowException {
0476:                // Suspend all process instances.
0477:                _client.changeProcessInstancesState(procDefId1, null,
0478:                        WMProcessInstanceState.OPEN_NOTRUNNING_SUSPENDED);
0479:
0480:                String procInstIds[] = { procInstId1, procInstId2, procInstId3,
0481:                        procInstId4 };
0482:                for (int i = 0; i < procInstIds.length; i++) {
0483:                    String procInstId = procInstIds[i];
0484:                    checkProcessInstanceState(procInstId,
0485:                            WMProcessInstanceState.OPEN_NOTRUNNING_SUSPENDED);
0486:                }
0487:
0488:                // Resume process instances 1, 2, 3, 4 and 5.
0489:                for (int i = 0; i < procInstIds.length; i++) {
0490:                    String procInstId = procInstIds[i];
0491:                    WMFilter filter = new WMFilter(
0492:                            ProcessInstanceAttributes.PROCESS_INSTANCE_ID,
0493:                            WMFilter.EQ, procInstId);
0494:                    _client.changeProcessInstancesState(procDefId1, filter,
0495:                            WMProcessInstanceState.OPEN_RUNNING);
0496:                    checkProcessInstanceState(procInstId,
0497:                            WMProcessInstanceState.OPEN_RUNNING);
0498:                    for (int j = i + 1; j < procInstIds.length; j++) {
0499:                        checkProcessInstanceState(
0500:                                procInstIds[j],
0501:                                WMProcessInstanceState.OPEN_NOTRUNNING_SUSPENDED);
0502:                    }
0503:                }
0504:                getLogger().info("testChangeProcessInstancesState passed");
0505:            }
0506:
0507:            public void testListProcessInstanceAttributes()
0508:                    throws WMWorkflowException {
0509:                WMAttributeIterator iter = _client
0510:                        .listProcessInstanceAttributes(procInstId1, null, true);
0511:                assertEquals("Process instance attribute count is wrong;", 16,
0512:                        iter.getCount());
0513:                iter = _client.listProcessInstanceAttributes(procInstId1, null,
0514:                        false);
0515:                assertEquals("Process instance attribute count is wrong;", 16,
0516:                        iter.getCount());
0517:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0518:                    WMAttribute attr = iter.tsNext();
0519:                    assertNotNull("Attribute is null;", attr);
0520:                }
0521:                try {
0522:                    iter.tsNext();
0523:                    fail("Fetch past end of data did not throw exception.");
0524:                } catch (WMWorkflowException e) {
0525:                    assertEquals("NoMoreData exception is wrong;",
0526:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0527:                }
0528:                getLogger().info("testListProcessInstanceAttributes passed");
0529:            }
0530:
0531:            public void testGetProcessInstanceAttributeValue()
0532:                    throws WMWorkflowException {
0533:
0534:                checkProcessInstanceAttributeValue(procInstId1, "stringVar",
0535:                        WMAttribute.STRING_TYPE, "Hello, World");
0536:                checkProcessInstanceAttributeValue(procInstId1,
0537:                        "processDefinitionId", WMAttribute.STRING_TYPE,
0538:                        procDefId1);
0539:                try {
0540:                    _client.getProcessInstanceAttributeValue(procInstId1,
0541:                            "nonExistentAttribute");
0542:                    fail("Get invalid attribute name did not throw exception.");
0543:                } catch (WMWorkflowException e) {
0544:                    assertEquals("Invalid attribute exception is wrong;",
0545:                            WMError.WM_INVALID_ATTRIBUTE, e.getError()
0546:                                    .getMainCode());
0547:                }
0548:                getLogger().info("testGetProcessInstanceAttributeValue passed");
0549:            }
0550:
0551:            public void testAssignProcessInstanceAttribute()
0552:                    throws WMWorkflowException {
0553:                // Test a custom attribute.
0554:                String attrName = "stringVar";
0555:                Object attrValue = "someAttributeValue";
0556:                _client.assignProcessInstanceAttribute(procInstId1, attrName,
0557:                        attrValue);
0558:                checkProcessInstanceAttributeValue(procInstId1, attrName,
0559:                        WMAttribute.STRING_TYPE, attrValue);
0560:
0561:                // Test a writable system attribute.
0562:                attrName = "priority";
0563:                attrValue = new Integer(3);
0564:                _client.assignProcessInstanceAttribute(procInstId1, attrName,
0565:                        attrValue);
0566:                checkProcessInstanceAttributeValue(procInstId1, attrName,
0567:                        WMAttribute.INTEGER_TYPE, attrValue);
0568:
0569:                // Test a read-only system attribute.
0570:                try {
0571:                    _client.assignProcessInstanceAttribute(procInstId1,
0572:                            "processInstanceId", "something wrong");
0573:                    fail("Attempting to set a read-only system attribute did not throw an exception.");
0574:                } catch (WMWorkflowException e) {
0575:                    // Make sure it wasn't the wrong exception.
0576:                    assertTrue("System attribute processInstanceId not found;",
0577:                            !(e instanceof  WMInvalidAttributeException));
0578:                }
0579:
0580:                getLogger().info("testAssignProcessInstanceAttribute passed");
0581:            }
0582:
0583:            public void testAssignProcessInstancesAttribute()
0584:                    throws WMWorkflowException {
0585:                WMFilter filter = new WMFilter(
0586:                        "state",
0587:                        WMFilter.EQ,
0588:                        new Integer(
0589:                                WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED_INT));
0590:                String[] ovProcInstIds = { procInstId2, procInstId3,
0591:                        procInstId4 };
0592:                String[] nvProcInstIds = { procInstId5, procInstId6 };
0593:
0594:                // Test a custom attribute.
0595:                String attrName = "stringVar";
0596:                Object oldValue1 = "Hello, World";
0597:                Object oldValue2 = "someAttributeValue";
0598:                Object newValue = "aDifferentAttributeValue";
0599:                _client.assignProcessInstancesAttribute(procDefId1, filter,
0600:                        attrName, newValue);
0601:                checkProcessInstanceAttributeValue(procInstId1, attrName,
0602:                        WMAttribute.STRING_TYPE, oldValue2);
0603:                checkProcessInstancesAttributeValue(ovProcInstIds, attrName,
0604:                        WMAttribute.STRING_TYPE, oldValue1);
0605:                checkProcessInstancesAttributeValue(nvProcInstIds, attrName,
0606:                        WMAttribute.STRING_TYPE, newValue);
0607:
0608:                // Test a writable system attribute.
0609:                attrName = "priority";
0610:                oldValue2 = new Integer(7);
0611:                newValue = new Integer(9);
0612:                _client.assignProcessInstancesAttribute(procDefId1, filter,
0613:                        attrName, newValue);
0614:                checkProcessInstancesAttributeValue(ovProcInstIds, attrName,
0615:                        WMAttribute.INTEGER_TYPE, oldValue2);
0616:                checkProcessInstancesAttributeValue(nvProcInstIds, attrName,
0617:                        WMAttribute.INTEGER_TYPE, newValue);
0618:
0619:                // Test a read-only system attribute.
0620:                try {
0621:                    _client.assignProcessInstancesAttribute(procDefId1, filter,
0622:                            "processInstanceId", "something wrong");
0623:                    fail("Attempting to set read-only system attributes did not throw an exception.");
0624:                } catch (WMWorkflowException e) {
0625:                    // We expect this to throw an exception.
0626:                }
0627:
0628:                getLogger().info("testAssignProcessInstancesAttribute passed");
0629:            }
0630:
0631:            public void testListActivityInstances() throws WMWorkflowException {
0632:                WMFilter filter = new WMFilter(
0633:                        ActivityInstanceAttributes.PROCESS_INSTANCE_ID,
0634:                        WMFilter.EQ, procInstId1);
0635:                WMActivityInstanceIterator iter = _client
0636:                        .listActivityInstances(filter, true);
0637:                assertEquals("Activity instance count is wrong;", 1, iter
0638:                        .getCount());
0639:                iter = _client.listActivityInstances(filter, false);
0640:                assertEquals("Activity instance count is wrong;", 1, iter
0641:                        .getCount());
0642:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0643:                    WMActivityInstance activityInst = iter.tsNext();
0644:                    assertNotNull("Activity instance is null;", activityInst);
0645:                    String actDefId = activityInst.getActivityDefinitionId();
0646:                    if (actDefId.equals(actDefId1))
0647:                        actInstId1 = activityInst.getId();
0648:                }
0649:                try {
0650:                    iter.tsNext();
0651:                    fail("Fetch past end of data did not throw exception.");
0652:                } catch (WMWorkflowException e) {
0653:                    assertEquals("NoMoreData exception is wrong",
0654:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0655:                }
0656:                getLogger().info("testListActivityInstances passed");
0657:            }
0658:
0659:            public void testGetActivityInstance() throws WMWorkflowException {
0660:                WMActivityInstance activityInst = _client.getActivityInstance(
0661:                        procInstId1, actInstId1);
0662:                assertNotNull("Activity instance is null;", activityInst);
0663:                assertEquals("Activity instance ID is wrong;", actInstId1,
0664:                        activityInst.getId());
0665:                assertEquals("Activity instance name is wrong;", "activity1",
0666:                        activityInst.getName());
0667:                assertEquals("Activity instance participant count is wrong;",
0668:                        1, activityInst.getParticipants().length);
0669:                assertEquals("Activity instance priority is wrong;", 7,
0670:                        activityInst.getPriority());
0671:                assertEquals("Activity process instance ID is wrong;",
0672:                        procInstId1, activityInst.getProcessInstanceId());
0673:                assertEquals("Activity instance state is wrong;",
0674:                        WMActivityInstanceState.OPEN_RUNNING, activityInst
0675:                                .getState());
0676:                getLogger().info("testGetActivityInstance passed");
0677:            }
0678:
0679:            public void testListActivityInstanceStates()
0680:                    throws WMWorkflowException {
0681:                WMActivityInstanceStateIterator iter = _client
0682:                        .listActivityInstanceStates(procInstId1, actInstId1,
0683:                                null, true);
0684:                assertEquals("Activity instance state count is wrong;", 6, iter
0685:                        .getCount());
0686:                iter = _client.listActivityInstanceStates(procInstId1,
0687:                        actInstId1, null, false);
0688:                assertEquals("Activity instance state count is wrong;", 6, iter
0689:                        .getCount());
0690:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0691:                    WMActivityInstanceState actInstState = iter.tsNext();
0692:                    assertNotNull("Activity instance state is null;",
0693:                            actInstState);
0694:                }
0695:                try {
0696:                    iter.tsNext();
0697:                    fail("Fetch past end of data did not throw exception.");
0698:                } catch (WMWorkflowException e) {
0699:                    assertEquals("NoMoreData exception is wrong",
0700:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0701:                }
0702:                getLogger().info("testListActivityInstanceStates passed");
0703:            }
0704:
0705:            public void testChangeActivityInstanceState()
0706:                    throws WMWorkflowException {
0707:                _client.changeActivityInstanceState(procInstId1, actInstId1,
0708:                        WMActivityInstanceState.OPEN_SUSPENDED);
0709:                checkActivityInstanceState(procInstId1, actInstId1,
0710:                        WMActivityInstanceState.OPEN_SUSPENDED);
0711:                _client.changeActivityInstanceState(procInstId1, actInstId1,
0712:                        WMActivityInstanceState.OPEN_RUNNING);
0713:                checkActivityInstanceState(procInstId1, actInstId1,
0714:                        WMActivityInstanceState.OPEN_RUNNING);
0715:                getLogger().info("testChangeActivityInstanceState passed");
0716:            }
0717:
0718:            public void testChangeActivityInstancesState()
0719:                    throws WMWorkflowException {
0720:                _client.changeActivityInstancesState(procDefId1, actDefId1,
0721:                        null, WMActivityInstanceState.OPEN_SUSPENDED);
0722:                WMFilter filter = new WMFilter("processDefinitionId = '"
0723:                        + procDefId1 + "' AND activityDefinitionId = '"
0724:                        + actDefId1 + "'");
0725:                WMActivityInstanceIterator iter = _client
0726:                        .listActivityInstances(filter, false);
0727:                for (int i = 0; i < iter.getCount(); i++) {
0728:                    WMActivityInstance activityInst = iter.tsNext();
0729:                    assertEquals("Activity instance state is wrong;",
0730:                            WMActivityInstanceState.OPEN_SUSPENDED,
0731:                            activityInst.getState());
0732:                }
0733:                _client.changeActivityInstancesState(procDefId1, actDefId1,
0734:                        null, WMActivityInstanceState.OPEN_RUNNING);
0735:                iter = _client.listActivityInstances(filter, false);
0736:                for (int i = 0; i < iter.getCount(); i++) {
0737:                    WMActivityInstance activityInst = iter.tsNext();
0738:                    assertEquals("Activity instance state is wrong;",
0739:                            WMActivityInstanceState.OPEN_RUNNING, activityInst
0740:                                    .getState());
0741:                }
0742:                getLogger().info("testChangeActivityInstancesState passed");
0743:            }
0744:
0745:            public void testListActivityInstanceAttributes()
0746:                    throws WMWorkflowException {
0747:                WMAttributeIterator iter = _client
0748:                        .listActivityInstanceAttributes(null, actInstId1, null,
0749:                                true);
0750:                assertEquals("Activity instance attribute count is wrong;", 16,
0751:                        iter.getCount());
0752:                iter = _client.listActivityInstanceAttributes(null, actInstId1,
0753:                        null, false);
0754:                assertEquals("Activity instance attribute count is wrong;", 16,
0755:                        iter.getCount());
0756:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0757:                    WMAttribute attr = iter.tsNext();
0758:                    assertNotNull("Activity instance is null;", attr);
0759:                }
0760:                try {
0761:                    iter.tsNext();
0762:                    fail("Fetch past end of data did not throw exception.");
0763:                } catch (WMWorkflowException e) {
0764:                    assertEquals("NoMoreData exception is wrong;",
0765:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0766:                }
0767:                getLogger().info("testListActivityInstanceAttributes passed");
0768:            }
0769:
0770:            public void testGetActivityInstanceAttributeValue()
0771:                    throws WMWorkflowException {
0772:
0773:                checkActivityInstanceAttributeValue(procInstId1, actInstId1,
0774:                        "processDefinitionId", WMAttribute.STRING_TYPE,
0775:                        procDefId1);
0776:                try {
0777:                    _client.getActivityInstanceAttributeValue(procInstId1,
0778:                            actInstId1, "nonExistentAttribute");
0779:                    fail("Get invalid attribute name did not throw exception.");
0780:                } catch (WMWorkflowException e) {
0781:                    assertEquals("Invalid attribute name exception is wrong;",
0782:                            WMError.WM_INVALID_ATTRIBUTE, e.getError()
0783:                                    .getMainCode());
0784:                }
0785:                getLogger()
0786:                        .info("testGetActivityInstanceAttributeValue passed");
0787:            }
0788:
0789:            public void testAssignActivityInstanceAttribute()
0790:                    throws WMWorkflowException {
0791:                String attrName = "priority";
0792:                Object attrValue = new Integer(7);
0793:                _client.assignActivityInstanceAttribute(procInstId1,
0794:                        actInstId1, attrName, attrValue);
0795:                checkActivityInstanceAttributeValue(procInstId1, actInstId1,
0796:                        attrName, WMAttribute.INTEGER_TYPE, attrValue);
0797:                getLogger().info("testAssignActivityInstanceAttribute passed");
0798:            }
0799:
0800:            public void testAssignActivityInstancesAttribute()
0801:                    throws WMWorkflowException {
0802:
0803:                // TODO: use a filter.
0804:                String attrName = "priority";
0805:                Object attrValue = new Integer(3);
0806:                _client.assignActivityInstancesAttribute(procDefId1, actDefId1,
0807:                        null, attrName, attrValue);
0808:                checkActivityInstanceAttributeValue(procInstId1, actInstId1,
0809:                        attrName, WMAttribute.INTEGER_TYPE, attrValue);
0810:                checkActivityInstanceAttributeValue(procInstId2, actInstId1,
0811:                        attrName, WMAttribute.INTEGER_TYPE, attrValue);
0812:                getLogger().info("testAssignActivityInstancesAttribute passed");
0813:            }
0814:
0815:            public void testListWorkItems() throws WMWorkflowException {
0816:                WMFilter filter = new WMFilter(
0817:                        WorkItemAttributes.PROCESS_INSTANCE_ID, WMFilter.EQ,
0818:                        procInstId1);
0819:                WMWorkItemIterator iter = _client.listWorkItems(filter, true);
0820:                assertEquals("Work item count is wrong;", 1, iter.getCount());
0821:                iter = _client.listWorkItems(filter, false);
0822:                assertEquals("Work item count is wrong;", 1, iter.getCount());
0823:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0824:                    WMWorkItem workItem = iter.tsNext();
0825:                    assertNotNull("Work item is null;", workItem);
0826:                    if (workItem.getActivityInstanceId().equals(actInstId1))
0827:                        workItemId1 = workItem.getId();
0828:                    else
0829:                        fail("Wrong work item ID");
0830:                }
0831:                try {
0832:                    iter.tsNext();
0833:                    fail("Fetch past end of data did not throw exception.");
0834:                } catch (WMWorkflowException e) {
0835:                    assertEquals("NoMoreData exception is wrong;",
0836:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0837:                }
0838:                getLogger().info("testListWorkItems passed");
0839:            }
0840:
0841:            public void testGetWorkItem() throws WMWorkflowException {
0842:                WMWorkItem workItem = _client.getWorkItem(procInstId1,
0843:                        workItemId1);
0844:                assertNotNull("Work item count is null;", workItem);
0845:                assertEquals("Work item activity instance ID is wrong;",
0846:                        actInstId1, workItem.getActivityInstanceId());
0847:                assertEquals("Work item ID is wrong;", workItemId1, workItem
0848:                        .getId());
0849:                assertEquals("Work item name is wrong;", "activity1", workItem
0850:                        .getName());
0851:                assertEquals("Work item participant is wrong;", "system",
0852:                        workItem.getParticipant().getName());
0853:                assertEquals("Work item priority is wrong;", 7, workItem
0854:                        .getPriority());
0855:                assertEquals("Work item process instance ID is wrong;",
0856:                        procInstId1, workItem.getProcessInstanceId());
0857:                assertEquals("Work item state is wrong;",
0858:                        WMWorkItemState.OPEN_RUNNING, workItem.getState());
0859:                getLogger().info("testGetWorkItem passed");
0860:            }
0861:
0862:            public void testReassignWorkItem() throws WMWorkflowException {
0863:                try {
0864:                    _client.reassignWorkItem("system", "nouser", procInstId1,
0865:                            workItemId1);
0866:                    fail("reassignWorkItem to invalid target user did not throw an exception");
0867:                } catch (WMInvalidTargetUserException e) {
0868:                } catch (Exception e) {
0869:                    fail("reassignWorkItem to invalid target user threw the wrong exception: "
0870:                            + e);
0871:                }
0872:                String targetUser = "testuser1";
0873:                _client.reassignWorkItem("system", targetUser, procInstId1,
0874:                        workItemId1);
0875:                WMWorkItem workItem = _client.getWorkItem(procInstId1,
0876:                        workItemId1);
0877:                assertEquals("Work item participant is wrong;", targetUser,
0878:                        workItem.getParticipant().getName());
0879:                getLogger().info("testReassignWorkItem passed");
0880:            }
0881:
0882:            public void testCompleteWorkItem() throws WMWorkflowException {
0883:                _client.completeWorkItem(procInstId1, workItemId1);
0884:                WMWorkItem workItem = _client.getWorkItem(procInstId1,
0885:                        workItemId1);
0886:                assertEquals("Work item state is wrong;",
0887:                        WMWorkItemState.CLOSED_COMPLETED, workItem.getState());
0888:                getLogger().info("testCompleteWorkItem passed");
0889:            }
0890:
0891:            public void testListWorkItemAttributes() throws WMWorkflowException {
0892:                WMAttributeIterator iter = _client.listWorkItemAttributes(null,
0893:                        workItemId1, null, true);
0894:                assertEquals("Wrong work item attribute count", 16, iter
0895:                        .getCount());
0896:                iter = _client.listWorkItemAttributes(null, workItemId1, null,
0897:                        false);
0898:                assertEquals("Wrong work item attribute count", 16, iter
0899:                        .getCount());
0900:                for (int i = 0, n = iter.getCount(); i < n; i++) {
0901:                    WMAttribute attr = iter.tsNext();
0902:                    assertNotNull("Work item attribute is null;", attr);
0903:                }
0904:                try {
0905:                    iter.tsNext();
0906:                    fail("Fetch past end of data did not throw exception.");
0907:                } catch (WMWorkflowException e) {
0908:                    assertEquals("NoMoreData exception is wrong;",
0909:                            WMError.WM_NO_MORE_DATA, e.getError().getMainCode());
0910:                }
0911:                getLogger().info("testListWorkItemAttributes passed");
0912:            }
0913:
0914:            public void testGetWorkItemAttributeValue()
0915:                    throws WMWorkflowException {
0916:                checkWorkItemAttributeValue(procInstId1, workItemId1, "state",
0917:                        WMAttribute.INTEGER_TYPE, new Integer(
0918:                                WMWorkItemState.CLOSED_COMPLETED_INT));
0919:                checkWorkItemAttributeValue(procInstId1, workItemId1,
0920:                        "processDefinitionId", WMAttribute.STRING_TYPE,
0921:                        procDefId1);
0922:                try {
0923:                    _client.getWorkItemAttributeValue(procInstId1, workItemId1,
0924:                            "nonExistentAttribute");
0925:                    fail("Get invalid attribute name did not throw exception.");
0926:                } catch (WMWorkflowException e) {
0927:                    assertEquals("Invalid attribute exception is wrong;",
0928:                            WMError.WM_INVALID_ATTRIBUTE, e.getError()
0929:                                    .getMainCode());
0930:                }
0931:                getLogger().info("testGetWorkItemAttributeValue passed");
0932:            }
0933:
0934:            public void testAssignWorkItemAttribute()
0935:                    throws WMWorkflowException {
0936:                String attrName = "priority";
0937:                Object attrValue = new Integer(3);
0938:                _client.assignWorkItemAttribute(procInstId1, workItemId1,
0939:                        attrName, attrValue);
0940:                checkWorkItemAttributeValue(procInstId1, workItemId1, attrName,
0941:                        WMAttribute.INTEGER_TYPE, attrValue);
0942:                getLogger().info("testAssignWorkItemAttribute passed");
0943:            }
0944:
0945:            public void testAbortProcessInstance() throws WMWorkflowException {
0946:                _client.abortProcessInstance(procInstId1);
0947:                checkProcessInstanceState(procInstId1,
0948:                        WMProcessInstanceState.CLOSED_ABORTED);
0949:                checkProcessInstanceState(procInstId2,
0950:                        WMProcessInstanceState.OPEN_RUNNING);
0951:                checkProcessInstanceState(procInstId3,
0952:                        WMProcessInstanceState.OPEN_RUNNING);
0953:                checkProcessInstanceState(procInstId4,
0954:                        WMProcessInstanceState.OPEN_RUNNING);
0955:                checkProcessInstanceState(procInstId5,
0956:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED);
0957:                checkProcessInstanceState(procInstId6,
0958:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED);
0959:                testAbortProcessInstancePassed = true;
0960:                getLogger().info("testAbortProcessInstancePassed passed");
0961:            }
0962:
0963:            public void testTerminateProcessInstance()
0964:                    throws WMWorkflowException {
0965:                _client.terminateProcessInstance(procInstId2);
0966:                if (testAbortProcessInstancePassed) {
0967:                    checkProcessInstanceState(procInstId1,
0968:                            WMProcessInstanceState.CLOSED_ABORTED);
0969:                }
0970:                checkProcessInstanceState(procInstId2,
0971:                        WMProcessInstanceState.CLOSED_TERMINATED);
0972:                checkProcessInstanceState(procInstId3,
0973:                        WMProcessInstanceState.OPEN_RUNNING);
0974:                checkProcessInstanceState(procInstId4,
0975:                        WMProcessInstanceState.OPEN_RUNNING);
0976:                checkProcessInstanceState(procInstId5,
0977:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED);
0978:                checkProcessInstanceState(procInstId6,
0979:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED);
0980:                testTerminateProcessInstancePassed = true;
0981:                getLogger().info("testTerminateProcessInstancePassed passed");
0982:            }
0983:
0984:            public void testAbortProcessInstances() throws WMWorkflowException {
0985:                WMFilter filter = new WMFilter("state", WMFilter.EQ,
0986:                        WMProcessInstanceState.OPEN_RUNNING_INT);
0987:                _client.abortProcessInstances(procDefId1, filter);
0988:                if (testAbortProcessInstancePassed) {
0989:                    checkProcessInstanceState(procInstId1,
0990:                            WMProcessInstanceState.CLOSED_ABORTED);
0991:                }
0992:                if (testTerminateProcessInstancePassed) {
0993:                    checkProcessInstanceState(procInstId2,
0994:                            WMProcessInstanceState.CLOSED_TERMINATED);
0995:                }
0996:                checkProcessInstanceState(procInstId3,
0997:                        WMProcessInstanceState.CLOSED_ABORTED);
0998:                checkProcessInstanceState(procInstId4,
0999:                        WMProcessInstanceState.CLOSED_ABORTED);
1000:                checkProcessInstanceState(procInstId5,
1001:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED);
1002:                checkProcessInstanceState(procInstId6,
1003:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED);
1004:                testAbortProcessInstancesPassed = true;
1005:                getLogger().info("testAbortProcessInstances passed");
1006:            }
1007:
1008:            public void testTerminateProcessInstances()
1009:                    throws WMWorkflowException {
1010:                WMFilter filter = new WMFilter("state", WMFilter.EQ,
1011:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED_INT);
1012:                _client.terminateProcessInstances(procDefId1, filter);
1013:                if (testAbortProcessInstancePassed) {
1014:                    checkProcessInstanceState(procInstId1,
1015:                            WMProcessInstanceState.CLOSED_ABORTED);
1016:                }
1017:                if (testTerminateProcessInstancePassed) {
1018:                    checkProcessInstanceState(procInstId2,
1019:                            WMProcessInstanceState.CLOSED_TERMINATED);
1020:                }
1021:                if (testAbortProcessInstancesPassed) {
1022:                    checkProcessInstanceState(procInstId3,
1023:                            WMProcessInstanceState.CLOSED_ABORTED);
1024:                    checkProcessInstanceState(procInstId4,
1025:                            WMProcessInstanceState.CLOSED_ABORTED);
1026:                }
1027:                checkProcessInstanceState(procInstId5,
1028:                        WMProcessInstanceState.CLOSED_TERMINATED);
1029:                checkProcessInstanceState(procInstId6,
1030:                        WMProcessInstanceState.CLOSED_TERMINATED);
1031:                testTerminateProcessInstancesPassed = true;
1032:                getLogger().info("testTerminateProcessInstances passed");
1033:            }
1034:
1035:            public void testDeleteProcessInstance() throws WMWorkflowException {
1036:                _client.deleteProcessInstance(procInstId1);
1037:                checkNoProcessInstance(procInstId1);
1038:                if (testTerminateProcessInstancePassed) {
1039:                    checkProcessInstanceState(procInstId2,
1040:                            WMProcessInstanceState.CLOSED_TERMINATED);
1041:                }
1042:                if (testAbortProcessInstancesPassed) {
1043:                    checkProcessInstanceState(procInstId3,
1044:                            WMProcessInstanceState.CLOSED_ABORTED);
1045:                    checkProcessInstanceState(procInstId4,
1046:                            WMProcessInstanceState.CLOSED_ABORTED);
1047:                }
1048:                if (testTerminateProcessInstancesPassed) {
1049:                    checkProcessInstanceState(procInstId5,
1050:                            WMProcessInstanceState.CLOSED_TERMINATED);
1051:                    checkProcessInstanceState(procInstId6,
1052:                            WMProcessInstanceState.CLOSED_TERMINATED);
1053:                }
1054:                getLogger().info("testDeleteProcessInstance passed");
1055:            }
1056:
1057:            public void testDeleteProcessInstances() throws WMWorkflowException {
1058:                WMFilter filter = new WMFilter("state", WMFilter.EQ,
1059:                        WMProcessInstanceState.CLOSED_ABORTED_INT);
1060:                _client.deleteProcessInstances(procDefId1, filter);
1061:
1062:                if (testTerminateProcessInstancePassed) {
1063:                    checkProcessInstanceState(procInstId2,
1064:                            WMProcessInstanceState.CLOSED_TERMINATED);
1065:                }
1066:                checkNoProcessInstance(procInstId3);
1067:                checkNoProcessInstance(procInstId4);
1068:                if (testTerminateProcessInstancesPassed) {
1069:                    checkProcessInstanceState(procInstId5,
1070:                            WMProcessInstanceState.CLOSED_TERMINATED);
1071:                    checkProcessInstanceState(procInstId6,
1072:                            WMProcessInstanceState.CLOSED_TERMINATED);
1073:                }
1074:
1075:                _client.deleteProcessInstances(procDefId1, null);
1076:                checkNoProcessInstance(procInstId2);
1077:                checkNoProcessInstance(procInstId5);
1078:                checkNoProcessInstance(procInstId6);
1079:                testDeleteProcessInstancesPassed = true;
1080:                getLogger().info("testDeleteProcessInstances passed");
1081:            }
1082:
1083:            public void testDeletePackage() throws Exception {
1084:                if (!testDeleteProcessInstancesPassed) {
1085:                    _client.deleteProcessInstances(procDefId1, null);
1086:                }
1087:                _client.deletePackage(pkgId1);
1088:
1089:                WMProcessDefinitionIterator iter = _client
1090:                        .listProcessDefinitions(null, true);
1091:                assertEquals(
1092:                        "Delete package did not delete all process definitions;",
1093:                        0, iter.getCount());
1094:                getLogger().info("testDeletePackage passed");
1095:            }
1096:
1097:            public void testDisconnect() throws WMWorkflowException {
1098:                disconnect();
1099:                try {
1100:                    _client.disconnect();
1101:                    fail("Invalid disconnect did not throw exception.");
1102:                } catch (WMConnectException e) {
1103:                    // This is the correct behaviour.
1104:                } catch (Exception e) {
1105:                    fail("Invalid disconnect threw wrong exception: " + e);
1106:                }
1107:                getLogger().info("testDisconnect passed");
1108:            }
1109:
1110:            private String createProcessInstance(String processDefinitionId,
1111:                    String procInstName) throws WMWorkflowException {
1112:
1113:                String procInstId = _client.createProcessInstance(
1114:                        processDefinitionId, procInstName);
1115:                checkProcessInstanceState(procInstId,
1116:                        WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED);
1117:                return procInstId;
1118:            }
1119:
1120:            private static void checkProcessInstanceState(
1121:                    String processInstanceId, WMProcessInstanceState state)
1122:                    throws WMWorkflowException {
1123:
1124:                WMProcessInstance procInst = _client
1125:                        .getProcessInstance(processInstanceId);
1126:                assertEquals("Process instance ID is wrong;",
1127:                        processInstanceId, procInst.getId());
1128:                assertEquals("Process instance '" + processInstanceId
1129:                        + "' state is wrong;", state, procInst.getState());
1130:            }
1131:
1132:            private void checkProcessInstanceAttributeValue(
1133:                    String processInstanceId, String attrName, int attrType,
1134:                    Object attrValue) throws WMWorkflowException {
1135:
1136:                WMAttribute attr = _client.getProcessInstanceAttributeValue(
1137:                        processInstanceId, attrName);
1138:                assertNotNull("Process instance '" + processInstanceId
1139:                        + "' attribute '" + attrName + "' is null;", attr);
1140:                assertEquals("Process instance '" + processInstanceId
1141:                        + "' attribute '" + attrName + "' name is wrong;",
1142:                        attrName, attr.getName());
1143:                assertEquals("Process instance '" + processInstanceId
1144:                        + "' attribute '" + attrName + "' type is wrong;",
1145:                        attrType, attr.getType());
1146:                assertEquals("Process instance '" + processInstanceId
1147:                        + "' attribute '" + attrName + "' value is wrong;",
1148:                        attrValue, attr.getValue());
1149:            }
1150:
1151:            private void checkProcessInstancesAttributeValue(
1152:                    String[] procInstIds, String attrName, int attrType,
1153:                    Object attrValue) throws WMWorkflowException {
1154:
1155:                for (int i = 0; i < procInstIds.length; i++) {
1156:                    checkProcessInstanceAttributeValue(procInstIds[i],
1157:                            attrName, attrType, attrValue);
1158:                }
1159:            }
1160:
1161:            private void checkActivityInstanceState(String processInstanceId,
1162:                    String activityInstId, WMActivityInstanceState state)
1163:                    throws WMWorkflowException {
1164:
1165:                WMActivityInstance activityInst = _client.getActivityInstance(
1166:                        processInstanceId, activityInstId);
1167:                assertEquals("Activity instance '" + activityInstId
1168:                        + "' state is wrong;", state, activityInst.getState());
1169:            }
1170:
1171:            private void checkActivityInstanceAttributeValue(
1172:                    String processInstanceId, String activityInstId,
1173:                    String attrName, int attrType, Object attrValue)
1174:                    throws WMWorkflowException {
1175:
1176:                WMAttribute attr = _client.getActivityInstanceAttributeValue(
1177:                        processInstanceId, activityInstId, attrName);
1178:                assertEquals("Activity instance '" + activityInstId
1179:                        + "' attribute '" + attrName + "' type is wrong;",
1180:                        attrType, attr.getType());
1181:                assertEquals("Activity instance '" + activityInstId
1182:                        + "' attribute '" + attrName + "' value is wrong;",
1183:                        attrValue, attr.getValue());
1184:            }
1185:
1186:            private void checkWorkItemAttributeValue(String processInstanceId,
1187:                    String workItemId, String attrName, int attrType,
1188:                    Object attrValue) throws WMWorkflowException {
1189:
1190:                WMAttribute attr = _client.getWorkItemAttributeValue(
1191:                        processInstanceId, workItemId, attrName);
1192:                assertEquals("Work item '" + workItemId + "' attribute '"
1193:                        + attrName + "' type is wrong;", attrType, attr
1194:                        .getType());
1195:                assertEquals("Work item attribute '" + attrName
1196:                        + "' value is wrong;", attrValue, attr.getValue());
1197:            }
1198:
1199:            private void checkNoProcessInstance(String procInstId) {
1200:                try {
1201:                    _client.getProcessInstance(procInstId);
1202:                    fail("getProcessInstance did not throw exception for invalid processInstanceId: "
1203:                            + procInstId);
1204:                } catch (WMWorkflowException e) {
1205:                    assertEquals("NoMoreData exception is wrong;",
1206:                            WMError.WM_INVALID_PROCESS_INSTANCE, e.getError()
1207:                                    .getMainCode());
1208:                }
1209:            }
1210:
1211:            private void checkPackageId(String pkgId, String content)
1212:                    throws XPDLParserException, IOException {
1213:
1214:                XPDLPackage pkg = readPackage(content);
1215:                assertEquals("Package ID is wrong;", pkgId, pkg.getId());
1216:            }
1217:
1218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.