use of org.opennms.features.topology.api.topo.DefaultVertexRef in project opennms by OpenNMS.
the class LayoutManagerTest method testHash.
@Test
public void testHash() {
ArrayList<VertexRef> defaultVertexRefs = Lists.newArrayList(new DefaultVertexRef("namespace1", "id1", "Label 1"), new DefaultVertexRef("namespace2", "id2", "Label 2"), new DefaultVertexRef("namespace3", "id3", "Label 3"));
String hash1 = LayoutManager.calculateHash(defaultVertexRefs);
String hash2 = LayoutManager.calculateHash(defaultVertexRefs);
Assert.assertEquals(hash1, hash2);
}
use of org.opennms.features.topology.api.topo.DefaultVertexRef 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.topo.DefaultVertexRef in project opennms by OpenNMS.
the class SimpleEdgeBuilder method edge.
public SimpleEdgeBuilder edge(String id, String srcNs, String srcId, String tgtNs, String tgtId) {
VertexRef srcVertex = new DefaultVertexRef(srcNs, srcId);
VertexRef tgtVertex = new DefaultVertexRef(tgtNs, tgtId);
SimpleConnector source = new SimpleConnector(ns(), srcId + "-" + id + "-connector", srcVertex);
SimpleConnector target = new SimpleConnector(ns(), tgtId + "-" + id + "-connector", tgtVertex);
m_currentEdge = new AbstractEdge(ns(), id, source, target);
source.setEdge(m_currentEdge);
target.setEdge(m_currentEdge);
m_edgeProvider.add(m_currentEdge);
return this;
}
use of org.opennms.features.topology.api.topo.DefaultVertexRef 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.topo.DefaultVertexRef in project opennms by OpenNMS.
the class SavedHistoryTest method verifyCRCIncludesSearchResult.
/**
* This methods tests whether the CRC checksums for {@link SavedHistory} object with {@link SearchResult}s are generated correctly,
* namely that they now take into account the search results
*/
@Test
public void verifyCRCIncludesSearchResult() {
Map<String, String> settings = new HashMap<String, String>();
settings.put("hello", "world");
VertexRef vert1 = new DefaultVertexRef("nodes", "1");
VertexRef vert2 = new DefaultVertexRef("nodes", "2", "HasALabel");
Map<VertexRef, Point> locations = new HashMap<VertexRef, Point>();
locations.put(vert1, new Point(0, 0));
locations.put(vert2, new Point(0, 0));
// Creating SavedHistory object with no search results
SavedHistory history1 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, Collections.emptyList());
List<SearchResult> searchResults = new ArrayList<>();
searchResults.add(new SearchResult("alarm", "alarmID", "someLabel", searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED));
// Creating SavedHistory object with a single search result with ID = "alarmID"
SavedHistory history2 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
// Assertion that the SavedHistory with no search results is different from the one with one
Assert.assertNotEquals(history1.getFragment(), history2.getFragment());
// Creating another SavedHistory WITH search result, identical to the 2nd one
SavedHistory history3 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
// Assertion that two SavedHistory objects with the same search results are identical
Assert.assertEquals(history2.getFragment(), history3.getFragment());
}
Aggregations