Java Code Examples for org.camunda.bpm.engine.test.Deployment

The following examples show how to use org.camunda.bpm.engine.test.Deployment. These examples are extracted from open source projects. 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 Project: camunda-bpm-assert-scenario   Source File: StartByTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/processes/StartByTest.bpmn"})
public void testStartByKey() {

  when(scenario.waitsAtReceiveTask("ReceiveTask")).thenReturn(new ReceiveTaskAction() {
    @Override
    public void execute(EventSubscriptionDelegate message) throws Exception {
      message.receive();
    }
  });

  Scenario.run(scenario).startByKey("StartByTest").execute();

  verify(scenario, times(1)).hasFinished("StartEvent");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 2
/**
 * Test the happy (approved) path.
 */
@Test
@Deployment(resources = PROCESS_RESOURCE)
public void testApprovedPath() throws Exception {
	// start process
	ProcessInstance pi = runtimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY,
			withVariables(Variable.NAME, "Demo"));
	assertThat(pi).isStarted();

	// check user task and approve user
	assertThat(pi).isWaitingAt("ApproveUser");
	Task task = task();
	assertNotNull("User task expected", task);
	complete(task, withVariables("approved", Boolean.TRUE));

	// check service task (asynchronous continuation)
	execute(job());
	assertThat(pi).hasPassed("ServiceTask_Logger");

	// check corresponding process end
	assertThat(pi).hasPassed("END_APPROVED");
	assertThat(pi).isEnded();

	// verify mocks
	verify(loggerTask, times(1)).execute(any(DelegateExecution.class));
}
 
Example 3
/**
 * Test the not approved path.
 */
@Test
@Deployment(resources = PROCESS_RESOURCE)
public void testNotApprovedPath() throws Exception {
	// start process
	ProcessInstance pi = runtimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY,
			withVariables(Variable.NAME, "Demo"));
	assertThat(pi).isStarted();

	// check user task and do not approve user
	assertThat(pi).isWaitingAt("ApproveUser");
	Task task = task();
	assertNotNull("User task expected", task);
	complete(task, withVariables("approved", Boolean.FALSE));

	// check corresponding process end
	assertThat(pi).hasPassed("END_NOT_APPROVED");
	assertThat(pi).isEnded();

	// verify mocks
	verify(loggerTask, times(0)).execute(any(DelegateExecution.class));

}
 
Example 4
@Test
@Deployment(resources = "processes/mail-poll.bpmn")
public void pollMailWithTextBody() throws MessagingException {
  greenMail.setUser("[email protected]", "bpmn");

  GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", "subject", "text body");

  ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("poll-mails");

  @SuppressWarnings("unchecked")
  List<Mail> mails = (List<Mail>) engineRule.getRuntimeService().getVariable(processInstance.getId(), "mails");

  assertThat(mails)
    .isNotNull()
    .hasSize(1);

  Mail mail = mails.get(0);
  assertThat(mail.getFrom()).isEqualTo("[email protected]");
  assertThat(mail.getSubject()).isEqualTo("subject");
  assertThat(mail.getText()).isEqualTo("text body");
}
 
Example 5
@Test
@Deployment(resources = "processes/mail-send-file.bpmn")
public void sendMailWithFileName() throws Exception {
  File attachment = new File(getClass().getResource("/attachment.txt").toURI());
  assertThat(attachment.exists()).isTrue();

  engineRule.getRuntimeService().startProcessInstanceByKey("send-mail",
      Variables.createVariables().putValue("file", attachment.getPath()));

  MimeMessage[] mails = greenMail.getReceivedMessages();
  assertThat(mails).hasSize(1);

  MimeMessage mail = mails[0];

  assertThat(mail.getContent()).isInstanceOf(MimeMultipart.class);
  MimeMultipart multiPart = (MimeMultipart) mail.getContent();

  assertThat(multiPart.getCount()).isEqualTo(1);
  assertThat(GreenMailUtil.getBody(multiPart.getBodyPart(0))).isEqualTo("plain text");
}
 
Example 6
Source Project: camunda-bpm-mail   Source File: ProcessIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "processes/printProcess.bpmn")
@Test
public void processPrintMail() throws Exception {

  processApplication.startService(engineRule.getProcessEngine());

  TaskQuery taskQuery = taskService.createTaskQuery().taskName("print it");

  // wait for first mail
  while(taskQuery.count() == 0) {
    Thread.sleep(500);
  }

  List<Task> tasks = taskQuery.list();
  assertThat(tasks).isNotEmpty();

  for (Task task : tasks) {
    taskService.complete(task.getId());
  }

  waitForAsyncJobs();

  assertThat(runtimeService.createProcessInstanceQuery().list()).isEmpty();
}
 
Example 7
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/boundary/ConditionalBoundaryEventTest.bpmn"})
public void testConditionInitiallyFalseAndSetTrue() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      rule.getRuntimeService().setVariable(task.getProcessInstance().getId(), "condition", true);
    }
  });

  Scenario.run(scenario)
      .startByKey("ConditionalBoundaryEventTest", variables)
      .execute();

  verify(scenario, times(1)).hasStarted("UserTask");
  verify(scenario, times(1)).hasFinished("UserTask");
  verify(scenario, times(1)).hasFinished("ConditionalBoundaryEvent");
  verify(scenario, never()).hasFinished("EndEventAfterUserTask");
  verify(scenario, times(1)).hasFinished("EndEventAfterBoundaryEvent");

}
 
Example 8
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/boundary/ConditionalBoundaryEventTest.bpmn"})
public void testConditionInitiallyFalseAndCompleteTask() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      task.complete();
    }
  });

  Scenario.run(scenario).startByKey("ConditionalBoundaryEventTest", variables).execute();

  verify(scenario, times(1)).hasStarted("UserTask");
  verify(scenario, times(1)).hasFinished("UserTask");
  verify(scenario, never()).hasFinished("ConditionalBoundaryEvent");
  verify(scenario, times(1)).hasFinished("EndEventAfterUserTask");
  verify(scenario, never()).hasFinished("EndEventAfterBoundaryEvent");

}
 
Example 9
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/boundary/ConditionalBoundaryEventTest.bpmn"})
public void testConditionInitiallyTrueAndCompleteTask() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      task.complete();
    }
  });

  variables.put("condition", true);

  Scenario.run(scenario).startByKey("ConditionalBoundaryEventTest", variables).execute();

  verify(scenario, times(1)).hasStarted("UserTask");
  verify(scenario, times(1)).hasFinished("ConditionalBoundaryEvent");
  verify(scenario, never()).hasFinished("EndEventAfterUserTask");
  verify(scenario, times(1)).hasFinished("EndEventAfterBoundaryEvent");
  verify(scenario, times(1)).hasFinished("UserTask");
  verify(scenario, times(1)).hasCanceled("UserTask");
  verify(scenario, never()).hasCompleted("UserTask");

}
 
Example 10
@Test(expected = Exception.class)
@Deployment(resources = {"org/camunda/bpm/scenario/test/boundary/ConditionalBoundaryEventTest.bpmn"})
public void testDoSomethingDeferred() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(final TaskDelegate task) {
      task.defer("PT3M", new Deferred() {
        @Override
        public void execute() throws Exception {
          throw new Exception(); // expected
        }
      });
    }
  });

  Scenario.run(scenario).startByKey("ConditionalBoundaryEventTest").execute();

}
 
Example 11
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/ConditionalIntermediateEventTest.bpmn"})
public void testTriggerCondition() {

  when(scenario.waitsAtConditionalIntermediateEvent("ConditionalIntermediateEvent")).thenReturn(new ConditionalIntermediateEventAction() {
    @Override
    public void execute(ProcessInstanceDelegate processInstance) {
      Execution execution = rule.getRuntimeService().createExecutionQuery().processInstanceId(processInstance.getId()).activityId("ConditionalIntermediateEvent").singleResult();
      rule.getRuntimeService().signal(execution.getId()); // not encouraged for conditional events, but possible and tested here...
    }
  });

  Scenario.run(scenario).startByKey("ConditionalIntermediateEventTest", variables).execute();

  verify(scenario, times(1)).hasFinished("ConditionalIntermediateEvent");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 12
Source Project: camunda-bpm-assert-scenario   Source File: StartByTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/processes/StartByTest.bpmn"})
public void testStartByStarterMessage2() {

  when(scenario.waitsAtReceiveTask("ReceiveTask")).thenReturn(new ReceiveTaskAction() {
    @Override
    public void execute(EventSubscriptionDelegate message) throws Exception {
      message.receive();
    }
  });

  Scenario.run(scenario).startBy(new ProcessStarter() {
    @Override
    public ProcessInstance start() {
      return rule.getRuntimeService().startProcessInstanceByMessage("msg_StartEvent2");
    }
  }).execute();

  verify(scenario, times(1)).hasFinished("StartEvent2");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 13
Source Project: camunda-bpm-assert-scenario   Source File: UserTaskTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/UserTaskTest.bpmn"})
public void testDoNothing() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      // Deal with task but do nothing here
    }
  });

  Scenario.run(scenario).startByKey("UserTaskTest").execute();

  verify(scenario, times(1)).hasStarted("UserTask");
  verify(scenario, never()).hasFinished("UserTask");
  verify(scenario, never()).hasFinished("EndEvent");

}
 
Example 14
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/timers/BoundaryInterruptingTimerTest.bpmn"})
public void testCompleteTask() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      task.complete();
    }
  });

  Scenario.run(scenario).startByKey("BoundaryInterruptingTimerTest").execute();

  verify(scenario, times(1)).waitsAtUserTask("UserTask");
  verify(scenario, times(1)).hasStarted("UserTask");
  verify(scenario, times(1)).hasFinished("UserTask");
  verify(scenario, times(1)).hasFinished("EndEventCompleted");
  verify(scenario, never()).hasFinished("EndEventCanceled");

}
 
Example 15
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/ConditionalIntermediateEventTest.bpmn"})
public void testConditionInitiallyTrueAndDoNothing() {

  when(scenario.waitsAtConditionalIntermediateEvent("ConditionalIntermediateEvent")).thenReturn(new ConditionalIntermediateEventAction() {
    @Override
    public void execute(ProcessInstanceDelegate processInstance) {
      // Deal with processInstance but do nothing here
    }
  });

  variables.put("condition", true);

  Scenario.run(scenario)
      .startByKey("ConditionalIntermediateEventTest", variables)
      .execute();

  verify(scenario, times(1)).hasFinished("ConditionalIntermediateEvent");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 16
@Test(expected = Exception.class)
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/ConditionalIntermediateEventTest.bpmn"})
public void testDoSomethingDeferred() {

  when(scenario.waitsAtConditionalIntermediateEvent("ConditionalIntermediateEvent")).thenReturn(new ConditionalIntermediateEventAction() {
    @Override
    public void execute(final ProcessInstanceDelegate pi) {
      pi.defer("PT3M", new Deferred() {
        @Override
        public void execute() throws Exception {
          throw new Exception(); // expected
        }
      });
    }
  });

  Scenario.run(scenario).startByKey("ConditionalIntermediateEventTest").execute();

}
 
Example 17
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/EventBasedGatewayTest.bpmn"})
public void testReceiveMessage() {

  when(scenario.waitsAtEventBasedGateway("EventBasedGateway")).thenReturn(new EventBasedGatewayAction() {
    @Override
    public void execute(EventBasedGatewayDelegate gateway) {
      gateway.getEventSubscription("MessageIntermediateCatchEvent").receive();
    }
  });

  Scenario.run(scenario).startByKey("EventBasedGatewayTest", variables).execute();

  verify(scenario, times(1)).hasFinished("EventBasedGateway");
  verify(scenario, times(1)).hasFinished("MessageIntermediateCatchEvent");
  verify(scenario, never()).hasFinished("ConditionalIntermediateEvent");
  verify(scenario, never()).hasFinished("TimerIntermediateEvent");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 18
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/timers/BoundaryInterruptingTimerTest.bpmn"})
public void testDoNothing() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      // Deal with task but do nothing here
    }
  });

  Scenario.run(scenario).startByKey("BoundaryInterruptingTimerTest").execute();

  verify(scenario, times(1)).waitsAtUserTask("UserTask");
  verify(scenario, times(1)).hasStarted("UserTask");
  verify(scenario, times(1)).hasFinished("UserTask");
  verify(scenario, never()).hasFinished("EndEventCompleted");
  verify(scenario, times(1)).hasFinished("EndEventCanceled");

}
 
Example 19
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/EventBasedGatewayTest.bpmn"})
public void testConditionInitiallyFalseThenSetConditionTrue() {

  when(scenario.waitsAtEventBasedGateway("EventBasedGateway")).thenReturn(new EventBasedGatewayAction() {
    @Override
    public void execute(EventBasedGatewayDelegate gateway) {
      rule.getRuntimeService().setVariable(gateway.getProcessInstance().getId(), "condition", true);
    }
  });

  Scenario.run(scenario).startByKey("EventBasedGatewayTest", variables).execute();

  verify(scenario, times(1)).hasFinished("EventBasedGateway");
  verify(scenario, never()).hasFinished("MessageIntermediateCatchEvent");
  verify(scenario, never()).hasFinished("TimerIntermediateEvent");
  verify(scenario, times(1)).hasFinished("ConditionalIntermediateEvent");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 20
Source Project: camunda-bpm-assert-scenario   Source File: StartByTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/processes/StartByTest.bpmn"})
public void testStartByStarterMessage1() {

  when(scenario.waitsAtReceiveTask("ReceiveTask")).thenReturn(new ReceiveTaskAction() {
    @Override
    public void execute(EventSubscriptionDelegate message) throws Exception {
      message.receive();
    }
  });

  Scenario.run(scenario).startBy(new ProcessStarter() {
    @Override
    public ProcessInstance start() {
      return rule.getRuntimeService().startProcessInstanceByMessage("msg_StartEvent1");
    }
  }).execute();

  verify(scenario, times(1)).hasFinished("StartEvent1");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 21
@Test
@Deployment(resources = {
  "org/camunda/bpm/scenario/test/waitstates/CallActivityTest.bpmn",
  "org/camunda/bpm/scenario/test/waitstates/UserTaskTest.bpmn"
})
public void testCompleteCallActivityUserTask() {

  when(scenario.runsCallActivity("CallActivity")).thenReturn(Scenario.use(calledScenario));
  when(calledScenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      task.complete();
    }
  });

  Scenario.run(scenario).startByKey("CallActivityTest").execute();

  verify(calledScenario, times(1)).hasFinished("UserTask");

  verify(scenario, times(1)).hasFinished("EndEvent");
  verify(scenario, times(1)).hasFinished("CallActivity");

}
 
Example 22
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/EventBasedGatewayWithoutTimerTest.bpmn"})
public void testReceiveMessage() {

  when(scenario.waitsAtEventBasedGateway("EventBasedGateway")).thenReturn(new EventBasedGatewayAction() {
    @Override
    public void execute(EventBasedGatewayDelegate gateway) {
      gateway.getEventSubscription("MessageIntermediateCatchEvent").receive();
    }
  });

  Scenario.run(scenario).startByKey("EventBasedGatewayWithoutTimerTest").execute();

  verify(scenario, times(1)).hasFinished("EventBasedGateway");
  verify(scenario, times(1)).hasFinished("MessageIntermediateCatchEvent");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 23
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/EventBasedGatewayWithoutTimerTest.bpmn"})
public void testDoNothing() {

  when(scenario.waitsAtEventBasedGateway("EventBasedGateway")).thenReturn(new EventBasedGatewayAction() {
    @Override
    public void execute(EventBasedGatewayDelegate gateway) {
      // Do nothing means process remains here because of no timers
    }
  });

  Scenario.run(scenario).startByKey("EventBasedGatewayWithoutTimerTest").execute();

  verify(scenario, times(1)).hasStarted("EventBasedGateway");
  verify(scenario, never()).hasFinished("EventBasedGateway");
  verify(scenario, never()).hasFinished("EndEvent");

}
 
Example 24
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/EventBasedGatewayTest.bpmn"})
public void testReceiveMessage() {

  when(scenario.waitsAtEventBasedGateway("EventBasedGateway")).thenReturn(new EventBasedGatewayAction() {
    @Override
    public void execute(EventBasedGatewayDelegate gateway) {
      gateway.getEventSubscription("MessageIntermediateCatchEvent").receive();
    }
  });

  Scenario.run(scenario).startByKey("EventBasedGatewayTest").execute();

  verify(scenario, times(1)).hasFinished("EventBasedGateway");
  verify(scenario, times(1)).hasFinished("MessageIntermediateCatchEvent");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 25
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/EventBasedGatewayTest.bpmn"})
public void testDoNothing() {

  when(scenario.waitsAtEventBasedGateway("EventBasedGateway")).thenReturn(new EventBasedGatewayAction() {
    @Override
    public void execute(EventBasedGatewayDelegate gateway) {
      // Do nothing means process moves forward because of the timers
    }
  });

  Scenario.run(scenario).startByKey("EventBasedGatewayTest").execute();

  verify(scenario, times(1)).hasFinished("TimerIntermediateEvent");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 26
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/ReceiveTaskTest.bpmn"})
public void testReceiveMessage() {

  when(scenario.waitsAtReceiveTask("ReceiveTask")).thenReturn(new ReceiveTaskAction() {
    @Override
    public void execute(EventSubscriptionDelegate messageEventSubscription) {
      messageEventSubscription.receive();
    }
  });

  Scenario.run(scenario).startByKey("ReceiveTaskTest").execute();

  verify(scenario, times(1)).hasFinished("ReceiveTask");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 27
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/waitstates/ReceiveTaskTest.bpmn"})
public void testDoNothing() {

  when(scenario.waitsAtReceiveTask("ReceiveTask")).thenReturn(new ReceiveTaskAction() {
    @Override
    public void execute(EventSubscriptionDelegate messageEventSubscription) {
      // Deal with messageEventSubscription but do nothing here
    }
  });

  Scenario.run(scenario).startByKey("ReceiveTaskTest").execute();

  verify(scenario, times(1)).hasStarted("ReceiveTask");
  verify(scenario, never()).hasFinished("ReceiveTask");
  verify(scenario, never()).hasFinished("EndEvent");

}
 
Example 28
Source Project: camunda-bpm-assert-scenario   Source File: StartByTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/processes/StartByTest.bpmn"})
public void testStartByMessage2() {

  when(scenario.waitsAtReceiveTask("ReceiveTask")).thenReturn(new ReceiveTaskAction() {
    @Override
    public void execute(EventSubscriptionDelegate message) throws Exception {
      message.receive();
    }
  });

  Scenario.run(scenario).startByMessage("msg_StartEvent2").execute();

  verify(scenario, times(1)).hasFinished("StartEvent2");
  verify(scenario, times(1)).hasFinished("EndEvent");

}
 
Example 29
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/timers/EventSubprocessInterruptingTimerTest.bpmn"})
public void testCompleteTask() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      task.complete();
    }
  });

  Scenario.run(scenario).startByKey("EventSubprocessInterruptingTimerTest").execute();

  verify(scenario, times(1)).waitsAtUserTask("UserTask");
  verify(scenario, times(1)).hasStarted("UserTask");
  verify(scenario, times(1)).hasFinished("UserTask");
  verify(scenario, times(1)).hasFinished("EndEventCompleted");
  verify(scenario, never()).hasFinished("EndEventCanceled");

}
 
Example 30
@Test
@Deployment(resources = {"org/camunda/bpm/scenario/test/timers/EventSubprocessInterruptingTimerTest.bpmn"})
public void testExactlyReachingMaximalTimeForTask() {

  when(scenario.waitsAtUserTask("UserTask")).thenReturn(new UserTaskAction() {
    @Override
    public void execute(TaskDelegate task) {
      task.defer("PT5M", new Deferred() {
        @Override
        public void execute() {
          // do nothing
        }
      });
    }
  });

  Scenario.run(scenario).startByKey("EventSubprocessInterruptingTimerTest").execute();

  verify(scenario, times(1)).waitsAtUserTask("UserTask");
  verify(scenario, times(1)).hasStarted("UserTask");
  verify(scenario, times(1)).hasFinished("UserTask");
  verify(scenario, never()).hasFinished("EndEventCompleted");
  verify(scenario, times(1)).hasFinished("EndEventCanceled");

}