public void shouldProceedCustomerWorkFlowWithMandatoryIdTasks()

in component-test/src/main/java/org/apache/fineract/cn/customer/TestTaskInstance.java [37:99]


  public void shouldProceedCustomerWorkFlowWithMandatoryIdTasks() throws Exception {
    // create a predefined and mandatory task validating every state transition
    // has a an ID card assigned
    final TaskDefinition taskDefinition = new TaskDefinition();
    taskDefinition.setIdentifier("nat-id");
    taskDefinition.setType(TaskDefinition.Type.ID_CARD.name());
    taskDefinition.setName("National ID is needed.");
    taskDefinition.setCommands(
        TaskDefinition.Command.ACTIVATE.name(),
        TaskDefinition.Command.UNLOCK.name(),
        TaskDefinition.Command.REOPEN.name()
    );
    taskDefinition.setPredefined(Boolean.TRUE);
    taskDefinition.setMandatory(Boolean.TRUE);

    this.customerManager.createTask(taskDefinition);
    this.eventRecorder.wait(CustomerEventConstants.POST_TASK, taskDefinition.getIdentifier());

    // create a random customer
    final Customer randomCustomer = CustomerGenerator.createRandomCustomer();
    this.customerManager.createCustomer(randomCustomer);
    this.eventRecorder.wait(CustomerEventConstants.POST_CUSTOMER, randomCustomer.getIdentifier());

    // try to activate the customer with missing ID card
    final Command activateCustomer = new Command();
    activateCustomer.setAction(Command.Action.ACTIVATE.name());
    this.customerManager.customerCommand(randomCustomer.getIdentifier(), activateCustomer);
    Assert.assertFalse(this.eventRecorder.wait(CustomerEventConstants.ACTIVATE_CUSTOMER, randomCustomer.getIdentifier()));

    // assert client is still in pending
    final Customer stillPendingCustomer = this.customerManager.findCustomer(randomCustomer.getIdentifier());
    Assert.assertEquals(Customer.State.PENDING.name(), stillPendingCustomer.getCurrentState());

    try {
      // try to close the task
      this.customerManager.taskForCustomerExecuted(randomCustomer.getIdentifier(), taskDefinition.getIdentifier());
      Assert.fail();
    } catch (final TaskExecutionException ex) {
      // do nothing, expected
    }

    // set the ID card for the customer
    final IdentificationCard randomIdentificationCard = IdentificationCardGenerator.createRandomIdentificationCard();
    this.customerManager.createIdentificationCard(randomCustomer.getIdentifier(), randomIdentificationCard);
    this.eventRecorder.wait(CustomerEventConstants.POST_IDENTIFICATION_CARD, randomIdentificationCard.getNumber());

    // close the task
    this.customerManager.taskForCustomerExecuted(randomCustomer.getIdentifier(), taskDefinition.getIdentifier());
    this.eventRecorder.wait(CustomerEventConstants.PUT_CUSTOMER, randomCustomer.getIdentifier());

    // try to activate customer
    this.customerManager.customerCommand(randomCustomer.getIdentifier(), activateCustomer);
    this.eventRecorder.wait(CustomerEventConstants.ACTIVATE_CUSTOMER, randomCustomer.getIdentifier());

    // assert customer is now active
    final Customer activatedCustomer = this.customerManager.findCustomer(randomCustomer.getIdentifier());
    Assert.assertEquals(Customer.State.ACTIVE.name(), activatedCustomer.getCurrentState());

    // set predefined to false so it does not have a side effect on other tests
    taskDefinition.setPredefined(false);
    this.customerManager.updateTask(taskDefinition.getIdentifier(), taskDefinition);
    this.eventRecorder.wait(CustomerEventConstants.PUT_TASK, taskDefinition.getIdentifier());
  }