IntegrationContextBuilder { public IntegrationContext from(IntegrationContextEntity integrationContextEntity, DelegateExecution execution) { IntegrationContextImpl integrationContext = buildFromExecution(execution); integrationContext.setId(integrationContextEntity.getId()); return integrationContext; } IntegrationContextBuilder(ExtensionsVariablesMappingProvider inboundVariablesProvider); IntegrationContext from(IntegrationContextEntity integrationContextEntity,
                                   DelegateExecution execution); IntegrationContext from(DelegateExecution execution);  }
@Test public void shouldBuildIntegrationContextFromExecution() { ExecutionEntity execution = mock(ExecutionEntity.class); ExecutionEntity processInstance = mock(ExecutionEntity.class); ServiceTask serviceTask = mock(ServiceTask.class); Map<String, Object> variables = singletonMap("key", "value"); given(inboundVariablesProvider.calculateInputVariables(execution)).willReturn(variables); given(serviceTask.getImplementation()).willReturn(IMPLEMENTATION); given(serviceTask.getName()).willReturn(SERVICE_TASK_NAME); given(execution.getVariables()).willReturn(variables); given(execution.getCurrentActivityId()).willReturn(CURRENT_ACTIVITY_ID); given(execution.getCurrentFlowElement()).willReturn(serviceTask); given(execution.getProcessInstanceId()).willReturn(PROCESS_INSTANCE_ID); given(execution.getProcessDefinitionId()).willReturn(PROCESS_DEFINITION_ID); given(execution.getCurrentActivityId()).willReturn(CURRENT_ACTIVITY_ID); given(execution.getProcessInstanceBusinessKey()).willReturn(PROCESS_INSTANCE_BUSINESS_KEY); given(execution.getProcessInstance()).willReturn(processInstance); given(processInstance.getParentProcessInstanceId()).willReturn(PARENT_PROCESS_INSTANCE_ID); IntegrationContext integrationContext = builder.from(execution); assertThat(integrationContext).isNotNull(); assertThat(integrationContext.getConnectorType()).isEqualTo(IMPLEMENTATION); assertThat(integrationContext.getClientId()).isEqualTo(CURRENT_ACTIVITY_ID); assertThat(integrationContext.getClientName()).isEqualTo(SERVICE_TASK_NAME); assertThat(integrationContext.getClientType()).isEqualTo(ServiceTask.class.getSimpleName()); assertThat(integrationContext.getBusinessKey()).isEqualTo(PROCESS_INSTANCE_BUSINESS_KEY); assertThat(integrationContext.getProcessDefinitionId()).isEqualTo(PROCESS_DEFINITION_ID); assertThat(integrationContext.getProcessInstanceId()).isEqualTo(PROCESS_INSTANCE_ID); assertThat(integrationContext.getProcessDefinitionKey()).isEqualTo(PROCESS_DEFINITION_KEY); assertThat(integrationContext.getProcessDefinitionVersion()).isEqualTo(PROCESS_DEFINITION_VERSION); assertThat(integrationContext.getParentProcessInstanceId()).isEqualTo(PARENT_PROCESS_INSTANCE_ID); assertThat(integrationContext.getInBoundVariables()).containsAllEntriesOf(variables); }
@Test public void shouldSetIdWhenIntegrationContextEntityIsProvided() { ExecutionEntity execution = mock(ExecutionEntity.class); ExecutionEntity processInstance = mock(ExecutionEntity.class); ServiceTask serviceTask = mock(ServiceTask.class); Map<String, Object> variables = singletonMap("key", "value"); given(inboundVariablesProvider.calculateInputVariables(execution)).willReturn(variables); given(serviceTask.getImplementation()).willReturn(IMPLEMENTATION); given(serviceTask.getName()).willReturn(SERVICE_TASK_NAME); given(execution.getVariables()).willReturn(variables); given(execution.getCurrentActivityId()).willReturn(CURRENT_ACTIVITY_ID); given(execution.getCurrentFlowElement()).willReturn(serviceTask); given(execution.getProcessInstanceId()).willReturn(PROCESS_INSTANCE_ID); given(execution.getProcessDefinitionId()).willReturn(PROCESS_DEFINITION_ID); given(execution.getCurrentActivityId()).willReturn(CURRENT_ACTIVITY_ID); given(execution.getProcessInstanceBusinessKey()).willReturn(PROCESS_INSTANCE_BUSINESS_KEY); given(execution.getProcessInstance()).willReturn(processInstance); given(processInstance.getParentProcessInstanceId()).willReturn(PARENT_PROCESS_INSTANCE_ID); IntegrationContextEntityImpl integrationContextEntity = new IntegrationContextEntityImpl(); integrationContextEntity.setId("entityId"); IntegrationContext integrationContext = builder.from(integrationContextEntity, execution); assertThat(integrationContext).isNotNull(); assertThat(integrationContext.getId()).isEqualTo("entityId"); assertThat(integrationContext.getConnectorType()).isEqualTo(IMPLEMENTATION); assertThat(integrationContext.getClientId()).isEqualTo(CURRENT_ACTIVITY_ID); assertThat(integrationContext.getClientName()).isEqualTo(SERVICE_TASK_NAME); assertThat(integrationContext.getClientType()).isEqualTo(ServiceTask.class.getSimpleName()); assertThat(integrationContext.getBusinessKey()).isEqualTo(PROCESS_INSTANCE_BUSINESS_KEY); assertThat(integrationContext.getProcessDefinitionId()).isEqualTo(PROCESS_DEFINITION_ID); assertThat(integrationContext.getProcessInstanceId()).isEqualTo(PROCESS_INSTANCE_ID); assertThat(integrationContext.getProcessDefinitionKey()).isEqualTo(PROCESS_DEFINITION_KEY); assertThat(integrationContext.getProcessDefinitionVersion()).isEqualTo(PROCESS_DEFINITION_VERSION); assertThat(integrationContext.getParentProcessInstanceId()).isEqualTo(PARENT_PROCESS_INSTANCE_ID); assertThat(integrationContext.getInBoundVariables()).containsAllEntriesOf(variables); }