org.camunda.bpm.engine.CaseService Java Examples

The following examples show how to use org.camunda.bpm.engine.CaseService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CaseInstanceFakeTest.java    From camunda-bpm-mockito with Apache License 2.0 6 votes vote down vote up
@Test
public void prepare_with_service_mock() {
  CaseService caseService = mock(CaseService.class);
  String uuid = UUID.randomUUID().toString();
  String businessKey = "12";

  AtomicReference<CaseInstanceFake> reference = CaseInstanceFake.prepareMock(caseService, uuid);

  assertThat(reference.get()).isNull();

  CaseInstance instance = caseService.createCaseInstanceByKey("case", businessKey, Variables.putValue("foo", "bar"));
  assertThat(reference.get()).isNotNull();
  assertThat(instance.getCaseInstanceId()).isEqualTo(uuid);

  assertThat(caseService.getVariable(uuid, "foo")).isEqualTo("bar");

  caseService.setVariable(uuid, "hello", 456);
  assertThat(caseService.getVariable(uuid, "hello")).isEqualTo(456);

  assertThat(caseService.createCaseInstanceQuery().singleResult()).isEqualTo(reference.get());
}
 
Example #2
Source File: MockedProcessEngineProvider.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void mockServices(ProcessEngine engine) {
  RepositoryService repoService = mock(RepositoryService.class);
  IdentityService identityService = mock(IdentityService.class);
  TaskService taskService = mock(TaskService.class);
  RuntimeService runtimeService = mock(RuntimeService.class);
  FormService formService = mock(FormService.class);
  HistoryService historyService = mock(HistoryService.class);
  ManagementService managementService = mock(ManagementService.class);
  CaseService caseService = mock(CaseService.class);
  FilterService filterService = mock(FilterService.class);
  ExternalTaskService externalTaskService = mock(ExternalTaskService.class);

  when(engine.getRepositoryService()).thenReturn(repoService);
  when(engine.getIdentityService()).thenReturn(identityService);
  when(engine.getTaskService()).thenReturn(taskService);
  when(engine.getRuntimeService()).thenReturn(runtimeService);
  when(engine.getFormService()).thenReturn(formService);
  when(engine.getHistoryService()).thenReturn(historyService);
  when(engine.getManagementService()).thenReturn(managementService);
  when(engine.getCaseService()).thenReturn(caseService);
  when(engine.getFilterService()).thenReturn(filterService);
  when(engine.getExternalTaskService()).thenReturn(externalTaskService);
}
 
Example #3
Source File: MockedProcessEngineProvider.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void mockServices(ProcessEngine engine) {
  RepositoryService repoService = mock(RepositoryService.class);
  IdentityService identityService = mock(IdentityService.class);
  TaskService taskService = mock(TaskService.class);
  RuntimeService runtimeService = mock(RuntimeService.class);
  FormService formService = mock(FormService.class);
  HistoryService historyService = mock(HistoryService.class);
  ManagementService managementService = mock(ManagementService.class);
  CaseService caseService = mock(CaseService.class);
  FilterService filterService = mock(FilterService.class);
  ExternalTaskService externalTaskService = mock(ExternalTaskService.class);

  when(engine.getRepositoryService()).thenReturn(repoService);
  when(engine.getIdentityService()).thenReturn(identityService);
  when(engine.getTaskService()).thenReturn(taskService);
  when(engine.getRuntimeService()).thenReturn(runtimeService);
  when(engine.getFormService()).thenReturn(formService);
  when(engine.getHistoryService()).thenReturn(historyService);
  when(engine.getManagementService()).thenReturn(managementService);
  when(engine.getCaseService()).thenReturn(caseService);
  when(engine.getFilterService()).thenReturn(filterService);
  when(engine.getExternalTaskService()).thenReturn(externalTaskService);
}
 
Example #4
Source File: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Before
public void setUpRuntime() {
  CaseDefinition mockCaseDefinition = MockProvider.createMockCaseDefinition();

  setUpRuntimeData(mockCaseDefinition);

  caseServiceMock = mock(CaseService.class);

  when(processEngine.getCaseService()).thenReturn(caseServiceMock);

  caseInstanceBuilder = mock(CaseInstanceBuilder.class);
  CaseInstance mockCaseInstance = MockProvider.createMockCaseInstance();

  when(caseServiceMock.withCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID)).thenReturn(caseInstanceBuilder);
  when(caseInstanceBuilder.businessKey(anyString())).thenReturn(caseInstanceBuilder);
  when(caseInstanceBuilder.setVariables(Matchers.<Map<String, Object>>any())).thenReturn(caseInstanceBuilder);
  when(caseInstanceBuilder.create()).thenReturn(mockCaseInstance);
}
 
Example #5
Source File: SentryScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("triggerStageEntryCriterion")
public static ScenarioSetup completeStage() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      CaseService caseService = engine.getCaseService();
      CaseInstance caseInstance = caseService.createCaseInstanceByKey("case", scenarioName);
      String caseInstanceId = caseInstance.getId();
      
      CaseExecutionQuery query = caseService.createCaseExecutionQuery().caseInstanceId(caseInstanceId);

      String firstHumanTaskId = query.activityId("PI_HumanTask_1").singleResult().getId();
      caseService.manuallyStartCaseExecution(firstHumanTaskId);
      caseService.completeCaseExecution(firstHumanTaskId);

      String secondHumanTaskId = query.activityId("PI_HumanTask_2").singleResult().getId();
      caseService.manuallyStartCaseExecution(secondHumanTaskId);
    }
  };
}
 
Example #6
Source File: SentryScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("newSentryInstance")
public static ScenarioSetup newSentryInstance() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      CaseService caseService = engine.getCaseService();
      CaseInstance caseInstance = caseService.createCaseInstanceByKey("case", scenarioName);
      String caseInstanceId = caseInstance.getId();
      
      CaseExecutionQuery query = caseService.createCaseExecutionQuery().caseInstanceId(caseInstanceId);

      String firstHumanTaskId = query.activityId("PI_HumanTask_1").singleResult().getId();
      caseService.manuallyStartCaseExecution(firstHumanTaskId);
      caseService.completeCaseExecution(firstHumanTaskId);

      String secondHumanTaskId = query.activityId("PI_HumanTask_2").singleResult().getId();
      caseService.manuallyStartCaseExecution(secondHumanTaskId);
      caseService.completeCaseExecution(secondHumanTaskId);
    }
  };
}
 
Example #7
Source File: ShipmentBoundaryServiceImpl.java    From Showcase with Apache License 2.0 6 votes vote down vote up
@Autowired
public ShipmentBoundaryServiceImpl(CompleteShipmentOrderTask completeShipmentOrderTask,
                                   OrganizeFlightTask organizeFlightTask,
                                   CreateInvoiceTask createInvoiceTask,
                                   ShipmentRepository shipmentRepository,
                                   InvoiceRepository invoiceRepository,
                                   FlightDepartedSentry flightDepartedSentry,
                                   FlightDeparted flightDeparted,
                                   ShipmentCaseControlService shipmentCaseControlService,
                                   ShipmentCaseEvaluator shipmentCaseEvaluator,
                                   ProcessEngine processEngine,
                                   CaseService caseService,
                                   TaskService taskService) {
    this.completeShipmentOrderTask = completeShipmentOrderTask;
    this.organizeFlightTask = organizeFlightTask;
    this.createInvoiceTask = createInvoiceTask;
    this.shipmentRepository = shipmentRepository;
    this.invoiceRepository = invoiceRepository;
    this.flightDepartedSentry = flightDepartedSentry;
    this.flightDeparted = flightDeparted;
    this.shipmentCaseControlService = shipmentCaseControlService;
    this.shipmentCaseEvaluator = shipmentCaseEvaluator;
    this.caseService = caseService;
    this.taskService = taskService;
}
 
Example #8
Source File: SentryScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("triggerTaskEntryCriterion")
public static ScenarioSetup triggerEntryCriterion() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      CaseService caseService = engine.getCaseService();
      caseService.createCaseInstanceByKey("case", scenarioName);
    }
  };
}
 
Example #9
Source File: SentryScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("completeInstance")
public static ScenarioSetup completeInstance() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      CaseService caseService = engine.getCaseService();
      caseService.createCaseInstanceByKey("case", scenarioName);
    }
  };
}
 
Example #10
Source File: LocalCaseExecutionVariablesResource.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void updateVariableEntities(VariableMap variables, List<String> deletions) {
  CaseService caseService = engine.getCaseService();
  caseService
    .withCaseExecution(resourceId)
    .setVariablesLocal(variables)
    .removeVariablesLocal(deletions)
    .execute();
}
 
Example #11
Source File: CaseExecutionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Before
public void setUpRuntime() {
  CaseExecution mockCaseExecution = MockProvider.createMockCaseExecution();

  caseServiceMock = mock(CaseService.class);

  when(processEngine.getCaseService()).thenReturn(caseServiceMock);

  caseExecutionQueryMock = mock(CaseExecutionQuery.class);

  when(caseServiceMock.createCaseExecutionQuery()).thenReturn(caseExecutionQueryMock);
  when(caseExecutionQueryMock.caseExecutionId(MockProvider.EXAMPLE_CASE_EXECUTION_ID)).thenReturn(caseExecutionQueryMock);
  when(caseExecutionQueryMock.singleResult()).thenReturn(mockCaseExecution);

  when(caseServiceMock.getVariableTyped(anyString(), anyString(), eq(true))).thenReturn(EXAMPLE_VARIABLE_VALUE);
  when(caseServiceMock.getVariablesTyped(anyString(), eq(true))).thenReturn(EXAMPLE_VARIABLES);

  when(caseServiceMock.getVariableLocalTyped(anyString(), eq(EXAMPLE_VARIABLE_KEY), anyBoolean())).thenReturn(EXAMPLE_VARIABLE_VALUE);
  when(caseServiceMock.getVariableLocalTyped(anyString(), eq(EXAMPLE_BYTES_VARIABLE_KEY), eq(false))).thenReturn(EXAMPLE_VARIABLE_VALUE_BYTES);
  when(caseServiceMock.getVariablesLocalTyped(anyString(), eq(true))).thenReturn(EXAMPLE_VARIABLES);

  when(caseServiceMock.getVariablesTyped(anyString(), Matchers.<Collection<String>>any(), eq(true))).thenReturn(EXAMPLE_VARIABLES);
  when(caseServiceMock.getVariablesLocalTyped(anyString(), Matchers.<Collection<String>>any(), eq(true))).thenReturn(EXAMPLE_VARIABLES);

  caseExecutionCommandBuilderMock = mock(CaseExecutionCommandBuilder.class);

  when(caseServiceMock.withCaseExecution(MockProvider.EXAMPLE_CASE_EXECUTION_ID)).thenReturn(caseExecutionCommandBuilderMock);

  when(caseExecutionCommandBuilderMock.setVariable(anyString(), any())).thenReturn(caseExecutionCommandBuilderMock);
  when(caseExecutionCommandBuilderMock.setVariableLocal(anyString(), any())).thenReturn(caseExecutionCommandBuilderMock);
  when(caseExecutionCommandBuilderMock.setVariables(Matchers.<Map<String, Object>>any())).thenReturn(caseExecutionCommandBuilderMock);
  when(caseExecutionCommandBuilderMock.setVariablesLocal(Matchers.<Map<String, Object>>any())).thenReturn(caseExecutionCommandBuilderMock);

  when(caseExecutionCommandBuilderMock.removeVariable(anyString())).thenReturn(caseExecutionCommandBuilderMock);
  when(caseExecutionCommandBuilderMock.removeVariableLocal(anyString())).thenReturn(caseExecutionCommandBuilderMock);
  when(caseExecutionCommandBuilderMock.removeVariables(Matchers.<Collection<String>>any())).thenReturn(caseExecutionCommandBuilderMock);
  when(caseExecutionCommandBuilderMock.removeVariablesLocal(Matchers.<Collection<String>>any())).thenReturn(caseExecutionCommandBuilderMock);

}
 
Example #12
Source File: CaseExecutionVariablesResource.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void setVariableEntity(String variableKey, TypedValue variableValue) {
  CaseService caseService = engine.getCaseService();
  caseService
    .withCaseExecution(resourceId)
    .setVariable(variableKey, variableValue)
    .execute();
}
 
Example #13
Source File: CaseExecutionVariablesResource.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void removeVariableEntity(String variableKey) {
  CaseService caseService = engine.getCaseService();
  caseService
    .withCaseExecution(resourceId)
    .removeVariable(variableKey)
    .execute();
}
 
Example #14
Source File: CaseExecutionVariablesResource.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void updateVariableEntities(VariableMap variables, List<String> deletions) {
  CaseService caseService = engine.getCaseService();
  caseService
    .withCaseExecution(resourceId)
    .setVariables(variables)
    .removeVariables(deletions)
    .execute();
}
 
Example #15
Source File: CaseInstanceResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public CaseInstanceDto getCaseInstance() {
  CaseService caseService = engine.getCaseService();

  CaseInstance instance = caseService
      .createCaseInstanceQuery()
      .caseInstanceId(caseInstanceId)
      .singleResult();

  if (instance == null) {
    throw new InvalidRequestException(Status.NOT_FOUND, "Case instance with id " + caseInstanceId + " does not exist.");
  }

  CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);
  return result;
}
 
Example #16
Source File: LocalCaseExecutionVariablesResource.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void removeVariableEntity(String variableKey) {
  CaseService caseService = engine.getCaseService();
  caseService
    .withCaseExecution(resourceId)
    .removeVariableLocal(variableKey)
    .execute();
}
 
Example #17
Source File: CaseExecutionResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public CaseExecutionDto getCaseExecution() {
  CaseService caseService = engine.getCaseService();

  CaseExecution execution = caseService
      .createCaseExecutionQuery()
      .caseExecutionId(caseExecutionId)
      .singleResult();

  if (execution == null) {
    throw new InvalidRequestException(Status.NOT_FOUND, "Case execution with id " + caseExecutionId + " does not exist.");
  }

  CaseExecutionDto result = CaseExecutionDto.fromCaseExecution(execution);
  return result;
}
 
Example #18
Source File: CaseTest.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
@Test
public void assigneToMe() {
  CaseService caseService = processEngine().getCaseService();
  CaseInstance caseInstance = caseService.createCaseInstanceByKey("Case");

  Task task = taskService().createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();
  assertThat(task).isAssignedTo("me");

  CaseExecution caseExecution = caseService.createCaseExecutionQuery().activityId("_ab60407c-449e-4048-ba9c-01bb59f2f095").singleResult();
  caseService.completeCaseExecution(caseExecution.getId());
}
 
Example #19
Source File: CaseInstanceFake.java    From camunda-bpm-mockito with Apache License 2.0 5 votes vote down vote up
public static AtomicReference<CaseInstanceFake> prepareMock(CaseService caseServiceMock, String caseInstanceId) {
  // create an instance with id
  AtomicReference<CaseInstanceFake> caseInstanceFake = new AtomicReference<>();

  when(caseServiceMock.createCaseInstanceByKey(anyString(), anyString(), anyMap())).thenAnswer(invocation -> {
    CaseInstanceFakeBuilder builder = builder().caseInstanceId(caseInstanceId)
      .caseDefinitionId(invocation.getArgument(0) + ":1")
      .businessKey(invocation.getArgument(1));

    ((Map<String, Object>) invocation.getArgument(2)).forEach((k, v) -> builder.variable(k, v));

    caseInstanceFake.set(builder.build());

    // let every caseInstance query return our instance
    QueryMocks.mockCaseInstanceQuery(caseServiceMock)
      .singleResult(Optional.ofNullable(caseInstanceFake.get())
        .orElse(null));


    return caseInstanceFake.get();
  });


  // answer getVariable by asking the fakes variableMap
  when(caseServiceMock.getVariable(ArgumentMatchers.eq(caseInstanceId), anyString()))
    .then(invocation -> Optional.ofNullable(caseInstanceFake.get())
      .map(i -> i.getVariable(invocation.getArgument(1))).orElse(null));

  // modify fakes variableMap on setVariable
  doAnswer(invocation -> {
    caseInstanceFake.get().setVariable(invocation.getArgument(1), invocation.getArgument(2));

    return null;
  }).when(caseServiceMock).setVariable(eq(caseInstanceId), anyString(), any());

  return caseInstanceFake;
}
 
Example #20
Source File: LocalCaseExecutionVariablesResource.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected VariableMap getVariableEntities(boolean deserializeValues) {
  CaseService caseService = engine.getCaseService();
  return caseService.getVariablesLocalTyped(resourceId, deserializeValues);
}
 
Example #21
Source File: SpringProcessEngineServicesConfiguration.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Bean(name = "caseService")
@Override
public CaseService getCaseService() {
  return processEngine.getCaseService();
}
 
Example #22
Source File: FlightDepartedSentry.java    From Showcase with Apache License 2.0 4 votes vote down vote up
@Autowired
public FlightDepartedSentry(CaseService caseService) {
    this.caseService = caseService;
}
 
Example #23
Source File: CaseInstanceQueryMock.java    From camunda-bpm-mockito with Apache License 2.0 4 votes vote down vote up
public CaseInstanceQueryMock() {
 super(CaseInstanceQuery.class, CaseService.class);
}
 
Example #24
Source File: ProcessEngineRestServiceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpRuntimeData() {
  namedProcessEngine = getProcessEngine(EXAMPLE_ENGINE_NAME);
  mockRepoService = mock(RepositoryService.class);
  mockRuntimeService = mock(RuntimeService.class);
  mockTaskService = mock(TaskService.class);
  mockIdentityService = mock(IdentityService.class);
  mockManagementService = mock(ManagementService.class);
  mockHistoryService = mock(HistoryService.class);
  mockCaseService = mock(CaseService.class);
  mockFilterService = mock(FilterService.class);
  mockExternalTaskService = mock(ExternalTaskService.class);

  when(namedProcessEngine.getRepositoryService()).thenReturn(mockRepoService);
  when(namedProcessEngine.getRuntimeService()).thenReturn(mockRuntimeService);
  when(namedProcessEngine.getTaskService()).thenReturn(mockTaskService);
  when(namedProcessEngine.getIdentityService()).thenReturn(mockIdentityService);
  when(namedProcessEngine.getManagementService()).thenReturn(mockManagementService);
  when(namedProcessEngine.getHistoryService()).thenReturn(mockHistoryService);
  when(namedProcessEngine.getCaseService()).thenReturn(mockCaseService);
  when(namedProcessEngine.getFilterService()).thenReturn(mockFilterService);
  when(namedProcessEngine.getExternalTaskService()).thenReturn(mockExternalTaskService);

  createProcessDefinitionMock();
  createProcessInstanceMock();
  createTaskMock();
  createIdentityMocks();
  createExecutionMock();
  createVariableInstanceMock();
  createJobDefinitionMock();
  createIncidentMock();
  createDeploymentMock();
  createMessageCorrelationBuilderMock();
  createCaseDefinitionMock();
  createCaseInstanceMock();
  createCaseExecutionMock();
  createFilterMock();
  createExternalTaskMock();

  createHistoricActivityInstanceMock();
  createHistoricProcessInstanceMock();
  createHistoricVariableInstanceMock();
  createHistoricActivityStatisticsMock();
  createHistoricDetailMock();
  createHistoricTaskInstanceMock();
  createHistoricIncidentMock();
  createHistoricJobLogMock();
  createHistoricExternalTaskLogMock();
}
 
Example #25
Source File: CaseExecutionQueryMock.java    From camunda-bpm-mockito with Apache License 2.0 4 votes vote down vote up
public CaseExecutionQueryMock() {
 super(CaseExecutionQuery.class, CaseService.class);
}
 
Example #26
Source File: CaseExecutionVariablesResource.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected TypedValue getVariableEntity(String variableKey, boolean deserializeValue) {
  CaseService caseService = engine.getCaseService();
  return caseService.getVariableTyped(resourceId, variableKey, deserializeValue);
}
 
Example #27
Source File: ProcessEngineConfigurationImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public CaseService getCaseService() {
  return caseService;
}
 
Example #28
Source File: ProcessEngineConfigurationImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void setCaseService(CaseService caseService) {
  this.caseService = caseService;
}
 
Example #29
Source File: CaseExecutionVariablesResource.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected VariableMap getVariableEntities(boolean deserializeValues) {
  CaseService caseService = engine.getCaseService();
  return caseService.getVariablesTyped(resourceId, deserializeValues);
}
 
Example #30
Source File: ProcessEngineImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public CaseService getCaseService() {
  return caseService;
}