Ejemplo n.º 1
0
  @Test
  public void testOrDecisions() {
    final WorkflowAction action1 = getAction(ACTIONCODES.ACTION1.name());
    final WorkflowAction action2 = getAction(ACTIONCODES.ACTION2.name());
    final WorkflowAction action3 = getAction(ACTIONCODES.ACTION3.name());
    final WorkflowAction action4 = getAction(ACTIONCODES.ACTION4.name());
    final WorkflowAction action5 = getAction(ACTIONCODES.ACTION5.name());
    final WorkflowAction action6 = getAction(ACTIONCODES.ACTION6.name());

    // complete action 1 with decision 2
    final WorkflowDecision decision2 = getDecision(DECISIONCODES.DECISION2.name(), action1);
    action1.setSelectedDecision(decision2);
    action1.decide();

    assertTrue("Action 1 should be completed", action1.isCompleted());
    assertTrue("Action 2 should be active", action2.isActive());
    assertFalse("Action 3 should be inactive", action3.isActive());
    assertTrue("Action 4 should be active", action4.isActive());
    assertFalse("Action 5 should be inactive", action5.isActive());
    assertFalse("Action 6 should be inactive", action6.isActive());

    // complete action 2 with decision 4
    final WorkflowDecision decision4 = getDecision(DECISIONCODES.DECISION4.name(), action2);
    action2.setSelectedDecision(decision4);
    action2.decide();

    assertTrue("Action 1 should be completed", action1.isCompleted());
    assertTrue("Action 2 should be completed", action2.isCompleted());
    assertFalse("Action 3 should be inactive", action3.isActive());
    assertTrue("Action 4 should be active", action4.isActive());
    assertTrue("Action 5 should be active", action5.isActive());
    assertFalse("Action 6 should be inactive", action6.isActive());
  }
  @Test
  public void testOrDecisions() {
    final WorkflowActionModel action1 = getAction(ACTIONCODES.ACTION1.name());
    final WorkflowActionModel action2 = getAction(ACTIONCODES.ACTION2.name());
    final WorkflowActionModel action3 = getAction(ACTIONCODES.ACTION3.name());
    final WorkflowActionModel action4 = getAction(ACTIONCODES.ACTION4.name());
    final WorkflowActionModel action5 = getAction(ACTIONCODES.ACTION5.name());
    final WorkflowActionModel action6 = getAction(ACTIONCODES.ACTION6.name());

    // complete action 1 with decision 2
    final WorkflowDecisionModel decision2 = getDecision(DECISIONCODES.DECISION2.name(), action1);
    workflowProcessingService.decideAction(action1, decision2);

    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertTrue("Action 2 should be active", workflowActionService.isActive(action2));
    assertFalse("Action 3 should be inactive", workflowActionService.isActive(action3));
    assertTrue("Action 4 should be active", workflowActionService.isActive(action4));
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));
    assertFalse("Action 6 should be inactive", workflowActionService.isActive(action6));

    // complete action 2 with decision 4
    final WorkflowDecisionModel decision4 = getDecision(DECISIONCODES.DECISION4.name(), action2);
    workflowProcessingService.decideAction(action2, decision4);

    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
    assertFalse("Action 3 should be inactive", workflowActionService.isActive(action3));
    assertTrue("Action 4 should be active", workflowActionService.isActive(action4));
    assertTrue("Action 5 should be active", workflowActionService.isActive(action5));
    assertFalse("Action 6 should be inactive", workflowActionService.isActive(action6));
  }
  /** Creates some attachments and assigns them to the test workflow. */
  @Test
  public void testAttachments() {
    final CatalogVersionModel testCv =
        catalogVersionService.getCatalogVersion("DefaultTestCatalog", "Online");
    assertNotNull(testCv);

    final PK workflowPk = testWorkflow.getPk();
    // create product attachment
    final ProductModel product = modelService.create(ProductModel.class);
    product.setCode("abc");

    product.setCatalogVersion(testCv);

    modelService.save(product);
    assertNotNull("Product not null", product);

    final WorkflowItemAttachmentModel attachProduct =
        createAttachment("productTest", product, testWorkflow);
    assertNotNull("Attachment not null", attachProduct);

    // create category attachment
    final CategoryModel category = modelService.create(CategoryModel.class);
    category.setCode("abc");
    category.setCatalogVersion(testCv);
    assertNotNull("Category not null", category);

    final WorkflowItemAttachmentModel attachCategory =
        createAttachment("categoryTest", category, testWorkflow);
    assertNotNull("Attachment not null", attachCategory);

    final WorkflowActionModel action1 = getAction(ACTIONCODES.ACTION1.name());
    action1.setAttachments(
        Arrays.asList(new WorkflowItemAttachmentModel[] {attachProduct, attachCategory}));

    clearCache();

    // check attachments
    final WorkflowModel found = modelService.get(workflowPk);
    assertEquals("Excpected number of attachments", 2, found.getAttachments().size());
    final WorkflowActionModel foundAction = getAction(ACTIONCODES.ACTION1.name());
    assertEquals(
        "Excpected number of attachments of action 1", 2, foundAction.getAttachments().size());
  }
Ejemplo n.º 4
0
  /** Creates some attachments and assigns them to the test workflow. */
  @Test
  public void testAttachments() {
    final PK workflowPk = testWorkflow.getPK();
    // create product attachment
    final Product product = jaloSession.getProductManager().createProduct("sabbers");
    assertNotNull("Product not null", product);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(WorkflowItemAttachment.CODE, "productTest");
    map.put(WorkflowItemAttachment.ITEM, product);
    map.put(WorkflowItemAttachment.WORKFLOW, testWorkflow);
    final WorkflowItemAttachment attachProduct =
        WorkflowManager.getInstance().createWorkflowItemAttachment(map);
    assertNotNull("Attachment not null", attachProduct);

    // create category attachment
    final Category category =
        CategoryManager.getInstance().createCategory(PK.createUUIDPK(0).getHex());
    assertNotNull("Category not null", category);
    map = new HashMap<String, Object>();
    map.put(WorkflowItemAttachment.CODE, "categoryTest");
    map.put(WorkflowItemAttachment.ITEM, category);
    map.put(WorkflowItemAttachment.WORKFLOW, testWorkflow);
    final WorkflowItemAttachment attachCategory =
        WorkflowManager.getInstance().createWorkflowItemAttachment(map);
    assertNotNull("Attachment not null", attachCategory);

    final WorkflowAction action1 = getAction(ACTIONCODES.ACTION1.name());
    action1.setAttachments(
        Arrays.asList(new WorkflowItemAttachment[] {attachProduct, attachCategory}));

    // restart
    Registry.getCurrentTenant().getCache();

    // check attachments
    final Workflow found = JaloSession.getCurrentSession().getItem(workflowPk);
    assertEquals("Excpected number of attachments", 2, found.getAttachments().size());
    final WorkflowAction foundAction = getAction(ACTIONCODES.ACTION1.name());
    assertEquals(
        "Excpected number of attachments of action 1", 2, foundAction.getAttachments().size());
  }
Ejemplo n.º 5
0
  /** tries to complete a action with the wrong user */
  @Test(expected = WorkflowActionDecideException.class)
  public void testAssignedUserDecide() {
    final User testUser1 = createUser("TestUser1");
    jaloSession.setUser(testUser1);

    // complete action 1 with decision 1
    final WorkflowAction action1 = getAction(ACTIONCODES.ACTION1.name());
    assertTrue("Action 1 should be active", action1.isActive());
    final WorkflowDecision decision1 = getDecision(DECISIONCODES.DECISION1.name(), action1);
    action1.setSelectedDecision(decision1);
    action1.decide();
    fail("The user can not decide an action he is not assigned to");
  }
  /** tries to complete a action with the wrong user */
  @Test(expected = WorkflowActionDecideException.class)
  public void testAssignedUserDecide() {
    final UserModel testUser1 = createUser("TestUser1");
    userService.setCurrentUser(testUser1);

    // complete action 1 with decision 1
    final WorkflowActionModel action1 = getAction(ACTIONCODES.ACTION1.name());
    assertTrue("Action 1 should be active", workflowActionService.isActive(action1));
    final WorkflowDecisionModel decision1 = getDecision(DECISIONCODES.DECISION1.name(), action1);
    action1.setSelectedDecision(decision1);
    workflowProcessingService.decideAction(action1, decision1);
    fail("The user can not decide an action he is not assigned to");
  }
  /**
   * Creates a workflow template with given user assigned.
   *
   * @param user user instance to use for template
   * @return new created template instance
   */
  @Override
  protected WorkflowTemplateModel createWorkflowTemplate(final UserModel user) {
    final WorkflowTemplateModel template =
        createWorkflowTemplate(user, "Test Template", "Test Template Descr");
    final WorkflowActionTemplateModel templateAction1 =
        createWorkflowActionTemplateModel(
            user, ACTIONCODES.ACTION1.name(), WorkflowActionType.START, template);
    final WorkflowActionTemplateModel templateAction2 =
        createWorkflowActionTemplateModel(
            user, ACTIONCODES.ACTION2.name(), WorkflowActionType.NORMAL, template);
    final WorkflowActionTemplateModel templateAction3 =
        createWorkflowActionTemplateModel(
            user, ACTIONCODES.ACTION3.name(), WorkflowActionType.NORMAL, template);
    final WorkflowActionTemplateModel templateAction4 =
        createWorkflowActionTemplateModel(
            user, ACTIONCODES.ACTION4.name(), WorkflowActionType.NORMAL, template);
    final WorkflowActionTemplateModel templateAction5 =
        createWorkflowActionTemplateModel(
            user, ACTIONCODES.ACTION5.name(), WorkflowActionType.END, template);

    final WorkflowDecisionTemplateModel templateDecision1 =
        createWorkflowDecisionTemplate(DECISIONCODES.DECISION1.name(), templateAction1);
    final WorkflowDecisionTemplateModel templateDecision2 =
        createWorkflowDecisionTemplate(DECISIONCODES.DECISION2.name(), templateAction2);
    final WorkflowDecisionTemplateModel templateDecision3 =
        createWorkflowDecisionTemplate(DECISIONCODES.DECISION3.name(), templateAction3);
    final WorkflowDecisionTemplateModel templateDecision4 =
        createWorkflowDecisionTemplate(DECISIONCODES.DECISION4.name(), templateAction4);
    final WorkflowDecisionTemplateModel templateDecision5 =
        createWorkflowDecisionTemplate(DECISIONCODES.DECISION5.name(), templateAction2);

    createWorkflowActionTemplateModelLinkTemplateRelation(
        templateDecision1, templateAction2, Boolean.FALSE);
    createWorkflowActionTemplateModelLinkTemplateRelation(
        templateDecision2, templateAction3, Boolean.FALSE);
    createWorkflowActionTemplateModelLinkTemplateRelation(
        templateDecision3, templateAction4, Boolean.FALSE);
    createWorkflowActionTemplateModelLinkTemplateRelation(
        templateDecision4, templateAction1, Boolean.FALSE);
    createWorkflowActionTemplateModelLinkTemplateRelation(
        templateDecision5, templateAction5, Boolean.FALSE);

    return template;
  }
Ejemplo n.º 8
0
  /** Checks if actions of test workflow has correct status. */
  @Test
  public void testWorkflowCreate() {
    // test action 1
    final WorkflowAction action1 = getAction(ACTIONCODES.ACTION1.name());
    assertEquals("Expected number of decisions of action 1", 2, action1.getDecisionsCount());
    assertFalse("Is the action 1 disabled?", action1.isDisabled());
    assertTrue("Is the action 1 active?", action1.isActive());

    for (final WorkflowDecision decision : action1.getDecisions()) {
      assertEquals(
          "Expected number of actions of decisions of action 1", 1, decision.getToActionsCount());
    }

    // test action 2
    final WorkflowAction action2 = getAction(ACTIONCODES.ACTION2.name());
    assertEquals("Expected number of decisions of action 2", 2, action2.getDecisionsCount());
    assertFalse("Is the action 2 disabled?", action2.isDisabled());
    assertTrue("Is the action 2 active?", action2.isActive());

    for (final WorkflowDecision decision : action2.getDecisions()) {
      if (decision.getCode().equals(DECISIONCODES.DECISION4.name())) {
        assertEquals(
            "Expected number of actions of decisions of action 2", 2, decision.getToActionsCount());
      } else {
        assertEquals(
            "Expected number of actions of decisions of action 2", 1, decision.getToActionsCount());
      }
    }

    // test action 3
    final WorkflowAction action3 = getAction(ACTIONCODES.ACTION3.name());
    assertEquals("Expected number of decisions of action 3", 1, action3.getDecisionsCount());
    assertFalse("Is the action 3 disabled?", action3.isDisabled());
    assertFalse("Is the action 3 active?", action3.isActive());

    for (final WorkflowDecision decision : action3.getDecisions()) {
      assertEquals(
          "Expected number of actions of decisions of action 3", 1, decision.getToActionsCount());
    }

    // test action 4
    final WorkflowAction action4 = getAction(ACTIONCODES.ACTION4.name());
    assertEquals("Expected number of decisions of action 4", 1, action4.getDecisionsCount());
    assertFalse("Is the action 4 disabled?", action4.isDisabled());
    assertFalse("Is the action 4 active?", action4.isActive());

    for (final WorkflowDecision decision : action4.getDecisions()) {
      assertEquals(
          "Expected number of actions of decisions of action 4", 1, decision.getToActionsCount());
    }

    // test action 5
    final WorkflowAction action5 = getAction(ACTIONCODES.ACTION5.name());
    assertEquals("Expected number of decisions of action 5", 1, action5.getDecisionsCount());
    assertFalse("Is the action 5 disabled?", action5.isDisabled());
    assertFalse("Is the action 5 active?", action5.isActive());

    for (final WorkflowDecision decision : action5.getDecisions()) {
      assertEquals(
          "Expected number of actions of decisions of action 5", 1, decision.getToActionsCount());
    }

    // test action 6
    final WorkflowAction action6 = getAction(ACTIONCODES.ACTION6.name());
    assertEquals("Expected number of decisions of action 6", 0, action5.getPredecessorsCount());
    assertFalse("Is the action 6 disabled?", action6.isDisabled());
    assertFalse("Is the action 6 active?", action6.isActive());
  }
Ejemplo n.º 9
0
  /** Completes the actions of the test workflow and checks the action status and the comments. */
  @Test
  public void testWorkflowCompleteChain() {
    // complete action 1 with decision 1
    WorkflowAction action1 = getAction(ACTIONCODES.ACTION1.name());
    assertTrue("Action 1 should be active", action1.isActive());
    final WorkflowDecision decision1 = getDecision(DECISIONCODES.DECISION1.name(), action1);
    action1.setSelectedDecision(decision1);
    assertEquals("Expected number of decisions of action 1", 2, action1.getDecisionsCount());
    action1.decide();

    // test action 1
    action1 = getAction(ACTIONCODES.ACTION1.name());
    assertTrue("Action 1 should be completed", action1.isCompleted());
    assertEquals(
        "Excpected number of comments of action 1", 1, action1.getWorkflowActionComments().size());

    // test action 2
    final WorkflowAction action2 = getAction(ACTIONCODES.ACTION2.name());
    assertFalse("Action 2 should not be disabled", action2.isDisabled());
    assertFalse("Action 2 should not be completed", action2.isCompleted());
    assertTrue("Action 2 should be active", action2.isActive());
    assertEquals(
        "Excpected number of comments of action 2", 0, action2.getWorkflowActionComments().size());

    // test action 3
    final WorkflowAction action3 = getAction(ACTIONCODES.ACTION3.name());
    assertFalse("Action 3 should not be disabled", action3.isDisabled());
    assertFalse("Action 3 should not be completed", action3.isCompleted());
    assertFalse("Action 3 should be inactive", action3.isActive());
    assertEquals(
        "Excpected number of comments of action 3", 0, action3.getWorkflowActionComments().size());

    // test action 4
    final WorkflowAction action4 = getAction(ACTIONCODES.ACTION4.name());
    assertFalse("Action 4 should not be disabled", action4.isDisabled());
    assertFalse("Action 4 should not be completed", action4.isCompleted());
    assertFalse("Action 4 should be inactive", action4.isActive());
    assertEquals(
        "Excpected number of comments of action 4", 0, action4.getWorkflowActionComments().size());

    // test action 5
    final WorkflowAction action5 = getAction(ACTIONCODES.ACTION5.name());
    assertFalse("Action 5 should not be disabled", action5.isDisabled());
    assertFalse("Action 5 should not be completed", action5.isCompleted());
    assertFalse("Action 5 should be inactive", action5.isActive());
    assertEquals(
        "Excpected number of comments of action 5", 0, action5.getWorkflowActionComments().size());

    // test action 6
    final WorkflowAction action6 = getAction(ACTIONCODES.ACTION6.name());
    assertFalse("Action 6 should not be disabled", action6.isDisabled());
    assertFalse("Action 6 should not be completed", action6.isCompleted());
    assertFalse("Action 6 should be inactive", action6.isActive());
    assertEquals(
        "Excpected number of comments of action 6", 0, action6.getWorkflowActionComments().size());

    // complete action 2 with decision 3
    final WorkflowDecision decision3 = getDecision(DECISIONCODES.DECISION3.name(), action2);
    action2.setSelectedDecision(decision3);
    action2.decide();

    assertTrue("Action 1 should be completed", action1.isCompleted());
    assertEquals(
        "Excpected number of comments of action 1", 1, action1.getWorkflowActionComments().size());
    assertTrue("Action 2 should be completed", action2.isCompleted());
    assertEquals(
        "Excpected number of comments of action 2", 1, action2.getWorkflowActionComments().size());
    assertTrue("Action 3 should be active", action3.isActive());
    assertEquals(
        "Excpected number of comments of action 3", 1, action3.getWorkflowActionComments().size());
    assertFalse("Action 4 should be inactive", action4.isActive());
    assertEquals(
        "Excpected number of comments of action 4", 0, action4.getWorkflowActionComments().size());
    assertFalse("Action 5 should be inactive", action5.isActive());
    assertEquals(
        "Excpected number of comments of action 5", 0, action5.getWorkflowActionComments().size());
    assertFalse("Action 6 should be inactive", action6.isActive());
    assertEquals(
        "Excpected number of comments of action 6", 0, action6.getWorkflowActionComments().size());
    assertFalse("Workflow should not be finished", testWorkflow.isFinished());

    // complete action 3 with decision 5
    final WorkflowDecision decision5 = getDecision(DECISIONCODES.DECISION5.name(), action3);
    action3.setSelectedDecision(decision5);
    action3.decide();
    assertTrue("Action 1 should be completed", action1.isCompleted());
    assertEquals(
        "Excpected number of comments of action 1", 1, action1.getWorkflowActionComments().size());
    assertTrue("Action 2 should be completed", action2.isCompleted());
    assertEquals(
        "Excpected number of comments of action 2", 1, action2.getWorkflowActionComments().size());
    assertTrue("Action 3 should be completed", action3.isCompleted());
    assertEquals(
        "Excpected number of comments of action 3", 2, action3.getWorkflowActionComments().size());
    assertFalse("Action 4 should be inactive", action4.isActive());
    assertEquals(
        "Excpected number of comments of action 4", 0, action4.getWorkflowActionComments().size());
    assertTrue("Action 5 should be ended by workflow", action5.isEndedByWorkflow());
    assertEquals(
        "Excpected number of comments of action 5", 0, action5.getWorkflowActionComments().size());
    assertFalse("Action 6 should be inactive", action6.isActive());
    assertEquals(
        "Excpected number of comments of action 6", 1, action6.getWorkflowActionComments().size());
    assertTrue("Workflow should be finished", testWorkflow.isFinished());
  }
  /** Completes the actions of the test workflow and checks the action status and the comments. */
  @Test
  public void testWorkflowCompleteChain() {
    // complete action 1 with decision 1
    WorkflowActionModel action1 = getAction(ACTIONCODES.ACTION1.name());
    assertTrue("Action 1 should be active", workflowActionService.isActive(action1));
    final WorkflowDecisionModel decision1 = getDecision(DECISIONCODES.DECISION1.name(), action1);
    assertEquals("Expected number of decisions of action 1", 2, action1.getDecisions().size());
    workflowProcessingService.decideAction(action1, decision1);

    // test action 1
    action1 = getAction(ACTIONCODES.ACTION1.name());
    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertEquals(
        "Excpected number of comments of action 1", 1, action1.getWorkflowActionComments().size());

    // test action 2
    final WorkflowActionModel action2 = getAction(ACTIONCODES.ACTION2.name());
    assertFalse("Action 2 should not be disabled", workflowActionService.isDisabled(action2));
    assertFalse("Action 2 should not be completed", workflowActionService.isCompleted(action2));
    assertTrue("Action 2 should be active", workflowActionService.isActive(action2));
    assertEquals(
        "Excpected number of comments of action 2", 0, action2.getWorkflowActionComments().size());

    // test action 3
    final WorkflowActionModel action3 = getAction(ACTIONCODES.ACTION3.name());
    assertFalse("Action 3 should not be disabled", workflowActionService.isDisabled(action3));
    assertFalse("Action 3 should not be completed", workflowActionService.isCompleted(action3));
    assertFalse("Action 3 should be inactive", workflowActionService.isActive(action3));
    assertEquals(
        "Excpected number of comments of action 3", 0, action3.getWorkflowActionComments().size());

    // test action 4
    final WorkflowActionModel action4 = getAction(ACTIONCODES.ACTION4.name());
    assertFalse("Action 4 should not be disabled", workflowActionService.isDisabled(action4));
    assertFalse("Action 4 should not be completed", workflowActionService.isCompleted(action4));
    assertFalse("Action 4 should be inactive", workflowActionService.isActive(action4));
    assertEquals(
        "Excpected number of comments of action 4", 0, action4.getWorkflowActionComments().size());

    // test action 5
    final WorkflowActionModel action5 = getAction(ACTIONCODES.ACTION5.name());
    assertFalse("Action 5 should not be disabled", workflowActionService.isDisabled(action5));
    assertFalse("Action 5 should not be completed", workflowActionService.isCompleted(action5));
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));
    assertEquals(
        "Excpected number of comments of action 5", 0, action5.getWorkflowActionComments().size());

    // test action 6
    final WorkflowActionModel action6 = getAction(ACTIONCODES.ACTION6.name());
    assertFalse("Action 6 should not be disabled", workflowActionService.isDisabled(action6));
    assertFalse("Action 6 should not be completed", workflowActionService.isCompleted(action6));
    assertFalse("Action 6 should be inactive", workflowActionService.isActive(action6));
    assertEquals(
        "Excpected number of comments of action 6", 0, action6.getWorkflowActionComments().size());

    // complete action 2 with decision 3
    final WorkflowDecisionModel decision3 = getDecision(DECISIONCODES.DECISION3.name(), action2);
    workflowProcessingService.decideAction(action2, decision3);

    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertEquals(
        "Excpected number of comments of action 1", 1, action1.getWorkflowActionComments().size());
    assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
    assertEquals(
        "Excpected number of comments of action 2", 1, action2.getWorkflowActionComments().size());
    assertTrue("Action 3 should be active", workflowActionService.isActive(action3));
    assertEquals(
        "Excpected number of comments of action 3", 1, action3.getWorkflowActionComments().size());
    assertFalse("Action 4 should be inactive", workflowActionService.isActive(action4));
    assertEquals(
        "Excpected number of comments of action 4", 0, action4.getWorkflowActionComments().size());
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));
    assertEquals(
        "Excpected number of comments of action 5", 0, action5.getWorkflowActionComments().size());
    assertFalse("Action 6 should be inactive", workflowActionService.isActive(action6));
    assertEquals(
        "Excpected number of comments of action 6", 0, action6.getWorkflowActionComments().size());
    assertFalse("Workflow should not be finished", workflowService.isFinished(testWorkflow));

    // complete action 3 with decision 5
    final WorkflowDecisionModel decision5 = getDecision(DECISIONCODES.DECISION5.name(), action3);
    workflowProcessingService.decideAction(action3, decision5);
    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertEquals(
        "Excpected number of comments of action 1", 1, action1.getWorkflowActionComments().size());
    assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
    assertEquals(
        "Excpected number of comments of action 2", 1, action2.getWorkflowActionComments().size());
    assertTrue("Action 3 should be completed", workflowActionService.isCompleted(action3));
    assertEquals(
        "Excpected number of comments of action 3", 2, action3.getWorkflowActionComments().size());
    assertFalse("Action 4 should be inactive", workflowActionService.isActive(action4));
    assertEquals(
        "Excpected number of comments of action 4", 0, action4.getWorkflowActionComments().size());
    assertTrue(
        "Action 5 should be ended by workflow", workflowActionService.isEndedByWorkflow(action5));
    assertEquals(
        "Excpected number of comments of action 5", 0, action5.getWorkflowActionComments().size());
    assertFalse("Action 6 should be inactive", workflowActionService.isActive(action6));
    assertEquals(
        "Excpected number of comments of action 6", 1, action6.getWorkflowActionComments().size());
    assertTrue("Workflow should be finished", workflowService.isFinished(testWorkflow));
  }
  @Test
  public void testWorkflowIteration() {
    final WorkflowActionModel action1 = getAction(ACTIONCODES.ACTION1.name());
    final WorkflowActionModel action2 = getAction(ACTIONCODES.ACTION2.name());
    final WorkflowActionModel action3 = getAction(ACTIONCODES.ACTION3.name());
    final WorkflowActionModel action4 = getAction(ACTIONCODES.ACTION4.name());
    final WorkflowActionModel action5 = getAction(ACTIONCODES.ACTION5.name());

    assertTrue("Action 1 should be active", workflowActionService.isActive(action1));
    assertFalse("Action 2 should be inactive", workflowActionService.isActive(action2));
    assertFalse("Action 3 should be inactive", workflowActionService.isActive(action3));
    assertFalse("Action 4 should be inactive", workflowActionService.isActive(action4));
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

    // complete action 1 with decision 1
    final WorkflowDecisionModel decision1 = getDecision(DECISIONCODES.DECISION1.name(), action1);
    action1.setSelectedDecision(decision1);

    workflowProcessingService.decideAction(action1, decision1);

    modelService.refresh(action2);
    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    modelService.refresh(action2);
    assertTrue("Action 2 should be active", workflowActionService.isActive(action2));
    assertFalse("Action 3 should be inactive", workflowActionService.isActive(action3));
    assertFalse("Action 4 should be inactive", workflowActionService.isActive(action4));
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

    // complete action 2 with decision 2
    final WorkflowDecisionModel decision2 = getDecision(DECISIONCODES.DECISION2.name(), action2);
    action2.setSelectedDecision(decision2);

    workflowProcessingService.decideAction(action2, decision2);

    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
    assertTrue("Action 3 should be active", workflowActionService.isActive(action3));
    assertFalse("Action 4 should be inactive", workflowActionService.isActive(action4));
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

    // complete action 3 with decision 3
    final WorkflowDecisionModel decision3 = getDecision(DECISIONCODES.DECISION3.name(), action3);
    action3.setSelectedDecision(decision3);
    workflowProcessingService.decideAction(action3, decision3);
    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
    assertTrue("Action 3 should be completed", workflowActionService.isCompleted(action3));
    assertTrue("Action 4 should be active", workflowActionService.isActive(action4));
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

    // complete action 4 with decision 4
    final WorkflowDecisionModel decision4 = getDecision(DECISIONCODES.DECISION4.name(), action4);
    action4.setSelectedDecision(decision4);
    workflowProcessingService.decideAction(action4, decision4);
    assertTrue("Action 1 should be active", workflowActionService.isActive(action1));
    assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
    assertTrue("Action 3 should be completed", workflowActionService.isCompleted(action3));
    assertTrue("Action 4 should be completed", workflowActionService.isCompleted(action4));
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

    // iterate 2 times
    for (int i = 0; i < 2; i++) {
      // complete action 1 with decision 1
      action1.setSelectedDecision(decision1);
      workflowProcessingService.decideAction(action1, decision1);
      assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
      assertTrue("Action 2 should be active", workflowActionService.isActive(action2));
      assertTrue("Action 3 should be completed", workflowActionService.isCompleted(action3));
      assertTrue("Action 4 should be completed", workflowActionService.isCompleted(action4));
      assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

      // complete action 2 with decision 2
      action2.setSelectedDecision(decision2);
      workflowProcessingService.decideAction(action2, decision2);
      assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
      assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
      assertTrue("Action 3 should be active", workflowActionService.isActive(action3));
      assertTrue("Action 4 should be completed", workflowActionService.isCompleted(action4));
      assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

      // complete action 3 with decision 3
      action3.setSelectedDecision(decision3);
      workflowProcessingService.decideAction(action3, decision3);
      assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
      assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
      assertTrue("Action 3 should be completed", workflowActionService.isCompleted(action3));
      assertTrue("Action 4 should be active", workflowActionService.isActive(action4));
      assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

      // complete action 4 with decision 4
      action4.setSelectedDecision(decision4);
      workflowProcessingService.decideAction(action4, decision4);
      assertTrue("Action 1 should be active", workflowActionService.isActive(action1));
      assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
      assertTrue("Action 3 should be completed", workflowActionService.isCompleted(action3));
      assertTrue("Action 4 should be completed", workflowActionService.isCompleted(action4));
      assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));
    }

    // complete action 1 with decision 1
    action1.setSelectedDecision(decision1);
    workflowProcessingService.decideAction(action1, decision1);
    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertTrue("Action 2 should be active", workflowActionService.isActive(action2));
    assertTrue("Action 3 should be completed", workflowActionService.isCompleted(action3));
    assertTrue("Action 4 should be completed", workflowActionService.isCompleted(action4));
    assertFalse("Action 5 should be inactive", workflowActionService.isActive(action5));

    // complete action 2 with decision 5
    final WorkflowDecisionModel decision5 = getDecision(DECISIONCODES.DECISION5.name(), action2);
    action2.setSelectedDecision(decision5);
    workflowProcessingService.decideAction(action2, decision5);
    assertTrue("Action 1 should be completed", workflowActionService.isCompleted(action1));
    assertTrue("Action 2 should be completed", workflowActionService.isCompleted(action2));
    assertTrue("Action 3 should be completed", workflowActionService.isCompleted(action3));
    assertTrue("Action 4 should be completed", workflowActionService.isCompleted(action4));
    assertTrue(
        "Action 5 should be ended by workflow", workflowActionService.isEndedByWorkflow(action5));
    assertTrue("Workflow should be finished", workflowService.isFinished(testWorkflow));
  }