GetProcessDefinitionKey { public static String from(final DelegateTask delegateTask) { Context context = null; String id = null; if (delegateTask.getProcessDefinitionId() != null) { context = Context.bpmn; id = delegateTask.getProcessDefinitionId(); } else { context = cmmn; id = delegateTask.getCaseDefinitionId(); } return new Adapter(context, delegateTask.getProcessEngineServices().getRepositoryService(), id).get(); } private  GetProcessDefinitionKey(); static String from(final DelegateTask delegateTask); static String from(DelegateCaseExecution execution); static String from(DelegateExecution execution);  }
@Test public void cannot_load_process_for_task() throws Exception { when(task.getProcessDefinitionId()).thenReturn("not there!"); thrown.expect(IllegalStateException.class); thrown.expectMessage("bpmn/not there!"); GetProcessDefinitionKey.from(task); }
@Test public void cannot_load_case_for_task() throws Exception { when(task.getCaseDefinitionId()).thenReturn("not there!"); thrown.expect(IllegalStateException.class); thrown.expectMessage("cmmn/not there!"); GetProcessDefinitionKey.from(task); }
@Test public void get_from_caseExecution() throws Exception { caseDefinition("1", "case"); when(caseExecution.getCaseDefinitionId()).thenReturn("1"); assertThat(GetProcessDefinitionKey.from(caseExecution)).isEqualTo("case"); }
@Test public void get_from_execution() throws Exception { processDefinition("1", "proc"); when(execution.getProcessDefinitionId()).thenReturn("1"); assertThat(GetProcessDefinitionKey.from(execution)).isEqualTo("proc"); }
@Test public void get_from_task_via_process() throws Exception { processDefinition("1", "proc"); when(task.getProcessDefinitionId()).thenReturn("1"); assertThat(GetProcessDefinitionKey.from(task)).isEqualTo("proc"); }
@Test public void get_from_task_via_case() throws Exception { caseDefinition("1", "case"); when(task.getCaseDefinitionId()).thenReturn("1"); assertThat(GetProcessDefinitionKey.from(task)).isEqualTo("case"); }