001: package org.emforge.jbpm;
002:
003: import static org.junit.Assert.assertEquals;
004: import static org.junit.Assert.assertFalse;
005: import static org.junit.Assert.assertNotNull;
006: import static org.junit.Assert.assertTrue;
007: import static org.junit.Assert.fail;
008:
009: import java.io.IOException;
010: import java.io.InputStream;
011: import java.util.Date;
012: import java.util.List;
013:
014: import org.acegisecurity.AccessDeniedException;
015: import org.acegisecurity.providers.encoding.PasswordEncoder;
016: import org.acegisecurity.userdetails.UserDetails;
017: import org.acegisecurity.userdetails.UsernameNotFoundException;
018: import org.apache.commons.io.IOUtils;
019: import org.apache.commons.lang.StringUtils;
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.emforge.BpmService;
023: import org.emforge.EmForgeException;
024: import org.emforge.projectmanager.ProjectService;
025: import org.emforge.projectmanager.base.MilestoneDO;
026: import org.emforge.projectmanager.base.ProjectDO;
027: import org.emforge.tests.BaseUnitTest;
028: import org.emforge.xfer.CommentTO;
029: import org.emforge.xfer.HistoryTO;
030: import org.emforge.xfer.PriorityTO;
031: import org.emforge.xfer.SelectValueTO;
032: import org.emforge.xfer.StepTO;
033: import org.emforge.xfer.TaskTO;
034: import org.emforge.xfer.TransitionTO;
035: import org.emforge.xfer.VariableTO;
036: import org.emforge.xfer.WorkflowTO;
037: import org.junit.After;
038: import org.junit.Before;
039: import org.junit.Test;
040: import org.springframework.beans.factory.annotation.Autowired;
041: import org.springframework.test.context.transaction.AfterTransaction;
042:
043: import ru.emdev.EmForge.security.dao.Role;
044: import ru.emdev.EmForge.security.dao.User;
045: import ru.emdev.EmForge.security.dao.UserDao;
046:
047: /** Unit Test for testing BPM Service functionality
048: *
049: */
050: public class BpmServiceTest extends BaseUnitTest {
051: private static final String PROJECT_NAME = "Project1";
052:
053: private final Log log = LogFactory.getLog(getClass());
054:
055: @Autowired
056: private BpmService bpmService;
057: @Autowired
058: private ProjectService projectService;
059: @Autowired
060: private PasswordEncoder passwordEncoder;
061: @Autowired
062: private UserDao userDao;
063:
064: private WorkflowTO testWorkflow;
065:
066: @Before
067: public void initData() throws Exception {
068: // make authentication - authenticate as admin user
069: authenticateUser("admin", "admin");
070:
071: initWorkflow();
072:
073: // create project
074: ProjectDO project1 = new ProjectDO();
075: project1.setName(PROJECT_NAME);
076: projectService.saveProject(project1);
077:
078: MilestoneDO milestone1 = new MilestoneDO();
079: milestone1.setProject(project1);
080: milestone1.setName("Milestone1");
081: milestone1.setDisplayName("Milestone 1");
082:
083: MilestoneDO milestone2 = new MilestoneDO();
084: milestone2.setProject(project1);
085: milestone2.setName("Milestone2");
086: milestone2.setDisplayName("Milestone 2");
087:
088: // create 2 new milestones
089: projectService.saveMilestone(milestone1);
090: projectService.saveMilestone(milestone2);
091:
092: // create developers
093: User developer1 = new User();
094: developer1.setUsername("developer1");
095: developer1.setPassword(passwordEncoder.encodePassword(
096: "somepass2", ""));
097: developer1.setEmail("dbuser2@test.com");
098: developer1.setFirstName("Test2");
099: developer1.setLastName("User");
100: developer1.setActive(true);
101: userDao.saveUser(developer1);
102:
103: User developer2 = new User();
104: developer2.setUsername("developer2");
105: developer2.setPassword(passwordEncoder.encodePassword(
106: "somepass2", ""));
107: developer2.setEmail("dbuser2@test.com");
108: developer2.setFirstName("Test2");
109: developer2.setLastName("User");
110: developer2.setActive(true);
111: userDao.saveUser(developer2);
112:
113: // assign developer role for them
114: Role roleDeveloper = userDao
115: .getRoleByName(ProjectService.ROLE_DEVELOPER);
116: projectService.addUser(project1, developer1, roleDeveloper);
117: projectService.addUser(project1, developer2, roleDeveloper);
118: }
119:
120: /** Since this method used transactional Service we cannot put it into @Before
121: * As far as changes done here will not be rolled-back
122: *
123: * @throws IOException
124: * @throws EmForgeException
125: */
126: protected void initWorkflow() throws Exception {
127: // now, we need to deploy workflow
128: InputStream is = this .getClass().getClassLoader()
129: .getResourceAsStream("processes/TestFixABug.par");
130:
131: // read into byte array
132: byte[] workflowContent = IOUtils.toByteArray(is);
133:
134: // deploy it into bmpService
135: testWorkflow = bpmService.addNewWorkflow(workflowContent,
136: "Workflow Deployed in unit-test");
137:
138: // deploy it twice - so, we will able to check history
139: testWorkflow = bpmService.addNewWorkflow(workflowContent,
140: "Final version of workflow");
141:
142: // second workflow required for correctly starting subprocess
143: is = this .getClass().getClassLoader().getResourceAsStream(
144: "processes/ImplementAFeature.par");
145:
146: // read into byte array
147: workflowContent = IOUtils.toByteArray(is);
148:
149: // deploy it into bmpService
150: WorkflowTO implementAFeatureWorkflow = bpmService
151: .addNewWorkflow(workflowContent,
152: "Workflow Deployed in unit-test");
153: assertNotNull(implementAFeatureWorkflow);
154: }
155:
156: /** Check how transactions is working
157: * Inside transation we should have user 'developer1'
158: */
159: @After
160: public void afterInTransaction() {
161: UserDetails user = userDao.loadUserByUsername("developer1");
162: assertNotNull(user);
163:
164: try {
165: List<StepTO> steps = bpmService.getActiveSteps(null);
166: assertNotNull(steps);
167: if (steps.size() > 0) {
168: assertTrue(true);
169: }
170: } catch (EmForgeException ex) {
171: // ignore it
172: }
173: }
174:
175: /** Check how transactions is working
176: * But outsie transaction we should have no any user
177: */
178: @AfterTransaction
179: public void afterTransaction() {
180: // check that we do not have users
181: boolean errorHappens = false;
182: try {
183: userDao.loadUserByUsername("developer1");
184: } catch (UsernameNotFoundException ex) {
185: errorHappens = true;
186: }
187:
188: assertTrue(errorHappens);
189:
190: try {
191: List<StepTO> steps = bpmService.getActiveSteps(null);
192: assertNotNull(steps);
193: } catch (EmForgeException ex) {
194: // ignore it
195: }
196: }
197:
198: @Test
199: public void testGetActiveSteps() throws EmForgeException {
200: List<StepTO> steps = bpmService.getActiveSteps(null);
201: assertNotNull(steps);
202:
203: // list all tasks
204: for (int i = 0; i < steps.size(); i++) {
205: StepTO step = steps.get(i);
206: log.info("Step #" + step.getId() + " : " + step.getTitle());
207: }
208: }
209:
210: @Test
211: public void testGetWorkflow() throws EmForgeException {
212: // try to get by name and version
213: WorkflowTO workflow = bpmService.getWorkflowByName(testWorkflow
214: .getName(), testWorkflow.getVersion());
215: assertNotNull(workflow);
216: assertEquals(testWorkflow.getId(), workflow.getId());
217:
218: // try to get by id
219: workflow = bpmService.getWorkflowById(testWorkflow.getId());
220: assertNotNull(workflow);
221: assertEquals(testWorkflow.getId(), workflow.getId());
222: assertEquals(testWorkflow.getName(), workflow.getName());
223: assertEquals(testWorkflow.getVersion(), workflow.getVersion());
224:
225: }
226:
227: @Test
228: public void testGetWorkflows() throws EmForgeException {
229: WorkflowTO[] workflows = bpmService.getWorkflows();
230: assertNotNull(workflows);
231: assertEquals(2, workflows.length);
232:
233: for (WorkflowTO workflow : workflows) {
234: log.info("Workflow #" + workflow.getId() + " : "
235: + workflow.getName() + "(" + workflow.getVersion()
236: + ") - " + workflow.getStartName());
237: }
238: }
239:
240: /** Test to check values, returned for start step */
241: @Test
242: public void testStartStep() throws EmForgeException {
243: StepTO startStep = bpmService.getWorkflowStartStep(testWorkflow
244: .getName(), testWorkflow.getVersion(), PROJECT_NAME);
245: assertNotNull(startStep);
246: VariableTO[] startVars = startStep.getWritableVariables();
247:
248: assertNotNull(startVars);
249: assertEquals(4, startVars.length);
250:
251: // check them
252: boolean foundAssignToDevelopers = false;
253: boolean foundMilestone = false;
254: boolean foundVersion = false;
255: boolean foundSite = false;
256:
257: for (VariableTO var : startVars) {
258: if ("AssignTo_Developer".equals(var.getLabel())) {
259: foundAssignToDevelopers = true;
260:
261: // get possible values:
262: assertNotNull(var.getSelectValues());
263: // should be 2 developers plus 1 entry for "Any Developer"
264: assertEquals(3, var.getSelectValues().length);
265:
266: // first entry in seelct values should be "Any Developer"
267: // role name (Developer) used as value
268: assertEquals("Developer", var.getSelectValues()[0]
269: .getValue());
270:
271: boolean foundDeveloper1 = false;
272: boolean foundDeveloper2 = false;
273:
274: for (SelectValueTO selectValue : var.getSelectValues()) {
275: if ("developer1".equals(selectValue.getValue())) {
276: foundDeveloper1 = true;
277: } else if ("developer2".equals(selectValue
278: .getValue())) {
279: foundDeveloper2 = true;
280: }
281: }
282:
283: assertTrue(foundDeveloper1);
284: assertTrue(foundDeveloper2);
285: } else if (BpmVariable.MILESTONE.getVariable().equals(
286: var.getLabel())) {
287: foundMilestone = true;
288:
289: // get possible values:
290: assertNotNull(var.getSelectValues());
291: // should be 2 milestones plus default empty value
292: assertEquals(3, var.getSelectValues().length);
293:
294: assertEquals("", var.getSelectValues()[0].getValue());
295:
296: boolean foundMilestone1 = false;
297: boolean foundMilestone2 = false;
298:
299: for (SelectValueTO selectValue : var.getSelectValues()) {
300: if ("Milestone1".equals(selectValue.getValue())) {
301: foundMilestone1 = true;
302: } else if ("Milestone2".equals(selectValue
303: .getValue())) {
304: foundMilestone2 = true;
305: }
306: }
307:
308: assertTrue(foundMilestone1);
309: assertTrue(foundMilestone2);
310: } else if ("Version".equals(var.getLabel())) {
311: foundVersion = true;
312: } else if ("Site".equals(var.getLabel())) {
313: foundSite = true;
314: }
315: }
316:
317: assertTrue(foundAssignToDevelopers);
318: assertTrue(foundMilestone);
319: assertTrue(foundVersion);
320: assertTrue(foundSite);
321:
322: // now, check transitions
323: assertNotNull(startStep.getTransitions());
324: assertEquals(2, startStep.getTransitions().length);
325:
326: boolean foundDefaultTransition = false;
327: boolean foundCheckTheBug = false;
328:
329: for (TransitionTO transition : startStep.getTransitions()) {
330: if (StringUtils.isEmpty(transition.getName())) {
331: foundDefaultTransition = true;
332: assertEquals("Test Report Bug (go to \"Fix Bug\")",
333: transition.getLabel());
334: } else if ("Check the bug".equals(transition.getName())) {
335: foundCheckTheBug = true;
336: }
337: }
338:
339: assertTrue(foundDefaultTransition);
340: assertTrue(foundCheckTheBug);
341: }
342:
343: /** Test for starting new task
344: *
345: */
346: @Test
347: public void testStartTask() throws EmForgeException {
348: Date dueDate = new Date();
349: String title = "This is test task 1";
350: PriorityTO priority = PriorityTO.ASAP;
351:
352: TaskTO newTask = startNewTask(title, dueDate, priority);
353:
354: // ok - now, check the passed variables
355: assertEquals(title, newTask.getTitle());
356: assertEquals(priority, newTask.getPriority());
357: assertEquals(dueDate, newTask.getDueDate());
358:
359: // check variables
360: boolean foundAssignToDevelopers = false;
361: boolean foundMilestone = false;
362: boolean foundVersion = false;
363: boolean foundSite = false;
364:
365: for (VariableTO var : newTask.getVariables()) {
366: if ("AssignTo_Developer".equals(var.getLabel())) {
367: foundAssignToDevelopers = true;
368: assertEquals("developer2", var.getValue());
369: } else if (BpmVariable.MILESTONE.getVariable().equals(
370: var.getLabel())) {
371: foundMilestone = true;
372: } else if ("Version".equals(var.getLabel())) {
373: foundVersion = true;
374: assertEquals("Product 1.1", var.getValue());
375: } else if ("Site".equals(var.getLabel())) {
376: foundSite = true;
377: assertEquals("http://www.emforge.org", var.getValue());
378: }
379: }
380:
381: assertTrue(foundAssignToDevelopers);
382: assertTrue(foundVersion);
383: assertTrue(foundSite);
384:
385: // check project
386: assertEquals(PROJECT_NAME, newTask.getProjectName());
387:
388: // check milestone - it should not be listed in variables
389: assertFalse(foundMilestone);
390: // since it is accessible via separate accessor
391: assertEquals("Milestone2", newTask.getMilestoneName());
392:
393: // now, check blocking steps - it should be Fix Bug
394: StepTO[] blockingSteps = bpmService.getBlockingSteps(newTask
395: .getId());
396: assertNotNull(blockingSteps);
397: assertEquals(1, blockingSteps.length);
398:
399: StepTO blockingStep = blockingSteps[0];
400: assertEquals("Check the bug", blockingStep.getName());
401: assertEquals(title, blockingStep.getTitle());
402: assertEquals(priority, blockingStep.getPriority());
403: }
404:
405: protected TaskTO startNewTask() throws EmForgeException {
406: Date dueDate = new Date();
407: String title = "This is test task 1";
408: PriorityTO priority = PriorityTO.ASAP;
409:
410: return startNewTask(title, dueDate, priority);
411:
412: }
413:
414: protected TaskTO startNewTask(String title, Date dueDate,
415: PriorityTO priority) throws EmForgeException {
416: StepTO startStep = bpmService.getWorkflowStartStep(testWorkflow
417: .getName(), testWorkflow.getVersion(), PROJECT_NAME);
418:
419: // set common values
420: startStep.setTitle(title);
421: startStep.setPriority(priority);
422: startStep.setDueDate(dueDate);
423:
424: // set required variables
425: VariableTO stepVar = startStep
426: .getVariable("AssignTo_Developer");
427: stepVar.setValue("developer2");
428:
429: stepVar = startStep.getVariable(BpmVariable.MILESTONE
430: .getVariable());
431: stepVar.setValue("Milestone2");
432:
433: stepVar = startStep.getVariable("Version");
434: stepVar.setValue("Product 1.1");
435:
436: stepVar = startStep.getVariable("Site");
437: stepVar.setValue("http://www.emforge.org");
438:
439: // start new task!
440: TaskTO newTask = bpmService.startTask(startStep, null, null);
441: assertNotNull(newTask);
442:
443: return newTask;
444: }
445:
446: /** If we trying start task with empty title - we should get EmForge exception!
447: *
448: */
449: @Test
450: public void testEmptyTitle() throws EmForgeException {
451: StepTO startStep = bpmService.getWorkflowStartStep(testWorkflow
452: .getName(), testWorkflow.getVersion(), PROJECT_NAME);
453: assertNotNull(startStep);
454:
455: try {
456: bpmService.startTask(startStep, null, null);
457: } catch (EmForgeException ex) {
458: // it is ok - we should be here
459: return;
460: }
461:
462: fail("EmForgeEception is expected");
463: }
464:
465: /** Test for not-specified variable
466: * Milestone is required - if we will not specify milestone - it should produce exception
467: */
468: @Test
469: public void testEmptyMilestone() throws EmForgeException {
470: StepTO startStep = bpmService.getWorkflowStartStep(testWorkflow
471: .getName(), testWorkflow.getVersion(), PROJECT_NAME);
472: assertNotNull(startStep);
473:
474: Date dueDate = new Date();
475: String title = "This is test task 1";
476: PriorityTO priority = PriorityTO.ASAP;
477:
478: // set common values
479: startStep.setTitle(title);
480: startStep.setPriority(priority);
481: startStep.setDueDate(dueDate);
482:
483: // set required variables
484: VariableTO stepVar = startStep
485: .getVariable("AssignTo_Developer");
486: stepVar.setValue("developer2");
487:
488: stepVar = startStep.getVariable("Version");
489: stepVar.setValue("Product 1.1");
490:
491: stepVar = startStep.getVariable("Site");
492: stepVar.setValue("http://www.emforge.org");
493:
494: // start new task!
495: try {
496: bpmService.startTask(startStep, null, null);
497: } catch (EmForgeException ex) {
498: // it is ok - it should produce exception
499: return;
500: }
501:
502: fail("Exception about missed variable should be produced");
503: }
504:
505: /** Test for incorrect user.
506: * Lets try to set not-allowed user into "AssignTo_Developer" variable
507: * bpmService should check, that incorrect value tryed to be set and throws Error
508: */
509: @Test
510: public void testIncorrectVarValue() throws EmForgeException {
511: StepTO startStep = bpmService.getWorkflowStartStep(testWorkflow
512: .getName(), testWorkflow.getVersion(), PROJECT_NAME);
513: assertNotNull(startStep);
514:
515: Date dueDate = new Date();
516: String title = "This is test task 1";
517: PriorityTO priority = PriorityTO.ASAP;
518:
519: // set common values
520: startStep.setTitle(title);
521: startStep.setPriority(priority);
522: startStep.setDueDate(dueDate);
523:
524: // set required variables
525: VariableTO stepVar = startStep
526: .getVariable("AssignTo_Developer");
527: // !!! We are setting here incorrect user-name - this user has no Developer role
528: stepVar.setValue("admin");
529:
530: stepVar = startStep.getVariable(BpmVariable.MILESTONE
531: .getVariable());
532: stepVar.setValue("Milestone2");
533:
534: stepVar = startStep.getVariable("Version");
535: stepVar.setValue("Product 1.1");
536:
537: stepVar = startStep.getVariable("Site");
538: stepVar.setValue("http://www.emforge.org");
539:
540: // start new task!
541: try {
542: bpmService.startTask(startStep, null, null);
543: } catch (EmForgeException ex) {
544: // it is ok - it should produce exception
545: return;
546: }
547:
548: fail("Exception about incorrect value should be produced");
549: }
550:
551: @Test
552: public void testStopTask() throws EmForgeException {
553: TaskTO newTask = startNewTask();
554:
555: // try to stop this task
556: Boolean stopResult = bpmService.stopTask(newTask.getId(),
557: "Try to stop correct task");
558: assertTrue(stopResult);
559:
560: // try to stop this task once again
561: Boolean exceptionFound = false;
562: try {
563: stopResult = bpmService.stopTask(newTask.getId(),
564: "Try to stop correct task again");
565: } catch (EmForgeException ex) {
566: exceptionFound = true;
567: } catch (AccessDeniedException ex) {
568: exceptionFound = true;
569: }
570:
571: assertTrue(exceptionFound);
572:
573: // try to stop not existed task
574: try {
575: stopResult = bpmService.stopTask(-999,
576: "Try to stop correct task again");
577: } catch (EmForgeException ex) {
578: return;
579: } catch (AccessDeniedException ex) {
580: return;
581: }
582:
583: fail("Exception should be thrown");
584: }
585:
586: @Test
587: public void testCompleteStep() throws EmForgeException {
588: TaskTO newTask = startNewTask();
589:
590: // get blocking step
591: StepTO[] blockingSteps = bpmService.getBlockingSteps(newTask
592: .getId());
593: assertNotNull(blockingSteps);
594: assertEquals(1, blockingSteps.length);
595:
596: StepTO blockingStep = blockingSteps[0];
597: assertEquals("Check the bug", blockingStep.getName());
598:
599: // now, complete it:
600: newTask = bpmService.completeStep(blockingStep,
601: "Yes, it is a bug", "This is a very bad bug!");
602: assertNotNull(newTask);
603:
604: // check new blocking steps
605: blockingSteps = bpmService.getBlockingSteps(newTask.getId());
606: assertNotNull(blockingSteps);
607: assertEquals(1, blockingSteps.length);
608:
609: blockingStep = blockingSteps[0];
610: assertEquals("Assign Bug to Milestone", blockingStep.getName());
611:
612: // try to clear milestone assignment
613: VariableTO milestoneVar = blockingStep
614: .getVariable(BpmVariable.MILESTONE.getVariable());
615: milestoneVar.setValue("");
616:
617: // try to complete this step
618: boolean exceptionFound = false;
619: try {
620: newTask = bpmService.completeStep(blockingStep, "",
621: "Try to assign it to incorrect milestone");
622: } catch (EmForgeException ex) {
623: // ok, nice, exception happens
624: exceptionFound = true;
625: }
626: assertTrue(exceptionFound);
627:
628: // ok, now change milestone and try to complete the task:
629: milestoneVar.setValue("Milestone1");
630: newTask = bpmService.completeStep(blockingStep, "",
631: "Now everything should be ok");
632: assertNotNull(newTask);
633:
634: // check new blocking step
635: blockingSteps = bpmService.getBlockingSteps(newTask.getId());
636: assertNotNull(blockingSteps);
637: assertEquals(1, blockingSteps.length);
638:
639: blockingStep = blockingSteps[0];
640: assertEquals("Assign Bug", blockingStep.getName());
641:
642: // check milestone variable:
643: assertEquals("Milestone1", blockingStep.getMilestoneName());
644:
645: // check task history
646: HistoryTO[] history = bpmService
647: .getTaskHistory(newTask.getId());
648: assertNotNull(history);
649: assertTrue(history.length > 0);
650:
651: }
652:
653: /** Test working with subtasks */
654: @Test
655: public void testSubTasks() throws EmForgeException {
656: TaskTO newTask = startNewTask();
657:
658: // get blocking step
659: StepTO[] blockingSteps = bpmService.getBlockingSteps(newTask
660: .getId());
661: assertNotNull(blockingSteps);
662: assertEquals(1, blockingSteps.length);
663:
664: StepTO blockingStep = blockingSteps[0];
665: assertEquals("Check the bug", blockingStep.getName());
666:
667: // create subprocess for it
668: StepTO dynStartStep = bpmService.getWorkflowStartStep(
669: "ImplementAFeature", 1, PROJECT_NAME);
670: dynStartStep.setTitle("Dynamic Sub task");
671: TaskTO dynSubTask = bpmService.startSubTask(blockingStep
672: .getId(), dynStartStep, null, null);
673: assertNotNull(dynSubTask);
674:
675: // check subtasks - they should be 1
676: TaskTO[] subTasks = bpmService.getBlockingSubTasks(newTask
677: .getId());
678: assertNotNull(subTasks);
679: assertEquals(1, subTasks.length);
680:
681: // go to the feature step:
682: newTask = bpmService.completeStep(blockingStep,
683: "It's a feature", "It is not a bug - it is a feature!");
684: assertNotNull(newTask);
685:
686: // check new blocking steps - seems we go throw state without stopping in it
687: blockingSteps = bpmService.getBlockingSteps(newTask.getId());
688: assertNotNull(blockingSteps);
689: assertEquals(0, blockingSteps.length);
690:
691: // now, our task should have 2 subprocess:
692: subTasks = bpmService.getBlockingSubTasks(newTask.getId());
693: assertNotNull(subTasks);
694: assertEquals(2, subTasks.length);
695:
696: // we should have 3 blockers
697: assertNotNull(newTask.getBlockers());
698: assertEquals(2, newTask.getBlockers().length);
699:
700: //lets try to stop it
701: bpmService.stopTask(subTasks[0].getId(),
702: "Lets try to stop subprocess");
703:
704: // now we should have 1 blocking subtasks
705: subTasks = bpmService.getBlockingSubTasks(newTask.getId());
706: assertNotNull(subTasks);
707: assertEquals(1, subTasks.length);
708:
709: // stop dynamic subtask
710: bpmService.stopTask(dynSubTask.getId(),
711: "Lets try to stop subprocess");
712:
713: // now we should have 0 blocking subtasks
714: subTasks = bpmService.getBlockingSubTasks(newTask.getId());
715: assertNotNull(subTasks);
716: assertEquals(0, subTasks.length);
717:
718: // but now we should have 1 finished subtasks
719: subTasks = bpmService.getFinishedSubTasks(newTask.getId());
720: assertNotNull(subTasks);
721: // TODO Here should be 2!!!
722: assertEquals(1, subTasks.length);
723: }
724:
725: @Test
726: public void testWorkflowHistory() throws Exception {
727: HistoryTO[] history = bpmService.getWorkflowHistory(
728: testWorkflow.getName(), testWorkflow.getVersion());
729: assertNotNull(history);
730:
731: //!!! This is commented due to probolem with transactions.
732: // Deploying of new process is not rolled-back at the end of test.
733: // As result we have here history size 26 - not 2.
734: // It is caused setting Transactional property for BpmService
735: //assertEquals(2, history.length);
736:
737: for (HistoryTO historyItem : history) {
738: assertNotNull(historyItem.getActor());
739: assertNotNull(historyItem.getDate());
740: assertNotNull(historyItem.getMessage());
741: assertNotNull(historyItem.getComment());
742: assertNotNull(historyItem.getLink());
743: }
744: }
745:
746: @Test
747: public void testUsedWorkflows() throws Exception {
748: WorkflowTO[] workflows = bpmService.getUsedWorkflows(
749: testWorkflow.getName(), testWorkflow.getVersion());
750: assertNotNull(workflows);
751: assertEquals(1, workflows.length);
752: assertEquals("ImplementAFeature", workflows[0].getName());
753: }
754:
755: @Test
756: public void testTransactions() throws Exception {
757: TaskTO newTask = startNewTask();
758:
759: // check comments
760: CommentTO[] comments = bpmService.getTaskComments(newTask
761: .getId());
762: assertNotNull(comments);
763: assertEquals(0, comments.length);
764:
765: // complete step
766: // get blocking step
767: StepTO[] blockingSteps = bpmService.getBlockingSteps(newTask
768: .getId());
769: assertNotNull(blockingSteps);
770: assertEquals(1, blockingSteps.length);
771:
772: StepTO blockingStep = blockingSteps[0];
773: assertEquals("Check the bug", blockingStep.getName());
774:
775: // now, complete it with incorrect transition
776: Boolean errorFound = false;
777: try {
778: newTask = bpmService.completeStep(blockingStep,
779: "Incorrect Transition", "This is a very bad bug!");
780: } catch (EmForgeException ex) {
781: errorFound = true;
782: }
783: assertTrue(errorFound);
784:
785: // check comments
786: comments = bpmService.getTaskComments(newTask.getId());
787: assertNotNull(comments);
788: // we should have no comments - since completing was failed
789: assertEquals(0, comments.length);
790: }
791: }
|