use of org.opennms.features.topology.api.support.SimpleGraphBuilder in project opennms by OpenNMS.
the class BreadcrumbPathCalculatorTest method setUp.
@Before
public void setUp() {
final GraphProvider layer1 = new SimpleGraphBuilder("layer1").vertex("A1").vertex("A2").get();
final GraphProvider layer2 = new SimpleGraphBuilder("layer2").vertex("B1").vertex("B2").vertex("B3").vertex("B4").get();
final GraphProvider layer3 = new SimpleGraphBuilder("layer3").vertex("C1").vertex("C2").vertex("C3").vertex("C4").vertex("C5").vertex("C6").edge("e1", "C1", "C4").edge("e2", "C1", "C5").edge("e3", "C4", "C5").get();
final Map<VertexRef, List<VertexRef>> oppositesMap = Maps.newHashMap();
oppositesMap.put(new DefaultVertexRef("layer1", "A1"), Lists.newArrayList(new DefaultVertexRef("layer2", "B3"), new DefaultVertexRef("layer2", "B4")));
oppositesMap.put(new DefaultVertexRef("layer1", "A2"), Lists.newArrayList(new DefaultVertexRef("layer2", "B1"), new DefaultVertexRef("layer2", "B2")));
oppositesMap.put(new DefaultVertexRef("layer2", "B1"), Lists.newArrayList(new DefaultVertexRef("layer3", "C2")));
oppositesMap.put(new DefaultVertexRef("layer2", "B2"), Lists.newArrayList(new DefaultVertexRef("layer3", "C1")));
oppositesMap.put(new DefaultVertexRef("layer2", "B3"), Lists.newArrayList(new DefaultVertexRef("layer3", "C3")));
MetaTopologyProvider metaTopologyProvider = new MetaTopologyProvider() {
@Override
public GraphProvider getDefaultGraphProvider() {
return layer1;
}
@Override
public Collection<GraphProvider> getGraphProviders() {
return Lists.newArrayList(layer1, layer2, layer3);
}
@Override
public Collection<VertexRef> getOppositeVertices(VertexRef vertexRef) {
return Optional.ofNullable(oppositesMap.get(vertexRef)).orElse(Lists.newArrayList());
}
@Override
public GraphProvider getGraphProviderBy(String namespace) {
return getGraphProviders().stream().filter(p -> p.getNamespace().equals(namespace)).findFirst().orElse(null);
}
@Override
public BreadcrumbStrategy getBreadcrumbStrategy() {
return BreadcrumbStrategy.NONE;
}
@Override
public String getId() {
return getGraphProviders().stream().map(g -> g.getNamespace()).collect(Collectors.joining(":"));
}
};
DefaultTopologyService topologyService = new DefaultTopologyService();
topologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
DefaultTopologyServiceClient client = new DefaultTopologyServiceClient(topologyService);
client.setMetaTopologyId(metaTopologyProvider.getId());
client.setNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
topologyServiceClient = client;
}
use of org.opennms.features.topology.api.support.SimpleGraphBuilder in project opennms by OpenNMS.
the class AbstractLayoutTest method setUp.
@Before
public void setUp() {
SimpleGraphBuilder bldr = new SimpleGraphBuilder("nodes");
for (int i = 0; i < 100; i++) {
bldr.vertex("v" + i).vLabel("vertex" + i).vIconKey("server").vTooltip("tooltip").vStyleName("vertex");
}
bldr.edge("e1", "v1", "v2").eStyleName("edge").edge("e2", "v1", "v3").eStyleName("edge").edge("e3", "v1", "v4").eStyleName("edge").edge("e4", "v1", "v5").eStyleName("edge").edge("e5", "v1", "v6").eStyleName("edge").edge("e6", "v1", "v7").eStyleName("edge").edge("e7", "v1", "v8").eStyleName("edge").edge("e8", "v1", "v8").eStyleName("edge").edge("e9", "v2", "v8").eStyleName("edge").edge("e10", "v2", "v7").eStyleName("edge").edge("e11", "v3", "v8").eStyleName("edge").edge("e12", "v5", "v8").eStyleName("edge").edge("e13", "v6", "v8").eStyleName("edge").edge("e14", "v7", "v8").eStyleName("edge");
final DefaultTopologyService topologyService = new DefaultTopologyService();
final MetaTopologyProvider metaTopologyProvider = new SimpleMetaTopologyProvider(getGraphProvider());
topologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
final VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
graphContainer.setTopologyService(topologyService);
graphContainer.setSelectedNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
graphContainer.setMetaTopologyId(metaTopologyProvider.getId());
m_graphContainer = graphContainer;
}
use of org.opennms.features.topology.api.support.SimpleGraphBuilder in project opennms by OpenNMS.
the class ManualLayoutAlgorithmTest method verifyAppliesXAndYCoordinates.
/*
* This test verifies, that the vertex coordinates of x and y are applied to the
* layout, if they exist.
*/
@Test
public void verifyAppliesXAndYCoordinates() {
final ManualTest test = new ManualTest(new SimpleGraphBuilder("dummy").vertex("1").vX(0).vY(0).vertex("2").vX(1).vY(1).get());
final LayoutAlgorithm layoutAlgorithm = new ManualLayoutAlgorithm(test.layoutManager);
layoutAlgorithm.updateLayout(test.graph);
Assert.assertEquals(ImmutableMap.builder().put(new DefaultVertexRef("dummy", "1"), new Point(0, 0)).put(new DefaultVertexRef("dummy", "2"), new Point(1, 1)).build(), test.layout.getLocations());
}
use of org.opennms.features.topology.api.support.SimpleGraphBuilder in project opennms by OpenNMS.
the class ManualLayoutAlgorithmTest method verifyDefaultsToGridLayout.
/*
* If no coordinates are defined for the vertex and there are no layout coordinates yet, verify that it falls
* back to the GridLayout.
*/
@Test
public void verifyDefaultsToGridLayout() {
final ManualTest test = new ManualTest(new SimpleGraphBuilder("dummy").vertex("1").vertex("2").get());
new ManualLayoutAlgorithm(test.layoutManager).updateLayout(test.graph);
Map<VertexRef, Point> manualLocations = test.layout.getLocations();
new GridLayoutAlgorithm().updateLayout(test.graph);
Assert.assertEquals(test.layout.getLocations(), manualLocations);
}
use of org.opennms.features.topology.api.support.SimpleGraphBuilder in project opennms by OpenNMS.
the class VEProviderGraphContainerTest method setUp.
@Before
public void setUp() {
MockLogAppender.setupLogging();
m_graphProvider = new SimpleGraphBuilder("nodes").vertex("g0").vLabel("group0").vIconKey("group").vTooltip("root group").vStyleName("vertex").vertex("g1").parent("g0").vLabel("group1").vIconKey("group").vTooltip("group 1").vStyleName("vertex").vertex("v1").parent("g1").vLabel("vertex1").vIconKey("server").vTooltip("tooltip").vStyleName("vertex").vertex("v2").parent("g1").vLabel("vertex2").vIconKey("server").vTooltip("tooltip").vStyleName("vertex").vertex("g2").parent("g0").vLabel("group2").vIconKey("group").vTooltip("group 2").vStyleName("vertex").vertex("v3").parent("g2").vLabel("vertex3").vIconKey("server").vTooltip("tooltip").vStyleName("vertex").vertex("v4").parent("g2").vLabel("vertex4").vIconKey("server").vTooltip("tooltip").vStyleName("vertex").edge("e1", "v1", "v2").eStyleName("edge").edge("e2", "v2", "v3").eStyleName("edge").edge("e3", "v3", "v4").eStyleName("edge").edge("e4", "v4", "v1").eStyleName("edge").get();
MetaTopologyProvider metaTopologyProvider = new SimpleMetaTopologyProvider(m_graphProvider);
DefaultTopologyService topologyService = new DefaultTopologyService();
topologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
graphContainer.setSemanticZoomLevel(0);
graphContainer.setTopologyService(topologyService);
graphContainer.setSelectedNamespace(m_graphProvider.getNamespace());
graphContainer.setMetaTopologyId(m_graphProvider.getNamespace());
m_graphContainer = graphContainer;
}
Aggregations