Search in sources :

Example 1 with GraphMLScriptVertexStatusProvider

use of org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider in project opennms by OpenNMS.

the class GraphMLVertexStatusProviderIT method testScriptStatusProvider.

@Test
public void testScriptStatusProvider() throws InvalidGraphException {
    GraphML graphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph.xml"));
    GraphMLTopologyProvider topologyProvider = new GraphMLTopologyProvider(null, graphML.getGraphs().get(0), new GraphMLServiceAccessor());
    GraphMLScriptVertexStatusProvider statusProvider = new GraphMLScriptVertexStatusProvider(topologyProvider.getNamespace(), this.alarmSummaryWrapper, new ScriptEngineManager(), this.serviceAccessor, Paths.get("src", "test", "opennms-home", "etc", "graphml-vertex-status"));
    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.NORMAL, 0), createVertexRef(topologyProvider.getNamespace(), "south"), createStatus(OnmsSeverity.WARNING, 42), createVertexRef(topologyProvider.getNamespace(), "east"), createStatus(OnmsSeverity.CRITICAL, 23)), 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) GraphML(org.opennms.features.graphml.model.GraphML) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) ScriptEngineManager(javax.script.ScriptEngineManager) GraphMLScriptVertexStatusProvider(org.opennms.features.topology.plugins.topo.graphml.status.GraphMLScriptVertexStatusProvider) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) 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