Search in sources :

Example 6 with BusinessServiceEntityBuilder

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

the class AbstractBusinessServiceRestServiceIT method verifyFriendlyName.

@Test
public void verifyFriendlyName() throws Exception {
    BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Some Custom Name").addReductionKey("My Reduction Key", new IdentityEntity(), "so friendly").reduceFunction(new HighestSeverityEntity()).toEntity();
    sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(entity)), 201);
    BusinessServiceResponseDTO responseDTO = verifyResponse(findEntityByName("Some Custom Name"));
    Assert.assertEquals(1, responseDTO.getReductionKeys().size());
    Assert.assertEquals("so friendly", responseDTO.getReductionKeys().get(0).getFriendlyName());
}
Also used : BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) 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 7 with BusinessServiceEntityBuilder

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

the class BusinessServiceSearchProviderIT method verifyQuery.

@Test
public void verifyQuery() {
    BusinessServiceEntity bs1 = new BusinessServiceEntityBuilder().name("Test Service").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs1.key1", new IdentityEntity(), 1).addReductionKey("bs1.key2", new IdentityEntity(), 1).toEntity();
    BusinessServiceEntity bs2 = new BusinessServiceEntityBuilder().name("Real Service 2").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs2.key1", new IdentityEntity(), 1).addReductionKey("bs2.key2", new IdentityEntity(), 1).toEntity();
    businessServiceDao.save(bs1);
    businessServiceDao.save(bs2);
    businessServiceDao.flush();
    // prepare mocks
    TopologyServiceClient topologyServiceClientMock = EasyMock.createNiceMock(TopologyServiceClient.class);
    EasyMock.expect(topologyServiceClientMock.getVertex(EasyMock.anyObject(BusinessServiceVertex.class))).andReturn(// always return a vertex, it just needs to be not null
    new AbstractVertex("bsm", "0", "Dummy Vertex"));
    GraphContainer graphContainerMock = EasyMock.createNiceMock(GraphContainer.class);
    EasyMock.expect(graphContainerMock.getTopologyServiceClient()).andReturn(topologyServiceClientMock).anyTimes();
    EasyMock.replay(graphContainerMock, topologyServiceClientMock);
    // try searching
    final BusinessServiceSearchProvider provider = new BusinessServiceSearchProvider();
    provider.setBusinessServiceManager(businessServiceManager);
    final SearchQuery query = new AbstractSearchQuery("Test") {

        @Override
        public boolean matches(String label) {
            // always match, it does not matter
            return true;
        }
    };
    final List<SearchResult> result = provider.query(query, graphContainerMock);
    Assert.assertEquals(1, result.size());
    EasyMock.verify(graphContainerMock, topologyServiceClientMock);
}
Also used : SearchQuery(org.opennms.features.topology.api.topo.SearchQuery) AbstractSearchQuery(org.opennms.features.topology.api.topo.AbstractSearchQuery) SearchResult(org.opennms.features.topology.api.topo.SearchResult) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) GraphContainer(org.opennms.features.topology.api.GraphContainer) TopologyServiceClient(org.opennms.features.topology.api.TopologyServiceClient) AbstractSearchQuery(org.opennms.features.topology.api.topo.AbstractSearchQuery) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 8 with BusinessServiceEntityBuilder

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

the class BusinessServiceDaoIT method verifyUniqueNameConstraint.

@Test()
@Transactional
public void verifyUniqueNameConstraint() {
    BusinessServiceEntity entity1 = new BusinessServiceEntityBuilder().name("Some Custom Name").reduceFunction(m_highestSeverity).toEntity();
    m_businessServiceDao.save(entity1);
    m_businessServiceDao.flush();
    BusinessServiceEntity entity2 = new BusinessServiceEntityBuilder().name("Some Custom Name").reduceFunction(m_highestSeverity).toEntity();
    m_businessServiceDao.save(entity2);
    // Should throw a ConstraintViolationException (name not unique)
    try {
        m_businessServiceDao.flush();
        fail("ConstraintViolationException must be thrown");
    } catch (final DataIntegrityViolationException e) {
    }
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with BusinessServiceEntityBuilder

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

the class BusinessServiceDaoIT method canCreateReadUpdateAndDeleteBusinessServices.

@Test
@Transactional
public void canCreateReadUpdateAndDeleteBusinessServices() {
    final int ifServiceCount = m_monitoredServiceDao.countAll();
    // Initially there should be no business services
    assertEquals(0, m_businessServiceDao.countAll());
    // Create a business service
    BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Web Servers").addAttribute("dc", "RDU").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).reduceFunction(m_highestSeverity).toEntity();
    m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // Read a business service
    assertEquals(bs, m_businessServiceDao.get(bs.getId()));
    assertEquals(2, m_businessServiceDao.get(bs.getId()).getReductionKeyEdges().size());
    // Update a business service
    bs.setName("Application Servers");
    bs.getAttributes().put("dc", "!RDU");
    bs.getAttributes().put("cd", "/");
    // Grab the first monitored service from node 1
    OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
    bs.addIpServiceEdge(ipService, m_ignore);
    m_businessServiceDao.update(bs);
    m_businessServiceDao.flush();
    // Verify the update
    assertEquals(bs, m_businessServiceDao.get(bs.getId()));
    // Delete
    m_businessServiceDao.delete(bs);
    m_businessServiceDao.flush();
    // There should be no business services after the delete
    assertEquals(0, m_businessServiceDao.countAll());
    // No if service should have been deleted
    assertEquals(ifServiceCount, m_monitoredServiceDao.countAll());
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with BusinessServiceEntityBuilder

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

the class BusinessServiceDaoIT method verifyDeleteOnCascade.

/**
     * If we do not explicitly delete the map or reduce function it should be deleted if not referenced anymore.
     */
@Test
@Transactional
public void verifyDeleteOnCascade() {
    BusinessServiceEntity child2 = new BusinessServiceEntityBuilder().name("Child 2").reduceFunction(new HighestSeverityEntity()).addReductionKey("some-key", new IdentityEntity()).toEntity();
    BusinessServiceEntity child1 = new BusinessServiceEntityBuilder().name("Child 1").reduceFunction(new HighestSeverityEntity()).addChildren(child2, new IdentityEntity()).toEntity();
    BusinessServiceEntity parent = new BusinessServiceEntityBuilder().name("Parent Web Servers").addAttribute("dc", "RDU").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).addIpService(getMonitoredServiceFromNode1(), new IdentityEntity()).reduceFunction(m_highestSeverity).addChildren(child1, new IdentityEntity()).toEntity();
    m_businessServiceDao.save(child2);
    m_businessServiceDao.save(child1);
    m_businessServiceDao.save(parent);
    m_businessServiceDao.flush();
    assertEquals(3, m_businessServiceDao.countAll());
    assertEquals(3, m_reductionFunctionDao.countAll());
    assertEquals(6, m_edgeDao.countAll());
    // Deletion of child does not delete the edges referencing to that child
    // remove all parent -> child associations manually
    BusinessServiceChildEdgeEntity parentToChild1Edge = parent.getChildEdges().iterator().next();
    parent.removeEdge(parentToChild1Edge);
    m_edgeDao.delete(parentToChild1Edge);
    // edges do not need to be deleted manually, deletes will be cascaded
    m_businessServiceDao.delete(child1);
    m_businessServiceDao.flush();
    assertEquals(2, m_businessServiceDao.countAll());
    assertEquals(2, m_reductionFunctionDao.countAll());
    assertEquals(4, m_edgeDao.countAll());
    // Deletion of parent should delete all references
    m_businessServiceDao.delete(parent);
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(1, m_reductionFunctionDao.countAll());
    assertEquals(1, m_edgeDao.countAll());
    // Deletion of Child 2 should also work
    m_businessServiceDao.delete(child2);
    assertEquals(0, m_businessServiceDao.countAll());
    assertEquals(0, m_reductionFunctionDao.countAll());
    assertEquals(0, m_edgeDao.countAll());
}
Also used : BusinessServiceChildEdgeEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity) 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) Transactional(org.springframework.transaction.annotation.Transactional)

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