@Test
public void testSpawnSampleProcessForLocalhost() throws Exception {

    DelegateExecution execution = mock(DelegateExecution.class);
    when(execution.getVariable(eq(CoreProcessVariables.POOL))).thenReturn(mock(Pool.class));
    when(execution.getVariable(eq(CoreProcessVariables.POOL_BUSINESS_KEY))).thenReturn(BUSINESS_KEY);
    List<Machine> machines = Lists.newArrayList(
        Machine.builder().localhost().createMachine(),
        Machine.builder().localhost().externalId("local-2").createMachine()
    );
    when(execution.getVariable(eq(CoreProcessVariables.MACHINES))).thenReturn(machines);
    ProcessVariablesCollector collector = new ProcessVariablesCollector();
    collector.install(execution);
    ProcessEngine processEngine = new StandaloneInMemProcessEngineConfiguration()
        .setJobExecutorActivate(true).buildProcessEngine();
    processEngine.getRepositoryService().createDeployment()
        .addClasspathResource("diagrams/empty.bpmn20.xml").deploy();
    try {
        JavaDelegate delegate = new SpawnProcessForEachMachine(processEngine, EMPTY_PROCESS_KEY, "test", RESULT);
        delegate.execute(execution);
        @SuppressWarnings("unchecked")
        List<String> processInstanceIds = (List<String>) collector.getVariable(RESULT);
        assertThat(processInstanceIds).hasSize(2);
    } finally {
        processEngine.close();
    }
}