Search in sources :

Example 1 with NodeBuilder

use of org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder in project opennms by OpenNMS.

the class AssetGraphGeneratorTest method verifySimpleGraphGeneration.

@Test
public void verifySimpleGraphGeneration() throws InvalidGraphException {
    final NodeProvider nodeProvider = new NodeProvider() {

        @Override
        public List<OnmsNode> getNodes(List<LayerDefinition> definitions) {
            List<OnmsNode> nodes = new ArrayList<>();
            nodes.add(new NodeBuilder().withId(1).withLabel("Node 1").withAssets().withRegion("Stuttgart").withBuilding("S1").done().getNode());
            nodes.add(new NodeBuilder().withId(2).withLabel("Node 2").withAssets().withRegion("Stuttgart").withBuilding("S2").done().getNode());
            nodes.add(new NodeBuilder().withId(3).withLabel("Node 3").withAssets().withRegion("Fulda").withBuilding("F1").done().getNode());
            nodes.add(new NodeBuilder().withId(4).withLabel("Node 4").withAssets().withRegion("Frankfurt").withBuilding("F1").done().getNode());
            nodes.add(new NodeBuilder().withId(5).withLabel("Node 5").withAssets().withRegion("Frankfurt").withBuilding("F2").done().getNode());
            nodes.add(new NodeBuilder().withId(6).withLabel("Node 6").withAssets().withRegion("Frankfurt").done().getNode());
            nodes.add(new NodeBuilder().withId(7).withLabel("Node 7").withAssets().withBuilding("F2").done().getNode());
            return nodes;
        }
    };
    final GeneratorConfig config = new GeneratorConfig();
    config.setLayerHierarchies(Lists.newArrayList(NodeParamLabels.ASSET_REGION, NodeParamLabels.ASSET_BUILDING));
    // empty filters
    config.setFilters(new ArrayList<>());
    final GraphML generatedGraphML = new AssetGraphGenerator(nodeProvider).generateGraphs(config);
    final GraphML expectedGraphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph-simple.xml"));
    // for debug generate file
    GraphMLWriter.write(generatedGraphML, new File("target/verifySimpleGraphGenerationGenerated.graphml"));
    Assert.assertEquals(generatedGraphML, expectedGraphML);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) GraphML(org.opennms.features.graphml.model.GraphML) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TestNodeProvider(org.opennms.features.topology.plugins.topo.asset.util.TestNodeProvider) NodeBuilder(org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder) File(java.io.File) Test(org.junit.Test)

Example 2 with NodeBuilder

use of org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder in project opennms by OpenNMS.

the class AssetGraphGeneratorTest method verifyFilter.

@Test
public void verifyFilter() throws InvalidGraphException {
    final NodeProvider nodeProvider = new NodeProvider() {

        @Override
        public List<OnmsNode> getNodes(List<LayerDefinition> definitions) {
            List<OnmsNode> nodes = new ArrayList<>();
            nodes.add(new NodeBuilder().withId(1).withLabel("Node 1").withAssets().withRegion("Stuttgart").withBuilding("S1").done().getNode());
            nodes.add(new NodeBuilder().withId(2).withLabel("Node 2").withAssets().withRegion("Fulda").withBuilding("F1").done().getNode());
            return nodes;
        }
    };
    final GeneratorConfig config = new GeneratorConfig();
    config.setLayerHierarchies(Lists.newArrayList(NodeParamLabels.ASSET_REGION));
    config.setFilters(Lists.newArrayList(String.format("%s=Stuttgart", NodeParamLabels.ASSET_REGION)));
    final GraphML generatedGraphML = new AssetGraphGenerator(nodeProvider).generateGraphs(config);
    Assert.assertEquals(2, generatedGraphML.getGraphs().size());
    Assert.assertEquals(1, generatedGraphML.getGraphs().get(0).getNodes().size());
    Assert.assertEquals(1, generatedGraphML.getGraphs().get(1).getNodes().size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) GraphML(org.opennms.features.graphml.model.GraphML) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TestNodeProvider(org.opennms.features.topology.plugins.topo.asset.util.TestNodeProvider) NodeBuilder(org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder) Test(org.junit.Test)

Example 3 with NodeBuilder

use of org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder in project opennms by OpenNMS.

the class PersistenceNodeProviderIT method setUp.

@Before
public void setUp() {
    OnmsNode node1 = new NodeBuilder().withLabel("Node 1").getNode();
    nodeDao.save(node1);
    OnmsNode parentNode = new NodeBuilder().withLabel("Node Parent").withForeignId("parentForeignId").withForeignSource("parentForeignSource").getNode();
    nodeDao.save(parentNode);
    OnmsNode node2 = new NodeBuilder().withLabel("Node 2").withCategories("Server").withForeignId("1234").withForeignSource("dummmy").withOperatingSystem("Windows").withSysname("Digger").withSyslocation("Moon").withAssets().withAddress1("Address 1").withAddress2("Address 2").withBuilding("Building").withCategory("Category").withDepartment("Department").withDescription("Description").withCircuitId("CircuitId").withCity("City").withCountry("Country").withDisplayCategory("DisplayCategory").withDivision("Division").withFloor("Floor").withLatitude("10").withLongitude("10").withManagedObjectInstance("ManagedObjectInstance").withManagedObjectType("ManagedObjectType").withManufacturer("Manufacturer").withModelNumber("ModelNumber").withNotifyCategory("NotifyCategory").withOperatingSystem("OperatingSystem").withPollerCategory("PollerCategory").withPort("Port").withRack("Rack").withRegion("Region").withRoom("Room").withSlot("slot").withState("State").withThresholdCategory("ThresholdCategory").withVendor("Vendor").withZip("Zip").done().getNode();
    node2.getCategories().forEach(c -> categoryDao.save(c));
    node2.setParent(parentNode);
    nodeDao.save(node2);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) NodeBuilder(org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder) Before(org.junit.Before)

Example 4 with NodeBuilder

use of org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder in project opennms by OpenNMS.

the class AssetGraphGeneratorTest method verifyGraphGenerationWithCategories.

@Test
public void verifyGraphGenerationWithCategories() throws InvalidGraphException {
    final NodeProvider nodeProvider = new NodeProvider() {

        @Override
        public List<OnmsNode> getNodes(List<LayerDefinition> definitions) {
            List<OnmsNode> nodes = new ArrayList<>();
            nodes.add(new NodeBuilder().withId(1).withLabel("Node 1").withCategories("Server").withAssets().withRegion("Stuttgart").withBuilding("S1").done().getNode());
            nodes.add(new NodeBuilder().withId(2).withLabel("Node 2").withCategories("Server").withAssets().withRegion("Stuttgart").withBuilding("S2").done().getNode());
            nodes.add(new NodeBuilder().withId(3).withLabel("Node 3").withCategories("Server,Router").withAssets().withRegion("Stuttgart").withBuilding("S2").done().getNode());
            return nodes;
        }
    };
    final GeneratorConfig config = new GeneratorConfig();
    config.setLayerHierarchies(Lists.newArrayList(NodeParamLabels.ASSET_REGION, NodeParamLabels.ASSET_BUILDING, NodeParamLabels.NODE_CATEGORIES));
    // empty filters
    config.setFilters(new ArrayList<>());
    final GraphML generatedGraphML = new AssetGraphGenerator(nodeProvider).generateGraphs(config);
    // for debug generate file
    GraphMLWriter.write(generatedGraphML, new File("target/verifyGraphGenerationWithCategoriesGenerated.graphml"));
    final GraphML expectedGraphML = GraphMLReader.read(getClass().getResourceAsStream("/test-graph-categories.xml"));
    Assert.assertEquals(expectedGraphML, generatedGraphML);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) GraphML(org.opennms.features.graphml.model.GraphML) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TestNodeProvider(org.opennms.features.topology.plugins.topo.asset.util.TestNodeProvider) NodeBuilder(org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder) File(java.io.File) Test(org.junit.Test)

Aggregations

NodeBuilder (org.opennms.features.topology.plugins.topo.asset.util.NodeBuilder)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Test (org.junit.Test)3 GraphML (org.opennms.features.graphml.model.GraphML)3 TestNodeProvider (org.opennms.features.topology.plugins.topo.asset.util.TestNodeProvider)3 File (java.io.File)2 Before (org.junit.Before)1