public static ProcessInstance createMockInstance(String tenantId) { ProcessInstance mock = mock(ProcessInstance.class); when(mock.getId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID); when(mock.getBusinessKey()).thenReturn(EXAMPLE_PROCESS_INSTANCE_BUSINESS_KEY); when(mock.getCaseInstanceId()).thenReturn(EXAMPLE_CASE_INSTANCE_ID); when(mock.getProcessDefinitionId()).thenReturn(EXAMPLE_PROCESS_DEFINITION_ID); when(mock.getProcessInstanceId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID); when(mock.isSuspended()).thenReturn(EXAMPLE_PROCESS_INSTANCE_IS_SUSPENDED); when(mock.isEnded()).thenReturn(EXAMPLE_PROCESS_INSTANCE_IS_ENDED); when(mock.getTenantId()).thenReturn(tenantId); return mock; }
public void testQuerySortingDesc() { // exclude instances without tenant id because of database-specific ordering List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery() .tenantIdIn(TENANT_ONE, TENANT_TWO) .orderByTenantId() .desc() .list(); assertThat(processInstances.size(), is(2)); assertThat(processInstances.get(0).getTenantId(), is(TENANT_TWO)); assertThat(processInstances.get(1).getTenantId(), is(TENANT_ONE)); }
public void testQuerySortingAsc() { // exclude instances without tenant id because of database-specific ordering List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery() .tenantIdIn(TENANT_ONE, TENANT_TWO) .orderByTenantId() .asc() .list(); assertThat(processInstances.size(), is(2)); assertThat(processInstances.get(0).getTenantId(), is(TENANT_ONE)); assertThat(processInstances.get(1).getTenantId(), is(TENANT_TWO)); }
public ProcessInstanceDto(ProcessInstance instance) { this.id = instance.getId(); this.definitionId = instance.getProcessDefinitionId(); this.businessKey = instance.getBusinessKey(); this.caseInstanceId = instance.getCaseInstanceId(); this.ended = instance.isEnded(); this.suspended = instance.isSuspended(); this.tenantId = instance.getTenantId(); }
public ProcessInstanceDto(ProcessInstance instance) { this.id = instance.getId(); this.definitionId = instance.getProcessDefinitionId(); this.businessKey = instance.getBusinessKey(); this.caseInstanceId = instance.getCaseInstanceId(); this.ended = instance.isEnded(); this.suspended = instance.isSuspended(); this.tenantId = instance.getTenantId(); }
public void testStartProcessInstanceByKeyWithoutTenantId() { deployment(PROCESS); deploymentForTenant(TENANT_ONE, PROCESS); runtimeService.createProcessInstanceByKey("testProcess") .processDefinitionWithoutTenantId() .execute(); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery(); assertThat(query.count(), is(1L)); assertThat(query.singleResult().getTenantId(), is(nullValue())); }
@Test public void startProcessInstanceWithTenantId() { testRule.deployForTenant(TENANT_ONE, PROCESS); Job job = managementService.createJobQuery().singleResult(); assertThat(job.getTenantId(), is(TENANT_ONE)); managementService.executeJob(job.getId()); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult(); assertThat(processInstance, is(notNullValue())); assertThat(processInstance.getTenantId(), is(TENANT_ONE)); }
public void testStartProcessInstanceAtActivityByKeyWithoutTenantId() { deployment(PROCESS); deploymentForTenant(TENANT_ONE, PROCESS); runtimeService.createProcessInstanceByKey("testProcess") .processDefinitionWithoutTenantId() .startBeforeActivity("userTask") .execute(); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery(); assertThat(query.count(), is(1L)); assertThat(query.singleResult().getTenantId(), is(nullValue())); }
public void testPropagateTenantIdToProcessInstance() { deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY) .startEvent() .userTask() .endEvent() .done()); startProcessInstance(PROCESS_DEFINITION_KEY); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult(); assertThat(processInstance, is(notNullValue())); // inherit the tenant id from process definition assertThat(processInstance.getTenantId(), is(TENANT_ID)); }
@Test public void correlateMessageToStartEventNoTenantIdSetForNonTenant() { testRule.deploy(MESSAGE_START_PROCESS); engineRule.getRuntimeService().createMessageCorrelation("message").correlate(); ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery(); assertThat(query.count(), is(1L)); assertThat(query.singleResult().getTenantId(), is(nullValue())); }
@Test public void correlateMessageToStartEventWithoutTenantId() { testRule.deploy(MESSAGE_START_PROCESS); testRule.deployForTenant(TENANT_ONE, MESSAGE_START_PROCESS); engineRule.getRuntimeService().createMessageCorrelation("message") .withoutTenantId() .correlate(); ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery(); assertThat(query.count(), is(1L)); assertThat(query.singleResult().getTenantId(), is(nullValue())); }
@Test public void correlateStartMessageWithoutTenantId() { testRule.deploy(MESSAGE_START_PROCESS); testRule.deployForTenant(TENANT_ONE, MESSAGE_START_PROCESS); engineRule.getRuntimeService().createMessageCorrelation("message") .withoutTenantId() .correlateStartMessage(); ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery(); assertThat(query.count(), is(1L)); assertThat(query.singleResult().getTenantId(), is(nullValue())); }
@Test public void sendSignalToStartEventForNonTenant() { testRule.deploy(SIGNAL_START_PROCESS); testRule.deployForTenant(TENANT_ONE, SIGNAL_START_PROCESS); engineRule.getRuntimeService().createSignalEvent("signal").withoutTenantId().send(); ProcessInstanceQuery query = engineRule.getRuntimeService().createProcessInstanceQuery(); assertThat(query.count(), is(1L)); assertThat(query.singleResult().getTenantId(), is(nullValue())); }
@Test public void propagateTenantIdToProcessInstance() { testRule.deploy(Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY) .startEvent() .userTask() .endEvent() .done()); engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY); ProcessInstance processInstance = engineRule.getRuntimeService().createProcessInstanceQuery().singleResult(); assertThat(processInstance, is(notNullValue())); // get the tenant id from the provider assertThat(processInstance.getTenantId(), is(TENANT_ID)); }
@Test public void setNullTenantId() { String tenantId = null; StaticTenantIdTestProvider tenantIdProvider = new StaticTenantIdTestProvider(tenantId); TestTenantIdProvider.delegate = tenantIdProvider; testRule.deploy(Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().userTask().done()); // if a process instance is started engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY); // then the tenant id provider can set the tenant id to null ProcessInstance processInstance = engineRule.getRuntimeService().createProcessInstanceQuery().singleResult(); assertThat(processInstance.getTenantId(), is(nullValue())); }
@Test public void shouldRestartProcessInstanceWithTenant() { // given ProcessDefinition processDefinition = testRule.deployForTenantAndGetDefinition("tenantId", ProcessModels.TWO_TASKS_PROCESS); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process"); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); // when runtimeService.restartProcessInstances(processDefinition.getId()) .startBeforeActivity("userTask1") .processInstanceIds(processInstance.getId()) .execute(); // then ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult(); assertNotNull(restartedProcessInstance.getTenantId()); assertEquals(processInstance.getTenantId(), restartedProcessInstance.getTenantId()); }
@Test public void setsTenantId_SubProcessInstance() { String tenantId = TENANT_ID; SetValueOnSubProcessInstanceTenantIdProvider tenantIdProvider = new SetValueOnSubProcessInstanceTenantIdProvider(tenantId); TestTenantIdProvider.delegate = tenantIdProvider; testRule.deploy(Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().userTask().done(), Bpmn.createExecutableProcess("superProcess").startEvent().callActivity().calledElement(PROCESS_DEFINITION_KEY).done()); // if a process instance is started engineRule.getRuntimeService().startProcessInstanceByKey("superProcess"); // then the tenant id provider can set the tenant id to a value ProcessInstance subProcessInstance = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult(); assertThat(subProcessInstance.getTenantId(), is(tenantId)); // and the super process instance is not assigned a tenant id ProcessInstance superProcessInstance = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionKey("superProcess").singleResult(); assertThat(superProcessInstance.getTenantId(), is(nullValue())); }
@Test public void setsTenantId() { String tenantId = TENANT_ID; StaticTenantIdTestProvider tenantIdProvider = new StaticTenantIdTestProvider(tenantId); TestTenantIdProvider.delegate = tenantIdProvider; testRule.deploy(Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().userTask().done()); // if a process instance is started engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY); // then the tenant id provider can set the tenant id to a value ProcessInstance processInstance = engineRule.getRuntimeService().createProcessInstanceQuery().singleResult(); assertThat(processInstance.getTenantId(), is(tenantId)); }
@Test public void setNullTenantId_SubProcessInstance() { String tenantId = null; SetValueOnSubProcessInstanceTenantIdProvider tenantIdProvider = new SetValueOnSubProcessInstanceTenantIdProvider(tenantId); TestTenantIdProvider.delegate = tenantIdProvider; testRule.deploy(Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().userTask().done(), Bpmn.createExecutableProcess("superProcess").startEvent().callActivity().calledElement(PROCESS_DEFINITION_KEY).done()); // if a process instance is started engineRule.getRuntimeService().startProcessInstanceByKey("superProcess"); // then the tenant id provider can set the tenant id to null ProcessInstance processInstance = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult(); assertThat(processInstance.getTenantId(), is(nullValue())); }
@Test public void tenantIdInheritedFromSuperProcessInstance() { String tenantId = TENANT_ID; SetValueOnRootProcessInstanceTenantIdProvider tenantIdProvider = new SetValueOnRootProcessInstanceTenantIdProvider(tenantId); TestTenantIdProvider.delegate = tenantIdProvider; testRule.deploy(Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().userTask().done(), Bpmn.createExecutableProcess("superProcess").startEvent().callActivity().calledElement(PROCESS_DEFINITION_KEY).done()); // if a process instance is started engineRule.getRuntimeService().startProcessInstanceByKey("superProcess"); // then the tenant id is inherited to the sub process instance even tough it is not set by the provider ProcessInstance processInstance = engineRule.getRuntimeService().createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult(); assertThat(processInstance.getTenantId(), is(tenantId)); }