Search in sources :

Example 6 with IpService

use of org.opennms.netmgt.bsm.service.model.IpService in project opennms by OpenNMS.

the class BusinessServiceVertexProviderTest method testVertexRefId.

@Test
public void testVertexRefId() {
    // Mock the manager to return a node label
    BusinessServiceManager managerMock = EasyMock.createNiceMock(BusinessServiceManager.class);
    EasyMock.expect(managerMock.getNodeById(EasyMock.anyInt())).andReturn(new Node() {

        @Override
        public String getLabel() {
            return "localhost";
        }

        @Override
        public Integer getId() {
            return 1;
        }
    }).anyTimes();
    EasyMock.replay(managerMock);
    // create 3 business service vertices, where the first 2 should be equal
    BusinessServiceEntityBuilder builder = new BusinessServiceEntityBuilder().id(10L).name("Name");
    BusinessService bs1 = new BusinessServiceImpl(managerMock, builder.toEntity());
    BusinessService bs2 = new BusinessServiceImpl(managerMock, builder.toEntity());
    // is different
    BusinessService bs3 = new BusinessServiceImpl(managerMock, builder.id(11L).toEntity());
    BusinessServiceVertex bsVertex1 = new BusinessServiceVertex(bs1, 0);
    BusinessServiceVertex bsVertex2 = new BusinessServiceVertex(bs2, 0);
    BusinessServiceVertex bsVertex3 = new BusinessServiceVertex(bs3, 0);
    // create 2 ip Service vertices where all of them should be equal
    IpService ipService1 = new IpServiceImpl(managerMock, BsmTestUtils.createMonitoredService(1, 1, "127.0.0.1", "SSH"));
    IpService ipService2 = new IpServiceImpl(managerMock, BsmTestUtils.createMonitoredService(1, 1, "127.0.0.1", "SSH"));
    IpServiceVertex ipServiceVertex1 = new IpServiceVertex(ipService1, 0);
    IpServiceVertex ipServiceVertex2 = new IpServiceVertex(ipService2, 0);
    // create 3 reduction key vertices where 2 of them should be equal
    ReductionKeyVertex rkVertex1 = new ReductionKeyVertex("key1", 0);
    ReductionKeyVertex rkVertex2 = new ReductionKeyVertex("key1", 0);
    ReductionKeyVertex rkVertex3 = new ReductionKeyVertex("key2", 0);
    // Add all the above vertices. Some of them even twice to ensure that the getRefId() methods work correctly
    BusinessServiceVertexProvider vertexProvider = new BusinessServiceVertexProvider(BusinessServicesTopologyProvider.TOPOLOGY_NAMESPACE);
    // adding twice on purpose
    vertexProvider.add(bsVertex1, bsVertex1, bsVertex2, bsVertex2, bsVertex3, bsVertex3);
    // adding twice on purpose
    vertexProvider.add(ipServiceVertex1, ipServiceVertex1, ipServiceVertex2, ipServiceVertex2);
    // adding twice on purpose
    vertexProvider.add(rkVertex1, rkVertex1);
    // adding twice on purpose
    vertexProvider.add(rkVertex2, rkVertex2);
    // adding twice on purpose
    vertexProvider.add(rkVertex3, rkVertex3);
    // In total there should be 5 vertices
    Assert.assertEquals(5, vertexProvider.getVertices().size());
    Assert.assertSame(ipServiceVertex2, vertexProvider.getVertex(ipServiceVertex1));
    Assert.assertSame(ipServiceVertex2, vertexProvider.getVertex(ipServiceVertex2));
    Assert.assertSame(bsVertex2, vertexProvider.getVertex(bsVertex1));
    Assert.assertSame(bsVertex2, vertexProvider.getVertex(bsVertex2));
    Assert.assertSame(bsVertex3, vertexProvider.getVertex(bsVertex3));
    Assert.assertNotSame(bsVertex1, vertexProvider.getVertex(bsVertex3));
    Assert.assertNotSame(bsVertex2, vertexProvider.getVertex(bsVertex3));
    Assert.assertSame(rkVertex2, vertexProvider.getVertex(rkVertex1));
    Assert.assertSame(rkVertex2, vertexProvider.getVertex(rkVertex2));
    Assert.assertNotSame(rkVertex1, vertexProvider.getVertex(rkVertex3));
    Assert.assertSame(rkVertex3, vertexProvider.getVertex(rkVertex3));
    EasyMock.verify(managerMock);
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceImpl(org.opennms.netmgt.bsm.service.internal.BusinessServiceImpl) Node(org.opennms.netmgt.bsm.service.model.Node) IpServiceImpl(org.opennms.netmgt.bsm.service.internal.IpServiceImpl) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) IpService(org.opennms.netmgt.bsm.service.model.IpService) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Aggregations

IpService (org.opennms.netmgt.bsm.service.model.IpService)6 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)5 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 Node (org.opennms.netmgt.bsm.service.model.Node)2 GraphEdge (org.opennms.netmgt.bsm.service.model.graph.GraphEdge)2 Strings (com.google.common.base.Strings)1 ShortcutAction (com.vaadin.event.ShortcutAction)1 FontAwesome (com.vaadin.server.FontAwesome)1 Sizeable (com.vaadin.server.Sizeable)1 Button (com.vaadin.ui.Button)1 Component (com.vaadin.ui.Component)1 FormLayout (com.vaadin.ui.FormLayout)1 Label (com.vaadin.ui.Label)1 Table (com.vaadin.ui.Table)1 UI (com.vaadin.ui.UI)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Window (com.vaadin.ui.Window)1