Search in sources :

Example 16 with BusinessServiceEntityBuilder

use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canAddReductionKeyEdge.

@Test
public void canAddReductionKeyEdge() throws Exception {
    // Create a business service without any edges
    BusinessServiceEntity service = new BusinessServiceEntityBuilder().name("Dummy Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long serviceId = m_businessServiceDao.save(service);
    m_businessServiceDao.flush();
    // The Request to send to create an edge
    ReductionKeyEdgeRequestDTO edgeRequestDTO = new ReductionKeyEdgeRequestDTO();
    edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
    // verify adding of existing ip service is possible
    edgeRequestDTO.setReductionKey("1st reduction key");
    sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
    // verify adding twice possible, but not modified
    sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 304);
    Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
    // verify adding of existing ip service is possible
    edgeRequestDTO.setReductionKey("2nd reduction key");
    sendData(POST, getMediaType(), buildReductionKeyEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(2, m_businessServiceDao.get(serviceId).getReductionKeyEdges().size());
}
Also used : FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) ReductionKeyEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ReductionKeyEdgeRequestDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 17 with BusinessServiceEntityBuilder

use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canUpdateBusinessService.

@Test
public void canUpdateBusinessService() throws Exception {
    // initialize
    BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Dummy Service").addAttribute("some-key", "some-value").addReductionKey("key1", new IdentityEntity()).addReductionKey("key2-deleteMe", new IdentityEntity()).reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long serviceId = m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // update
    BusinessServiceRequestDTO requestDTO = toRequestDto(bs);
    requestDTO.setName("New Name");
    requestDTO.getAttributes().put("key", "value");
    requestDTO.getReductionKeys().clear();
    requestDTO.addReductionKey("key1updated", new FunctionsManager().getMapFunctionDTO(new Ignore()), Edge.DEFAULT_WEIGHT);
    sendData(PUT, getMediaType(), "/business-services/" + serviceId, marshal(requestDTO), 204);
    // Reload from database and verify changes
    bs = m_businessServiceDao.get(serviceId);
    Assert.assertEquals(requestDTO.getName(), bs.getName());
    Assert.assertEquals(requestDTO.getAttributes(), bs.getAttributes());
    Assert.assertEquals(1, bs.getReductionKeyEdges().size());
    Assert.assertEquals(1, bs.getEdges().size());
    Assert.assertEquals(1, m_businessServiceDao.findAll().size());
    Assert.assertEquals(Sets.newHashSet(), bs.getIpServiceEdges());
    BusinessServiceResponseDTO responseDTO = verifyResponse(bs);
    verifyReductionKey("key1updated", responseDTO);
}
Also used : Ignore(org.opennms.netmgt.bsm.service.model.functions.map.Ignore) FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) BusinessServiceRequestDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 18 with BusinessServiceEntityBuilder

use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canAddChildServiceEdge.

@Test
public void canAddChildServiceEdge() throws Exception {
    // Create a child and parent Business Service without any edges
    BusinessServiceEntity childEntity = new BusinessServiceEntityBuilder().name("Child Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    BusinessServiceEntity parentEntity = new BusinessServiceEntityBuilder().name("Parent Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long parentServiceId = m_businessServiceDao.save(parentEntity);
    final Long childServiceId = m_businessServiceDao.save(childEntity);
    m_businessServiceDao.flush();
    // The Request to send to create the edge
    ChildEdgeRequestDTO edgeRequestDTO = new ChildEdgeRequestDTO();
    edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
    // verify adding of not existing ip parentEntity is not possible
    edgeRequestDTO.setChildId(-1L);
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 404);
    // verify adding of existing ip parentEntity is possible
    edgeRequestDTO.setChildId(childServiceId);
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 200);
    Assert.assertEquals(1, m_businessServiceDao.get(parentServiceId).getChildEdges().size());
    // verify adding twice possible, but not modified
    sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 304);
    Assert.assertEquals(1, m_businessServiceDao.get(parentServiceId).getChildEdges().size());
}
Also used : ChildEdgeRequestDTO(org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO) FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Identity(org.opennms.netmgt.bsm.service.model.functions.map.Identity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 19 with BusinessServiceEntityBuilder

use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder 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

Test (org.junit.Test)19 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)19 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)18 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)13 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)12 Transactional (org.springframework.transaction.annotation.Transactional)7 Identity (org.opennms.netmgt.bsm.service.model.functions.map.Identity)4 BusinessServiceResponseDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO)4 FunctionsManager (org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager)4 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)3 Criteria (org.opennms.core.criteria.Criteria)2 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)2 IgnoreEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity)2 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)2 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)2 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 After (org.junit.After)1