Java Code Examples for org.camunda.bpm.engine.test.mock.Mocks#register()

The following examples show how to use org.camunda.bpm.engine.test.mock.Mocks#register() . 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: MocksTest.java    From camunda-bpm-platform with Apache License 2.0 7 votes vote down vote up
private void testMockAvailability() {
  //given
  final String testStr = "testValue";

  Mocks.register("myMock", new Object() {

    public String getTest() {
      return testStr;
    }

    public void testMethod(DelegateExecution execution, String str) {
      execution.setVariable("testVar", str);
    }

  });

  //when
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("mocksTest");
  Mocks.reset();

  //then
  assertEquals(testStr, runtimeService.getVariable(pi.getId(), "testVar"));
}
 
Example 2
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testTaskQueryByBusinessKeyExpression() {
  // given
  String aBusinessKey = "business key";
  Mocks.register("aBusinessKey", aBusinessKey);

  createDeploymentWithBusinessKey(aBusinessKey);

  // when
  TaskQueryImpl extendedQuery = (TaskQueryImpl)taskService.createTaskQuery()
    .processInstanceBusinessKeyExpression("${ " + Mocks.getMocks().keySet().toArray()[0] + " }");

  Filter filter = filterService.newTaskFilter("aFilterName");
  filter.setQuery(extendedQuery);
  filterService.saveFilter(filter);

  TaskQueryImpl filterQuery = filterService.getFilter(filter.getId()).getQuery();

  // then
  assertEquals(extendedQuery.getExpressions().get("processInstanceBusinessKey"),
    filterQuery.getExpressions().get("processInstanceBusinessKey"));
  assertEquals(1, filterService.list(filter.getId()).size());
}
 
Example 3
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testTaskQueryByBusinessKeyExpressionInAdhocQuery() {
  // given
  processEngineConfiguration.setEnableExpressionsInAdhocQueries(true);

  String aBusinessKey = "business key";
  Mocks.register("aBusinessKey", aBusinessKey);

  createDeploymentWithBusinessKey(aBusinessKey);

  // when
  Filter filter = filterService.newTaskFilter("aFilterName");
  filter.setQuery(taskService.createTaskQuery());
  filterService.saveFilter(filter);

  TaskQueryImpl extendingQuery = (TaskQueryImpl)taskService.createTaskQuery()
    .processInstanceBusinessKeyExpression("${ " + Mocks.getMocks().keySet().toArray()[0] + " }");

  // then
  assertEquals(extendingQuery.getExpressions().get("processInstanceBusinessKey"),
    "${ " + Mocks.getMocks().keySet().toArray()[0] + " }");
  assertEquals(1, filterService.list(filter.getId(), extendingQuery).size());
}
 
Example 4
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testTaskQueryByBusinessKeyLikeExpression() {
  // given
  String aBusinessKey = "business key";
  Mocks.register("aBusinessKeyLike", "%" + aBusinessKey.substring(5));

  createDeploymentWithBusinessKey(aBusinessKey);

  // when
  TaskQueryImpl extendedQuery = (TaskQueryImpl)taskService.createTaskQuery()
    .processInstanceBusinessKeyLikeExpression("${ " + Mocks.getMocks().keySet().toArray()[0] + " }");

  Filter filter = filterService.newTaskFilter("aFilterName");
  filter.setQuery(extendedQuery);
  filterService.saveFilter(filter);

  TaskQueryImpl filterQuery = filterService.getFilter(filter.getId()).getQuery();

  // then
  assertEquals(extendedQuery.getExpressions().get("processInstanceBusinessKeyLike"),
    filterQuery.getExpressions().get("processInstanceBusinessKeyLike"));
  assertEquals(1, filterService.list(filter.getId()).size());
}
 
Example 5
Source File: FilterTaskQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testTaskQueryByBusinessKeyLikeExpressionInAdhocQuery() {
  // given
  processEngineConfiguration.setEnableExpressionsInAdhocQueries(true);

  String aBusinessKey = "business key";
  Mocks.register("aBusinessKeyLike", "%" + aBusinessKey.substring(5));

  createDeploymentWithBusinessKey(aBusinessKey);

  // when
  Filter filter = filterService.newTaskFilter("aFilterName");
  filter.setQuery(taskService.createTaskQuery());
  filterService.saveFilter(filter);

  TaskQueryImpl extendingQuery = (TaskQueryImpl)taskService.createTaskQuery()
    .processInstanceBusinessKeyLikeExpression("${ " + Mocks.getMocks().keySet().toArray()[0] + " }");

  // then
  assertEquals(extendingQuery.getExpressions().get("processInstanceBusinessKeyLike"),
    "${ " + Mocks.getMocks().keySet().toArray()[0] + " }");
  assertEquals(1, filterService.list(filter.getId(), extendingQuery).size());
}
 
Example 6
Source File: ProcessLocalTest.java    From camunda-bpm-identity-keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Setup the test case.
 */
@Before
public void setup() {
	// Initialize and register mocks
	MockitoAnnotations.initMocks(this);
	Mocks.register("logger", loggerTask);

	// Initialize BPM Assert
	init(rule.getProcessEngine());
}
 
Example 7
Source File: TaskQueryExpressionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByProcessInstanceBusinessKeyExpression() {
  // given
  String aBusinessKey = "business key";
  Mocks.register("aBusinessKey", aBusinessKey);

  createBusinessKeyDeployment(aBusinessKey);

  // when
  TaskQuery taskQuery = taskQuery()
    .processInstanceBusinessKeyExpression("${ " + Mocks.getMocks().keySet().toArray()[0] + " }");

  // then
  assertCount(taskQuery, 1);
}
 
Example 8
Source File: TaskQueryExpressionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByProcessInstanceBusinessKeyLikeExpression() {
  // given
  String aBusinessKey = "business key";
  Mocks.register("aBusinessKeyLike", "%" + aBusinessKey.substring(5));

  createBusinessKeyDeployment(aBusinessKey);

  // when
  TaskQuery taskQuery = taskQuery()
    .processInstanceBusinessKeyLikeExpression("${ " + Mocks.getMocks().keySet().toArray()[0] + " }");

  // then
  assertCount(taskQuery, 1);
}
 
Example 9
Source File: StartTimerEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testInterruptingWithDurationExpression() {
  // given
  Mocks.register("duration", "PT60S");

  ProcessBuilder processBuilder = Bpmn.createExecutableProcess("process");

  BpmnModelInstance modelInstance = processBuilder
    .startEvent().timerWithDuration("${duration}")
      .userTask("aTaskName")
    .endEvent()
    .done();

  deploymentId = repositoryService.createDeployment()
    .addModelInstance("process.bpmn", modelInstance).deploy()
    .getId();

  // when
  String jobId = managementService.createJobQuery()
    .singleResult()
    .getId();

  managementService.executeJob(jobId);

  // then
  assertEquals(1, taskService.createTaskQuery().taskName("aTaskName").list().size());

  // cleanup
  Mocks.reset();
}
 
Example 10
Source File: AbstractTest.java    From camunda-bpm-assert-scenario with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  MockitoAnnotations.initMocks(this);
  Mocks.register("javaDelegate", mock(JavaDelegate.class));
}
 
Example 11
Source File: StartTimerEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void testRecalculateTimeCycleExpressionCurrentDateBased() throws Exception {
  // given
  Mocks.register("cycle", "R/PT15M");

  ProcessBuilder processBuilder = Bpmn.createExecutableProcess("process");

  BpmnModelInstance modelInstance = processBuilder
    .startEvent().timerWithCycle("${cycle}")
      .userTask("aTaskName")
    .endEvent()
    .done();

  deploymentId = repositoryService.createDeployment()
    .addModelInstance("process.bpmn", modelInstance).deploy()
    .getId();
  
  JobQuery jobQuery = managementService.createJobQuery();
  assertEquals(1, jobQuery.count());

  Job job = jobQuery.singleResult();
  String jobId = job.getId();
  Date oldDuedate = job.getDuedate();

  // when
  moveByMinutes(1);
  managementService.recalculateJobDuedate(jobId, false);

  // then
  Job jobUpdated = jobQuery.singleResult();
  assertEquals(jobId, jobUpdated.getId());
  assertNotEquals(oldDuedate, jobUpdated.getDuedate());
  assertTrue(oldDuedate.before(jobUpdated.getDuedate()));
  
  // when
  Mocks.register("cycle", "R/PT10M");
  managementService.recalculateJobDuedate(jobId, false);

  // then
  jobUpdated = jobQuery.singleResult();
  assertEquals(jobId, jobUpdated.getId());
  assertNotEquals(oldDuedate, jobUpdated.getDuedate());
  assertTrue(oldDuedate.after(jobUpdated.getDuedate()));
  
  Mocks.reset();
}
 
Example 12
Source File: StartTimerEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void testRecalculateTimeCycleExpressionCreationDateBased() throws Exception {
  // given
  Mocks.register("cycle", "R/PT15M");

  ProcessBuilder processBuilder = Bpmn.createExecutableProcess("process");

  BpmnModelInstance modelInstance = processBuilder
    .startEvent().timerWithCycle("${cycle}")
      .userTask("aTaskName")
    .endEvent()
    .done();

  deploymentId = repositoryService.createDeployment()
    .addModelInstance("process.bpmn", modelInstance).deploy()
    .getId();
  
  JobQuery jobQuery = managementService.createJobQuery();
  assertEquals(1, jobQuery.count());

  Job job = jobQuery.singleResult();
  String jobId = job.getId();
  Date oldDuedate = job.getDuedate();

  // when
  moveByMinutes(1);
  managementService.recalculateJobDuedate(jobId, true);

  // then
  Job jobUpdated = jobQuery.singleResult();
  assertEquals(jobId, jobUpdated.getId());
  Date expectedDate = LocalDateTime.fromDateFields(jobUpdated.getCreateTime()).plusMinutes(15).toDate();
  assertEquals(expectedDate, jobUpdated.getDuedate());
  
  // when
  Mocks.register("cycle", "R/PT10M");
  managementService.recalculateJobDuedate(jobId, true);

  // then
  jobUpdated = jobQuery.singleResult();
  assertEquals(jobId, jobUpdated.getId());
  assertNotEquals(oldDuedate, jobUpdated.getDuedate());
  assertTrue(oldDuedate.after(jobUpdated.getDuedate()));
  expectedDate = LocalDateTime.fromDateFields(jobUpdated.getCreateTime()).plusMinutes(10).toDate();
  assertEquals(expectedDate, jobUpdated.getDuedate());
  
  Mocks.reset();
}