StormStatusServiceImpl implements StormStatusService { @Override public TopologyResponse activateTopology(String name) { TopologyResponse topologyResponse = new TopologyResponse(); String id = getTopologyId(name); if (id != null) { Map result = restTemplate .postForObject(getStormUiProperty() + TOPOLOGY_URL + "/" + id + "/activate", null, Map.class); if ("success".equals(result.get("status"))) { topologyResponse.setSuccessMessage(TopologyStatusCode.ACTIVE.toString()); } else { topologyResponse.setErrorMessage((String) result.get("status")); } } else { topologyResponse.setErrorMessage(TopologyStatusCode.TOPOLOGY_NOT_FOUND.toString()); } return topologyResponse; } @Autowired  StormStatusServiceImpl(Environment environment, RestTemplate restTemplate, SensorParserGroupService sensorParserGroupService); @Override SupervisorSummary getSupervisorSummary(); @Override TopologySummary getTopologySummary(); @Override TopologyStatus getTopologyStatus(String name); @Override List<TopologyStatus> getAllTopologyStatus(); @Override TopologyResponse activateTopology(String name); @Override TopologyResponse deactivateTopology(String name);  }
@Test public void activateTopologyShouldReturnActiveTopologyResponse() throws Exception { final TopologyStatus topologyStatus = new TopologyStatus(); topologyStatus.setName("bro"); topologyStatus.setId("bro_id"); final TopologySummary topologySummary = new TopologySummary(); topologySummary.setTopologies(new TopologyStatus[]{topologyStatus}); when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI); when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary); when(restTemplate.postForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_id/activate", null, Map.class)) .thenReturn(new HashMap() {{ put("status", "success"); }}); TopologyResponse expected = new TopologyResponse(); expected.setSuccessMessage(TopologyStatusCode.ACTIVE.toString()); assertEquals(expected, stormStatusService.activateTopology("bro")); }
@Test public void activateTopologyShouldReturnErrorTopologyResponse() throws Exception { final TopologyStatus topologyStatus = new TopologyStatus(); topologyStatus.setName("bro"); topologyStatus.setId("bro_id"); final TopologySummary topologySummary = new TopologySummary(); topologySummary.setTopologies(new TopologyStatus[]{topologyStatus}); when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI); when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary); when(restTemplate.postForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_id/activate", null, Map.class)) .thenReturn(new HashMap() {{ put("status", "error message"); }}); TopologyResponse expected = new TopologyResponse(); expected.setErrorMessage("error message"); assertEquals(expected, stormStatusService.activateTopology("bro")); }
@Test public void activateTopologyShouldReturnTopologyNotFoundTopologyResponse() throws Exception { when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI); when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(new TopologySummary()); TopologyResponse expected = new TopologyResponse(); expected.setErrorMessage(TopologyStatusCode.TOPOLOGY_NOT_FOUND.toString()); assertEquals(expected, stormStatusService.activateTopology("bro")); }