Search in sources :

Example 1 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 2 with BusinessServiceEntityBuilder

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

the class BusinessServiceDaoIT method verifyDistinctObjectLoading.

@Test
@Transactional
public void verifyDistinctObjectLoading() {
    BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Parent Web Servers").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).addReductionKey("TestReductionKeyC", new IdentityEntity()).reduceFunction(m_highestSeverity).toEntity();
    m_businessServiceDao.save(entity);
    m_businessServiceDao.flush();
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(3, m_edgeDao.countAll());
    Criteria criteria = new CriteriaBuilder(BusinessServiceEntity.class).toCriteria();
    // verify that root entity is merged
    assertEquals(1, m_businessServiceDao.findMatching(criteria).size());
    // verify that countMatching also works
    assertEquals(1, m_businessServiceDao.countMatching(criteria));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Criteria(org.opennms.core.criteria.Criteria) 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)

Example 3 with BusinessServiceEntityBuilder

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

the class BusinessServiceDaoIT method verifyBeanValidation.

@Test(expected = ConstraintViolationException.class)
@Transactional
public void verifyBeanValidation() {
    BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Some Custom Name").addReductionKey("My Reduction Key", new IdentityEntity(), "so friendly").addReductionKey("Another Reduction Key", new IdentityEntity(), Strings.padEnd("too", 30, 'o') + " friendly").reduceFunction(m_highestSeverity).toEntity();
    // Should throw a ConstraintViolationException (friendly name too long)
    m_businessServiceDao.save(entity);
    m_businessServiceDao.flush();
}
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) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with BusinessServiceEntityBuilder

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

the class AbstractBusinessServiceRestServiceIT method verifyHighestSeverityAboveReduceFunction.

@Test
public void verifyHighestSeverityAboveReduceFunction() throws Exception {
    BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Dummy Service").reduceFunction(new HighestSeverityAboveEntity(Status.CRITICAL.ordinal())).toEntity();
    sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(entity)), 201);
    entity.setId(findEntityByName("Dummy Service").getId());
    verifyResponse(entity);
}
Also used : HighestSeverityAboveEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityAboveEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test)

Example 5 with BusinessServiceEntityBuilder

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

the class AbstractBusinessServiceRestServiceIT method canRemoveEdges.

@Test
public void canRemoveEdges() throws Exception {
    BusinessServiceEntity child = new BusinessServiceEntityBuilder().name("Child Service").reduceFunction(new HighestSeverityEntity()).toEntity();
    m_businessServiceDao.save(child);
    BusinessServiceEntity parent = new BusinessServiceEntityBuilder().name("Parent Service").reduceFunction(new HighestSeverityEntity()).addIpService(monitoredServiceDao.get(17), new SetToEntity(OnmsSeverity.CRITICAL.getId())).addIpService(monitoredServiceDao.get(18), new IgnoreEntity()).addIpService(monitoredServiceDao.get(20), new IdentityEntity()).addReductionKey("abc", new IgnoreEntity()).addReductionKey("abcd", new IgnoreEntity()).addChildren(child, new IncreaseEntity()).toEntity();
    final Long parentServiceId = m_businessServiceDao.save(parent);
    m_businessServiceDao.flush();
    // verify that test data is set up correctly
    Assert.assertEquals(3, parent.getIpServiceEdges().size());
    Assert.assertEquals(2, parent.getReductionKeyEdges().size());
    Assert.assertEquals(1, parent.getChildEdges().size());
    Assert.assertEquals(6, parent.getEdges().size());
    // determine edge ids
    List<Long> edgeIdList = parent.getEdges().stream().map(e -> e.getId()).sorted().collect(Collectors.toList());
    // verify removing not existing ip service not possible
    sendData(DELETE, getMediaType(), buildEdgeUrl(parentServiceId, -1), "", 404);
    // verify removing of existing ip service is possible
    for (int i = 0; i < edgeIdList.size(); i++) {
        long edgeId = edgeIdList.get(i);
        int edgesLeftCount = edgeIdList.size() - i - 1;
        // verify removing of existing ip service is possible
        sendData(DELETE, getMediaType(), buildEdgeUrl(parentServiceId, edgeId), "", 200);
        Assert.assertEquals(edgesLeftCount, m_businessServiceDao.get(parentServiceId).getEdges().size());
        // verify removing twice possible, but not modified
        sendData(DELETE, getMediaType(), buildEdgeUrl(parentServiceId, edgeId), "", 304);
        Assert.assertEquals(edgesLeftCount, m_businessServiceDao.get(parentServiceId).getEdges().size());
    }
}
Also used : IgnoreEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity) IncreaseEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IncreaseEntity) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) SetToEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.SetToEntity) 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)

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