Search in sources :

Example 6 with IdentityEntity

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

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

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

the class AbstractBusinessServiceRestServiceIT method canRetrieveBusinessServices.

@Test
public void canRetrieveBusinessServices() throws Exception {
    // Add business services to the DB
    BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Application Servers").addReductionKey("MyReductionKey", new IdentityEntity()).reduceFunction(new HighestSeverityEntity()).toEntity();
    Long id = m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // Retrieve the list of business services
    List<ResourceLocation> businessServices = listBusinessServices();
    // Verify
    Assert.assertEquals(1, businessServices.size());
    BusinessServiceResponseDTO expectedResponseDTO = toResponseDto(bs);
    BusinessServiceResponseDTO actualResponseDTO = getAndUnmarshal(buildServiceUrl(id), 200, BusinessServiceResponseDTO.class);
    Assert.assertEquals(expectedResponseDTO, actualResponseDTO);
    verifyReductionKey("MyReductionKey", actualResponseDTO);
}
Also used : BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) ResourceLocation(org.opennms.web.rest.api.ResourceLocation) 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 9 with IdentityEntity

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

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

the class AbstractBusinessServiceRestServiceIT method canCreateSimpleHierarchy.

/**
 * Verify that the Rest API can deal with setting of a hierarchy
 */
@Test
public void canCreateSimpleHierarchy() throws Exception {
    final SimpleTestHierarchy testData = new SimpleTestHierarchy(databasePopulator);
    // clear hierarchy
    for (BusinessServiceEntity eachEntity : testData.getServices()) {
        eachEntity.getEdges().clear();
    }
    // save business services
    for (BusinessServiceEntity eachEntity : testData.getServices()) {
        sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(eachEntity)), 201);
    }
    // set hierarchy
    BusinessServiceEntity parentEntity = findEntityByName("Parent").addChildServiceEdge(findEntityByName("Child 1"), new IdentityEntity(), 1).addChildServiceEdge(findEntityByName("Child 2"), new IdentityEntity(), 1);
    sendData(PUT, getMediaType(), buildServiceUrl(parentEntity.getId()), marshal(toRequestDto(parentEntity)), 204);
    // Verify
    Assert.assertEquals(3, m_businessServiceDao.countAll());
    parentEntity = findEntityByName("Parent");
    BusinessServiceEntity child1Entity = findEntityByName("Child 1");
    BusinessServiceEntity child2Entity = findEntityByName("Child 2");
    Assert.assertEquals(0, m_businessServiceDao.findParents(parentEntity).size());
    Assert.assertEquals(2, parentEntity.getChildEdges().size());
    Assert.assertEquals(1, m_businessServiceDao.findParents(child1Entity).size());
    Assert.assertEquals(0, child1Entity.getChildEdges().size());
    Assert.assertEquals(1, m_businessServiceDao.findParents(child2Entity).size());
    Assert.assertEquals(0, child2Entity.getChildEdges().size());
    verifyResponse(parentEntity);
    verifyResponse(child1Entity);
    verifyResponse(child2Entity);
}
Also used : SimpleTestHierarchy(org.opennms.netmgt.bsm.test.hierarchies.SimpleTestHierarchy) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

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