RundeckServlet extends HttpServlet { @VisibleForTesting void writeRundeckResourceModelXmlTo(PrintWriter writer) { final List<ProcessInstance> processes = processEngine.getRuntimeService() .createProcessInstanceQuery().list(); Project project = new Project(); for (ProcessInstance instance : processes) { final Pool pool = (Pool) processEngine.getRuntimeService() .getVariable(instance.getId(), CoreProcessVariables.POOL); if (pool == null) { continue; } final String businessKey = (String) processEngine.getRuntimeService() .getVariable(instance.getId(), CoreProcessVariables.POOL_BUSINESS_KEY); if (!Objects.equal(instance.getBusinessKey(), businessKey)) { continue; } @SuppressWarnings("unchecked") List<Machine> machines = (List<Machine>) processEngine.getRuntimeService() .getVariable(instance.getId(), CoreProcessVariables.MACHINES); if (machines == null) { continue; } project.setNodes(transformMachinesToRundeckNodes(businessKey, pool, machines)); } try { marshaller.marshal(project, writer); } catch (JAXBException e) { throw Throwables.propagate(e); } } RundeckServlet(ProcessEngine processEngine);   }
@Test public void testEmptyListOfMachines() throws JAXBException, IOException, SAXException { ProcessEngine processEngine = new StandaloneInMemProcessEngineConfiguration().buildProcessEngine(); try { RundeckServlet servlet = new RundeckServlet(processEngine); servlet.writeRundeckResourceModelXmlTo(writer); writer.flush(); assertXMLEqual(output.toString(), "<project />"); } finally { processEngine.close(); } }