use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceEdgeDaoIT method canCreateReadUpdateAndDeleteEdges.
@Test
public void canCreateReadUpdateAndDeleteEdges() {
// Create a business service
BusinessServiceEntity bs = new BusinessServiceEntity();
bs.setName("Web Servers");
bs.setAttribute("dc", "RDU");
bs.setReductionFunction(m_highestSeverity);
m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// Initially there should be no edges
assertEquals(0, m_businessServiceEdgeDao.countAll());
// Create an edge
IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
edge.setMapFunction(m_identity);
edge.setBusinessService(bs);
// Grab the first monitored service from node 1
OnmsMonitoredService ipService = m_databasePopulator.getNode1().getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
edge.setIpService(ipService);
m_businessServiceEdgeDao.save(edge);
m_businessServiceEdgeDao.flush();
// Read an edge
assertEquals(edge, m_businessServiceEdgeDao.get(edge.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.persistence.api.IPServiceEdgeEntity 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());
}
use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity 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());
}
use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity in project opennms by OpenNMS.
the class IPServiceEdgeDaoIT method ipServiceEdgesWithRelatedIpServicesAreDeletedOnCascade.
@Test
public void ipServiceEdgesWithRelatedIpServicesAreDeletedOnCascade() throws InterruptedException {
// Create a business service
BusinessServiceEntity bs = new BusinessServiceEntity();
bs.setName("Mont Cascades");
bs.setAttribute("dc", "RDU");
bs.setReductionFunction(m_highestSeverity);
m_businessServiceDao.save(bs);
m_businessServiceDao.flush();
// Initially there should be no edges
assertEquals(0, m_businessServiceEdgeDao.countAll());
// Create an edge
IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
edge.setMapFunction(m_identity);
edge.setBusinessService(bs);
// Grab the first monitored service from node 1
OnmsNode node = m_databasePopulator.getNode1();
OnmsMonitoredService ipService = node.getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
edge.setIpService(ipService);
m_businessServiceEdgeDao.save(edge);
m_businessServiceEdgeDao.flush();
bs.addEdge(edge);
m_businessServiceDao.update(bs);
m_businessServiceDao.flush();
// We should have a single business service with a single IP service associated
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(1, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
// Now delete the node
m_nodeDao.delete(node);
m_nodeDao.flush();
// The business service should still be present, but the IP service should have been deleted
// by the foreign key constraint
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(0, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
}
use of org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method setIpServiceEdges.
@Override
public void setIpServiceEdges(BusinessService businessService, Set<IpServiceEdge> ipServiceEdges) {
final BusinessServiceEntity entity = getBusinessServiceEntity(businessService);
for (final IPServiceEdgeEntity e : entity.getIpServiceEdges()) {
entity.removeEdge(e);
}
ipServiceEdges.forEach(e -> entity.addEdge(((IpServiceEdgeImpl) e).getEntity()));
}
Aggregations