JPSServiceStatusProvider extends ServiceProvider { @Override public Map<String, Boolean> getServiceStatus(List<ComponentService> services) { Result rs = new Result(); try { rs = CommandExecutor.executeCommand(COMMAND_JPS); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } String[] outlines = rs.getOutput().split(LINE_SEPERATOR); Set<String> processes = new HashSet<String>(); for (String line : outlines) { String pIdName[] = line.split(" "); if (pIdName.length == 2) { processes.add(pIdName[1].toLowerCase()); } } Map<String, Boolean> serviceStatus = new HashMap<String, Boolean>(); for (ComponentService service : services) { serviceStatus.put( service.getRole(), processes.contains(service.getName().toString() .toLowerCase())); } LOGGER.info("Service Status " + serviceStatus); return serviceStatus; }  @Override Map<String, Boolean> getServiceStatus(List<ComponentService> services);  }
@Test public void testGetServiceStatusForEmptyServiceList() throws Exception { List<ComponentService> services = new LinkedList(); Map<String, Boolean> result = fixture.getServiceStatus(services); assertNotNull(result); assertEquals(0, result.size()); }
@Test public void testGetServiceStatusForJPSService() throws Exception { ComponentService cs = new ComponentService(JPS, JPS, JPS); List<ComponentService> services = new LinkedList(); services.add(cs); Map<String, Boolean> result = fixture.getServiceStatus(services); assertNotNull(result); assertEquals(1, result.size()); assertNotNull(result.get(JPS)); }