use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderIT method testPropagateStatusProvider.
@Test
public void testPropagateStatusProvider() throws Exception {
final File graphXml = this.tempFolder.newFile();
Resources.asByteSource(Resources.getResource("test-graph.xml")).copyTo(Files.asByteSink(graphXml));
final GraphMLMetaTopologyProvider metaTopoProvider = new GraphMLMetaTopologyProvider(new GraphMLServiceAccessor());
metaTopoProvider.setTopologyLocation(graphXml.getAbsolutePath());
metaTopoProvider.reload();
final GraphMLTopologyProvider childTopologyProvider = metaTopoProvider.getRawTopologyProvider("acme:markets");
final GraphMLDefaultVertexStatusProvider childStatusProvider = new GraphMLDefaultVertexStatusProvider(childTopologyProvider.getNamespace(), this.alarmSummaryWrapper);
final ServiceReference<StatusProvider> statusProviderReference = EasyMock.niceMock(ServiceReference.class);
final BundleContext bundleContext = EasyMock.niceMock(BundleContext.class);
EasyMock.expect(bundleContext.getServiceReferences(StatusProvider.class, null)).andReturn(ImmutableList.of(statusProviderReference)).anyTimes();
EasyMock.expect(bundleContext.getService(statusProviderReference)).andReturn(childStatusProvider);
EasyMock.replay(statusProviderReference, bundleContext);
final GraphMLTopologyProvider topologyProvider = metaTopoProvider.getRawTopologyProvider("acme:regions");
final GraphMLPropagateVertexStatusProvider statusProvider = new GraphMLPropagateVertexStatusProvider(topologyProvider.getNamespace(), metaTopoProvider, bundleContext);
List<VertexRef> vertices = topologyProvider.getVertices().stream().map(eachVertex -> (VertexRef) eachVertex).collect(Collectors.toList());
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(topologyProvider.getNamespace(), statusProvider.getNamespace());
Assert.assertTrue(statusProvider.contributesTo(topologyProvider.getNamespace()));
Map<? extends VertexRef, ? extends Status> statusForVertices = statusProvider.getStatusForVertices(topologyProvider, vertices, new Criteria[0]);
Assert.assertEquals(4, statusForVertices.size());
Assert.assertEquals(ImmutableMap.of(createVertexRef(topologyProvider.getNamespace(), "north"), createStatus(OnmsSeverity.NORMAL, 0), createVertexRef(topologyProvider.getNamespace(), "west"), createStatus(OnmsSeverity.MAJOR, 4), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.NORMAL, 0), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.CRITICAL, 11)), statusForVertices);
}
use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderIT method testDefaultStatusProvider.
@Test
public void testDefaultStatusProvider() throws InvalidGraphException {
GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graphML.getGraphs().get(0), new GraphMLServiceAccessor());
GraphMLDefaultVertexStatusProvider statusProvider = new GraphMLDefaultVertexStatusProvider(topologyProvider.getNamespace(), this.alarmSummaryWrapper);
List<VertexRef> vertices = topologyProvider.getVertices().stream().map(eachVertex -> (VertexRef) eachVertex).collect(Collectors.toList());
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(topologyProvider.getNamespace(), statusProvider.getNamespace());
Assert.assertTrue(statusProvider.contributesTo(topologyProvider.getNamespace()));
Map<? extends VertexRef, ? extends Status> statusForVertices = statusProvider.getStatusForVertices(topologyProvider, vertices, new Criteria[0]);
Assert.assertEquals(4, statusForVertices.size());
Assert.assertEquals(ImmutableMap.of(createVertexRef(topologyProvider.getNamespace(), "north"), createStatus(OnmsSeverity.WARNING, 1), createVertexRef(topologyProvider.getNamespace(), "west"), createStatus(OnmsSeverity.MINOR, 2), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.MAJOR, 3), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.NORMAL, 0)), statusForVertices);
}
use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.
the class GraphMLSearchProviderTest method verifyContributesTo.
@Test
public void verifyContributesTo() {
GraphMLGraph graph = new GraphMLGraph();
graph.setProperty(GraphMLProperties.NAMESPACE, "namespace1:graph1");
GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graph, new GraphMLServiceAccessor());
GraphMLSearchProvider searchProvider = new GraphMLSearchProvider(topologyProvider);
Assert.assertEquals(true, searchProvider.contributesTo("namespace1:graph1"));
Assert.assertEquals(true, searchProvider.contributesTo("namespace1:graph2"));
Assert.assertEquals(true, searchProvider.contributesTo("namespace1:graph3"));
Assert.assertEquals(false, searchProvider.contributesTo("namespace1"));
}
use of org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor in project opennms by OpenNMS.
the class GraphMLVertexStatusProviderIT method before.
@Before
public void before() {
BeanUtils.assertAutowiring(this);
this.databasePopulator.populateDatabase();
this.serviceAccessor = new GraphMLServiceAccessor();
this.serviceAccessor.setTransactionOperations(this.transactionOperations);
this.serviceAccessor.setNodeDao(this.nodeDao);
this.serviceAccessor.setSnmpInterfaceDao(this.snmpInterfaceDao);
this.serviceAccessor.setMeasurementsService(request -> new QueryResponse());
this.alarmSummaryWrapper = nodeIds -> Lists.newArrayList(createSummary(1, "North", OnmsSeverity.WARNING, 1), createSummary(2, "West", OnmsSeverity.MINOR, 2), createSummary(3, "South", OnmsSeverity.MAJOR, 3), createSummary(4, "West 2", OnmsSeverity.MAJOR, 4), createSummary(5, "East 1", OnmsSeverity.CRITICAL, 5), createSummary(6, "East 2", OnmsSeverity.WARNING, 6));
}
Aggregations