Search in sources :

Example 6 with BusinessServiceResponseDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canCreateBusinessService.

@Test
public void canCreateBusinessService() throws Exception {
    final BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("some-service").addAttribute("some-key", "some-value").reduceFunction(new HighestSeverityEntity()).addReductionKey("reductionKey-1", new IdentityEntity()).addReductionKey("reductionKey-2", new IdentityEntity()).addReductionKey("reductionKey-3", new IdentityEntity()).toEntity();
    sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(bs)), 201);
    Assert.assertEquals(1, m_businessServiceDao.countAll());
    for (BusinessServiceEntity eachEntity : m_businessServiceDao.findAll()) {
        BusinessServiceResponseDTO responseDTO = verifyResponse(eachEntity);
        Assert.assertEquals(3, responseDTO.getReductionKeys().size());
    }
}
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 7 with BusinessServiceResponseDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canUpdateBusinessService.

@Test
public void canUpdateBusinessService() throws Exception {
    // initialize
    BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Dummy Service").addAttribute("some-key", "some-value").addReductionKey("key1", new IdentityEntity()).addReductionKey("key2-deleteMe", new IdentityEntity()).reduceFunction(new HighestSeverityEntity()).toEntity();
    final Long serviceId = m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // update
    BusinessServiceRequestDTO requestDTO = toRequestDto(bs);
    requestDTO.setName("New Name");
    requestDTO.getAttributes().put("key", "value");
    requestDTO.getReductionKeys().clear();
    requestDTO.addReductionKey("key1updated", new FunctionsManager().getMapFunctionDTO(new Ignore()), Edge.DEFAULT_WEIGHT);
    sendData(PUT, getMediaType(), "/business-services/" + serviceId, marshal(requestDTO), 204);
    // Reload from database and verify changes
    bs = m_businessServiceDao.get(serviceId);
    Assert.assertEquals(requestDTO.getName(), bs.getName());
    Assert.assertEquals(requestDTO.getAttributes(), bs.getAttributes());
    Assert.assertEquals(1, bs.getReductionKeyEdges().size());
    Assert.assertEquals(1, bs.getEdges().size());
    Assert.assertEquals(1, m_businessServiceDao.findAll().size());
    Assert.assertEquals(Sets.newHashSet(), bs.getIpServiceEdges());
    BusinessServiceResponseDTO responseDTO = verifyResponse(bs);
    verifyReductionKey("key1updated", responseDTO);
}
Also used : Ignore(org.opennms.netmgt.bsm.service.model.functions.map.Ignore) FunctionsManager(org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager) BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) BusinessServiceRequestDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO) 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 8 with BusinessServiceResponseDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO in project opennms by OpenNMS.

the class BsmTestUtils method toResponseDto.

public static BusinessServiceResponseDTO toResponseDto(BusinessServiceEntity input) {
    Objects.requireNonNull(input);
    BusinessServiceResponseDTO response = new BusinessServiceResponseDTO();
    response.setId(input.getId());
    response.setName(input.getName());
    response.setReduceFunction(transform(input.getReductionFunction()));
    // we assume INDETERMINATE
    response.setOperationalStatus(Status.INDETERMINATE);
    response.setAttributes(input.getAttributes());
    response.setLocation(ResourceLocationFactory.createBusinessServiceLocation(input.getId().toString()));
    response.setReductionKeys(input.getReductionKeyEdges().stream().map(it -> toResponseDTO(it)).collect(Collectors.toList()));
    response.setIpServices(input.getIpServiceEdges().stream().map(it -> toResponseDTO(it)).collect(Collectors.toList()));
    response.setChildren(input.getChildEdges().stream().map(it -> toResponseDTO(it)).collect(Collectors.toList()));
    // do not know that here
    response.setParentServices(Sets.newHashSet());
    return response;
}
Also used : BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO)

Aggregations

BusinessServiceResponseDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO)7 Test (org.junit.Test)4 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)4 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)4 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)4 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)4 Ignore (org.opennms.netmgt.bsm.service.model.functions.map.Ignore)2 ResourceLocation (org.opennms.web.rest.api.ResourceLocation)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)1 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)1 EdgeVisitor (org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor)1 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)1 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)1 HighestSeverity (org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity)1 BusinessServiceRequestDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO)1 TestHelper.createMapFunctionDTO (org.opennms.web.rest.v2.bsm.model.TestHelper.createMapFunctionDTO)1 FunctionsManager (org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager)1