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());
}
}
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);
}
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;
}
Aggregations