Search in sources :

Example 1 with IncreaseEntity

use of org.opennms.netmgt.bsm.persistence.api.functions.map.IncreaseEntity 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)1 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)1 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)1 IgnoreEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity)1 IncreaseEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IncreaseEntity)1 SetToEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.SetToEntity)1 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)1 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)1