@Test
  public void existingNotStartedBusinessProcessShouldPickUpLatestProcessDefinition()
      throws InterruptedException {
    final ActionsJournal journal = Registry.getApplicationContext().getBean(ActionsJournal.class);
    final DynamicProcessDefinitionModel initialProcessDefinition = givenInitialProcessDefinition();

    final BusinessProcessModel businessProcess =
        businessProcessService.createProcess(TEST_PROCESS_CODE, TEST_DEFINITION_CODE);
    givenUpdatedProcessDefinitionOf(initialProcessDefinition);
    businessProcessService.startProcess(businessProcess);
    waitFor(businessProcess);

    assertThat(businessProcess.getProcessDefinitionName()).isEqualTo(TEST_DEFINITION_CODE);
    assertThat(businessProcess.getProcessDefinitionVersion())
        .isNotNull()
        .isEqualTo(Long.toString(1L));
    journal.verify(businessProcess.getCode(), PROCEDURAL_ACTION_ID, UPDATED_NUMBER_OF_NODES);
  }
  @Test
  public void runningBusinessProcessShouldFinishWithOldProcessDefinition()
      throws InterruptedException {
    final ActionsJournal journal = Registry.getApplicationContext().getBean(ActionsJournal.class);
    final DynamicProcessDefinitionModel initialProcessDefinition = givenInitialProcessDefinition();

    final BusinessProcessModel businessProcess =
        businessProcessService.createProcess(TEST_PROCESS_CODE, TEST_DEFINITION_CODE);
    businessProcessService.startProcess(businessProcess);
    final DynamicProcessDefinitionModel latestProcessDefinition =
        givenUpdatedProcessDefinitionOf(initialProcessDefinition);
    waitFor(businessProcess);

    assertThat(businessProcess.getProcessDefinitionName()).isEqualTo(TEST_DEFINITION_CODE);
    assertThat(businessProcess.getProcessDefinitionVersion())
        .isNotNull()
        .isNotEqualTo(latestProcessDefinition.getChecksum());
    journal.verify(businessProcess.getCode(), PROCEDURAL_ACTION_ID, INITIAL_NUMBER_OF_NODES);
  }
Пример #3
0
  @Override
  public void executeAction(final OrderProcessModel process) throws Exception {
    if (LOG.isInfoEnabled()) {
      LOG.info("Process: " + process.getCode() + " in step " + getClass());
    }

    // find the order's entries that are not already allocated to consignments
    final List<AbstractOrderEntryModel> entriesToSplit = new ArrayList<AbstractOrderEntryModel>();
    for (final AbstractOrderEntryModel entry : process.getOrder().getEntries()) {
      if (entry.getConsignmentEntries() == null || entry.getConsignmentEntries().isEmpty()) {
        entriesToSplit.add(entry);
      }
    }

    final List<ConsignmentModel> consignments =
        getOrderSplittingService().splitOrderForConsignment(process.getOrder(), entriesToSplit);

    if (LOG.isDebugEnabled()) {
      LOG.debug("Splitting order into " + consignments.size() + " consignments.");
    }

    final BusinessProcessService businessProcessService = getBusinessProcessService();

    int index = 0;
    for (final ConsignmentModel consignment : consignments) {
      final ConsignmentProcessModel subProcess =
          businessProcessService.<ConsignmentProcessModel>createProcess(
              process.getCode() + "_" + (++index),
              MitreFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_NAME);

      subProcess.setParentProcess(process);
      subProcess.setConsignment(consignment);
      save(subProcess);

      businessProcessService.startProcess(subProcess);
    }
    setOrderStatus(process.getOrder(), OrderStatus.ORDER_SPLIT);
  }
  @Test
  public void businessProcessShouldPickUpTheOnlyOneExistingProcessDefinition()
      throws InterruptedException {
    final ActionsJournal journal = Registry.getApplicationContext().getBean(ActionsJournal.class);
    givenInitialProcessDefinition();

    final BusinessProcessModel businessProcess =
        businessProcessService.startProcess(TEST_PROCESS_CODE, TEST_DEFINITION_CODE);
    waitFor(businessProcess);

    assertThat(businessProcess.getProcessDefinitionName()).isEqualTo(TEST_DEFINITION_CODE);
    assertThat(businessProcess.getProcessDefinitionVersion())
        .isNotNull()
        .isEqualTo(Long.toString(0L));
    journal.verify(businessProcess.getCode(), PROCEDURAL_ACTION_ID, INITIAL_NUMBER_OF_NODES);
  }