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);
}
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());
}
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);
}
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);
}
Aggregations