TopologyMgmtResourceImpl { public List<TopologyStatus> getTopologies() throws Exception { List<Topology> topologyDefinitions = dao.listTopologies(); List<StreamingCluster> clusters = dao.listClusters(); List<TopologyStatus> topologies = new ArrayList<>(); for (Topology topologyDef : topologyDefinitions) { TopologySummary topologySummary = getTopologySummery(clusters, topologyDef); if (topologySummary != null) { TopologyStatus t = new TopologyStatus(); t.setName(topologySummary.get_name()); t.setId(topologySummary.get_id()); t.setState(topologySummary.get_status()); t.setTopology(topologyDef); topologies.add(t); } } return topologies; }  void startTopology(String topologyName); void stopTopology(String topologyName); List<TopologyStatus> getTopologies();  }
@Ignore @Test public void testGetTopologies() throws Exception { topologyManager.startTopology(topologyName); Thread.sleep(10000); List<TopologyStatus> topologies = topologyManager.getTopologies(); Assert.assertTrue(topologies.size() == 1); }
@Test public void testGetTopologies1() throws Exception { IMetadataDao dao = MetadataDaoFactory.getInstance().getMetadataDao(); TopologyMgmtResourceImpl service = new TopologyMgmtResourceImpl(); Field daoField = TopologyMgmtResourceImpl.class.getDeclaredField("dao"); daoField.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(daoField, daoField.getModifiers() & ~Modifier.FINAL); daoField.set(null, dao); Topology topology = new Topology("test", 1, 1); StreamingCluster cluster =new StreamingCluster(); dao.clear(); dao.addTopology(topology); dao.addCluster(cluster); TopologyMgmtResourceImpl spy = PowerMockito.spy(service); PowerMockito.doReturn(new TopologySummary()).when(spy,"getTopologySummery", Mockito.anyCollection(), Mockito.any(Topology.class)); Assert.assertEquals(1, spy.getTopologies().size()); }