Search in sources :

Example 1 with IdentityEntity

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

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

the class BsmdIT method createBusinessService.

private BusinessServiceEntity createBusinessService(String name) {
    BusinessServiceEntity bs = new BusinessServiceEntity();
    bs.setName(name);
    bs.setReductionFunction(new HighestSeverityEntity());
    bs.setAttribute("my-attr-key", "my-attr-value");
    // Grab the first monitored service from node 1
    OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
    bs.addIpServiceEdge(ipService, new IdentityEntity());
    // Persist
    m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    return bs;
}
Also used : BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)

Example 3 with IdentityEntity

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

the class FriendlyNameValidationTest method friendlyNameTooLong.

@Test
public void friendlyNameTooLong() {
    IdentityEntity identityEntity = new IdentityEntity();
    IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
    edge.setFriendlyName(FRIENDLYNAME_TOO_LONG);
    edge.setMapFunction(identityEntity);
    validator.validate(edge);
    Set<ConstraintViolation<IPServiceEdgeEntity>> constraintViolations = validator.validate(edge);
    Assert.assertEquals(1, constraintViolations.size());
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) ConstraintViolation(javax.validation.ConstraintViolation) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 4 with IdentityEntity

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

the class FriendlyNameValidationTest method friendlyNameMaximum.

@Test
public void friendlyNameMaximum() {
    IdentityEntity identityEntity = new IdentityEntity();
    IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
    edge.setFriendlyName(FRIENDLYNAME_THIRTY_CHARS);
    edge.setMapFunction(identityEntity);
    validator.validate(edge);
    Set<ConstraintViolation<IPServiceEdgeEntity>> constraintViolations = validator.validate(edge);
    Assert.assertEquals(0, constraintViolations.size());
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) ConstraintViolation(javax.validation.ConstraintViolation) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 5 with IdentityEntity

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

Aggregations

IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)19 Test (org.junit.Test)16 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)14 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)12 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)12 Transactional (org.springframework.transaction.annotation.Transactional)5 IPServiceEdgeEntity (org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity)4 BusinessServiceResponseDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO)4 ConstraintViolation (javax.validation.ConstraintViolation)3 Before (org.junit.Before)3 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 BusinessServiceChildEdgeEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceChildEdgeEntity)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 Assert (org.junit.Assert)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 RunWith (org.junit.runner.RunWith)1