@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionKey_shouldSuspendJob() {
// given
// a deployed process definition
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
// a running process instance with a failed job
Map<String, Object> params = new HashMap<String, Object>();
params.put("fail", Boolean.TRUE);
runtimeService.startProcessInstanceByKey("suspensionProcess", params);
// the failed job
JobQuery jobQuery = managementService.createJobQuery();
Job job = jobQuery.singleResult();
assertFalse(job.isSuspended());
// when
// the job will be suspended
managementService.suspendJobByProcessDefinitionKey(processDefinition.getKey());
// then
// the job should be suspended
assertEquals(0, jobQuery.active().count());
assertEquals(1, jobQuery.suspended().count());