Search in sources :

Example 1 with IgnoreEntity

use of org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity 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)

Example 2 with IgnoreEntity

use of org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity in project opennms by OpenNMS.

the class BusinessServiceDaoIT method setUp.

@Before
public void setUp() {
    BeanUtils.assertAutowiring(this);
    m_databasePopulator.populateDatabase();
    m_highestSeverity = new HighestSeverityEntity();
    m_ignore = new IgnoreEntity();
}
Also used : IgnoreEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Before(org.junit.Before)

Example 3 with IgnoreEntity

use of org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity in project opennms by OpenNMS.

the class BusinessServiceDaoIT method verifyFindMatching.

@Test
@Transactional
public void verifyFindMatching() {
    /*
         * Test that offset and limit work, when only ordered by id
         */
    // create test data
    Long bsId1 = m_businessServiceDao.save(new BusinessServiceEntityBuilder().name("BS 1.1").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs1.key1", new IgnoreEntity(), 1).addReductionKey("bs1.key2", new IgnoreEntity(), 2).addReductionKey("bs1.key3", new IgnoreEntity(), 3).toEntity());
    Long bsId2 = m_businessServiceDao.save(new BusinessServiceEntityBuilder().name("BS 2.0").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs2.key1", new IgnoreEntity(), 1).addReductionKey("bs2.key2", new IgnoreEntity(), 2).addReductionKey("bs2.key3", new IgnoreEntity(), 3).toEntity());
    m_businessServiceDao.flush();
    // create criteria to limit result
    org.opennms.core.criteria.Criteria criteria = new CriteriaBuilder(BusinessServiceEntity.class).offset(0).limit(2).orderBy("id").toCriteria();
    // verify that entities are distinct
    List<BusinessServiceEntity> filteredBusinessServices = m_businessServiceDao.findMatching(criteria);
    Assert.assertEquals(2, filteredBusinessServices.size());
    Assert.assertEquals(m_businessServiceDao.findAll().stream().sorted((bs1, bs2) -> bs1.getId().compareTo(bs2.getId())).collect(Collectors.toList()), filteredBusinessServices);
    // create another bs for a more complex test
    Long bsId3 = m_businessServiceDao.save(new BusinessServiceEntityBuilder().name("BS 3.1").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs3.key3.1", new IgnoreEntity(), 4).addReductionKey("bs3.key3.2", new IgnoreEntity(), 5).addReductionKey("bs3.key3.3", new IgnoreEntity(), 6).toEntity());
    m_businessServiceDao.flush();
    // restrict to value3% and order by id descending
    criteria.setAliases(Lists.newArrayList(new Alias("edges", "edge", Alias.JoinType.INNER_JOIN, Restrictions.ge("edge.weight", 3))));
    criteria.setOrders(Lists.newArrayList(new Order("id", false)));
    // Verify
    filteredBusinessServices = m_businessServiceDao.findMatching(criteria);
    Assert.assertEquals(2, filteredBusinessServices.size());
    Assert.assertEquals(Lists.newArrayList(m_businessServiceDao.get(bsId2), m_businessServiceDao.get(bsId3)), filteredBusinessServices);
    /*
         * Verify that one can also order by name
         */
    Criteria nameCriteria = new CriteriaBuilder(BusinessServiceEntity.class).ilike("name", "BS %.1").orderBy("name").limit(2).toCriteria();
    filteredBusinessServices = m_businessServiceDao.findMatching(nameCriteria);
    Assert.assertEquals(2, filteredBusinessServices.size());
    Assert.assertEquals(Lists.newArrayList(m_businessServiceDao.get(bsId1), m_businessServiceDao.get(bsId3)), filteredBusinessServices);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Order(org.opennms.core.criteria.Order) Criteria(org.opennms.core.criteria.Criteria) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) Criteria(org.opennms.core.criteria.Criteria) IgnoreEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity) Alias(org.opennms.core.criteria.Alias) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IgnoreEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IgnoreEntity)3 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)3 Test (org.junit.Test)2 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)2 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)2 Before (org.junit.Before)1 Alias (org.opennms.core.criteria.Alias)1 Criteria (org.opennms.core.criteria.Criteria)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 Order (org.opennms.core.criteria.Order)1 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)1 IncreaseEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IncreaseEntity)1 SetToEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.SetToEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1