Search in sources :

Example 1 with GraphMLPropagateVertexStatusProvider

use of org.opennms.features.topology.plugins.topo.graphml.status.GraphMLPropagateVertexStatusProvider 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);
}
Also used : Date(java.util.Date) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) GraphMLReader(org.opennms.features.graphml.model.GraphMLReader) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) GraphMLPropagateVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLPropagateVertexStatusProvider) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) Map(java.util.Map) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) ServiceReference(org.osgi.framework.ServiceReference) Before(org.junit.Before) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) NodeDao(org.opennms.netmgt.dao.api.NodeDao) JUnitConfigurationEnvironment(org.opennms.test.JUnitConfigurationEnvironment) Resources(com.google.common.io.Resources) ImmutableMap(com.google.common.collect.ImmutableMap) ScriptEngineManager(javax.script.ScriptEngineManager) Test(org.junit.Test) GraphML(org.opennms.features.graphml.model.GraphML) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) BeanUtils(org.opennms.core.spring.BeanUtils) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) Rule(org.junit.Rule) OpenNMSJUnit4ClassRunner(org.opennms.core.test.OpenNMSJUnit4ClassRunner) GraphMLDefaultVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider) Paths(java.nio.file.Paths) GraphMLVertexStatus(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLVertexStatus) AlarmSummaryWrapper(org.opennms.features.topology.plugins.topo.graphml.internal.AlarmSummaryWrapper) TransactionOperations(org.springframework.transaction.support.TransactionOperations) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Criteria(org.opennms.features.topology.api.topo.Criteria) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Status(org.opennms.features.topology.api.topo.Status) GraphMLScriptVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider) Assert(org.junit.Assert) VertexRef(org.opennms.features.topology.api.topo.VertexRef) TemporaryFolder(org.junit.rules.TemporaryFolder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) GraphMLPropagateVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLPropagateVertexStatusProvider) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) GraphMLDefaultVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider) GraphMLScriptVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider) GraphMLDefaultVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLDefaultVertexStatusProvider) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) File(java.io.File) GraphMLPropagateVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLPropagateVertexStatusProvider) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Files (com.google.common.io.Files)1 Resources (com.google.common.io.Resources)1 File (java.io.File)1 Paths (java.nio.file.Paths)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 ScriptEngineManager (javax.script.ScriptEngineManager)1 EasyMock (org.easymock.EasyMock)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 TemporaryFolder (org.junit.rules.TemporaryFolder)1 RunWith (org.junit.runner.RunWith)1 BeanUtils (org.opennms.core.spring.BeanUtils)1