use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder in project opennms by OpenNMS.
the class BusinessServiceDaoIT method verifyUniqueNameConstraint.
@Test()
@Transactional
public void verifyUniqueNameConstraint() {
BusinessServiceEntity entity1 = new BusinessServiceEntityBuilder().name("Some Custom Name").reduceFunction(m_highestSeverity).toEntity();
m_businessServiceDao.save(entity1);
m_businessServiceDao.flush();
BusinessServiceEntity entity2 = new BusinessServiceEntityBuilder().name("Some Custom Name").reduceFunction(m_highestSeverity).toEntity();
m_businessServiceDao.save(entity2);
// Should throw a ConstraintViolationException (name not unique)
try {
m_businessServiceDao.flush();
fail("ConstraintViolationException must be thrown");
} catch (final DataIntegrityViolationException e) {
}
}
use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder in project opennms by OpenNMS.
the class BusinessServiceDaoIT method canCreateReadUpdateAndDeleteBusinessServices.
@Test
@Transactional
public void canCreateReadUpdateAndDeleteBusinessServices() {
final int ifServiceCount = m_monitoredServiceDao.countAll();
// Initially there should be no business services
assertEquals(0, m_businessServiceDao.countAll());
// Create a business service
BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Web Servers").addAttribute("dc", "RDU").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).reduceFunction(m_highestSeverity).toEntity();
m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// Read a business service
assertEquals(bs, m_businessServiceDao.get(bs.getId()));
assertEquals(2, m_businessServiceDao.get(bs.getId()).getReductionKeyEdges().size());
// Update a business service
bs.setName("Application Servers");
bs.getAttributes().put("dc", "!RDU");
bs.getAttributes().put("cd", "/");
// Grab the first monitored service from node 1
OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
bs.addIpServiceEdge(ipService, m_ignore);
m_businessServiceDao.update(bs);
m_businessServiceDao.flush();
// Verify the update
assertEquals(bs, m_businessServiceDao.get(bs.getId()));
// Delete
m_businessServiceDao.delete(bs);
m_businessServiceDao.flush();
// There should be no business services after the delete
assertEquals(0, m_businessServiceDao.countAll());
// No if service should have been deleted
assertEquals(ifServiceCount, m_monitoredServiceDao.countAll());
}
use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder in project opennms by OpenNMS.
the class BusinessServiceChildEdgeIT method canCreateReadUpdateAndDeleteEdges.
@Test
public void canCreateReadUpdateAndDeleteEdges() {
// Create the Parent Business Service
BusinessServiceEntity parent = new BusinessServiceEntityBuilder().name("Parent Service").reduceFunction(new HighestSeverityEntity()).toEntity();
// Create the Child Business Service
BusinessServiceEntity child = new BusinessServiceEntityBuilder().name("Child Service").reduceFunction(new HighestSeverityEntity()).toEntity();
Long parentServiceId = m_businessServiceDao.save(parent);
Long childServiceId = m_businessServiceDao.save(child);
m_businessServiceDao.flush();
// Initially there should be no edges
assertEquals(0, m_businessServiceEdgeDao.countAll());
// Create an edge
BusinessServiceChildEdgeEntity edge = new BusinessServiceChildEdgeEntity();
edge.setMapFunction(new IdentityEntity());
edge.setBusinessService(parent);
edge.setChild(child);
m_businessServiceEdgeDao.save(edge);
m_businessServiceEdgeDao.flush();
// Read an edge
assertEquals(1, m_businessServiceEdgeDao.countAll());
assertEquals(edge, m_businessServiceEdgeDao.get(edge.getId()));
assertEquals(parentServiceId, edge.getBusinessService().getId());
assertEquals(childServiceId, edge.getChild().getId());
// Update an edge
edge.setWeight(2);
m_businessServiceEdgeDao.save(edge);
m_businessServiceEdgeDao.flush();
BusinessServiceEdgeEntity otherEdge = m_businessServiceEdgeDao.get(edge.getId());
assertEquals(edge, otherEdge);
assertEquals(1, m_businessServiceEdgeDao.countAll());
// Delete an edge
m_businessServiceEdgeDao.delete(edge);
assertEquals(0, m_businessServiceEdgeDao.countAll());
}
use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder 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.netmgt.bsm.test.BusinessServiceEntityBuilder in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method canAddIpServiceEdge.
@Test
public void canAddIpServiceEdge() throws Exception {
// Create a business service without any edges
BusinessServiceEntity service = new BusinessServiceEntityBuilder().name("Dummy Service").reduceFunction(new HighestSeverityEntity()).toEntity();
final Long serviceId = m_businessServiceDao.save(service);
m_businessServiceDao.flush();
// The Request to send to create an edge
IpServiceEdgeRequestDTO edgeRequestDTO = new IpServiceEdgeRequestDTO();
edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
// verify adding of not existing ip service is not possible
edgeRequestDTO.setIpServiceId(-1);
sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 404);
// verify adding of existing ip service is possible
edgeRequestDTO.setIpServiceId(10);
sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
// verify adding twice possible, but not modified
sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 304);
Assert.assertEquals(1, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
// verify adding of existing ip service is possible
edgeRequestDTO.setIpServiceId(17);
sendData(POST, getMediaType(), buildIpServiceEdgeUrl(serviceId), marshal(edgeRequestDTO), 200);
Assert.assertEquals(2, m_businessServiceDao.get(serviceId).getIpServiceEdges().size());
}
Aggregations