use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder 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());
}
use of org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder in project opennms by OpenNMS.
the class BusinessServiceSearchProviderIT method verifyQuery.
@Test
public void verifyQuery() {
BusinessServiceEntity bs1 = new BusinessServiceEntityBuilder().name("Test Service").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs1.key1", new IdentityEntity(), 1).addReductionKey("bs1.key2", new IdentityEntity(), 1).toEntity();
BusinessServiceEntity bs2 = new BusinessServiceEntityBuilder().name("Real Service 2").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs2.key1", new IdentityEntity(), 1).addReductionKey("bs2.key2", new IdentityEntity(), 1).toEntity();
businessServiceDao.save(bs1);
businessServiceDao.save(bs2);
businessServiceDao.flush();
// prepare mocks
TopologyServiceClient topologyServiceClientMock = EasyMock.createNiceMock(TopologyServiceClient.class);
EasyMock.expect(topologyServiceClientMock.getVertex(EasyMock.anyObject(BusinessServiceVertex.class))).andReturn(// always return a vertex, it just needs to be not null
new AbstractVertex("bsm", "0", "Dummy Vertex"));
GraphContainer graphContainerMock = EasyMock.createNiceMock(GraphContainer.class);
EasyMock.expect(graphContainerMock.getTopologyServiceClient()).andReturn(topologyServiceClientMock).anyTimes();
EasyMock.replay(graphContainerMock, topologyServiceClientMock);
// try searching
final BusinessServiceSearchProvider provider = new BusinessServiceSearchProvider();
provider.setBusinessServiceManager(businessServiceManager);
final SearchQuery query = new AbstractSearchQuery("Test") {
@Override
public boolean matches(String label) {
// always match, it does not matter
return true;
}
};
final List<SearchResult> result = provider.query(query, graphContainerMock);
Assert.assertEquals(1, result.size());
EasyMock.verify(graphContainerMock, topologyServiceClientMock);
}
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 BusinessServiceDaoIT method verifyDeleteOnCascade.
/**
* If we do not explicitly delete the map or reduce function it should be deleted if not referenced anymore.
*/
@Test
@Transactional
public void verifyDeleteOnCascade() {
BusinessServiceEntity child2 = new BusinessServiceEntityBuilder().name("Child 2").reduceFunction(new HighestSeverityEntity()).addReductionKey("some-key", new IdentityEntity()).toEntity();
BusinessServiceEntity child1 = new BusinessServiceEntityBuilder().name("Child 1").reduceFunction(new HighestSeverityEntity()).addChildren(child2, new IdentityEntity()).toEntity();
BusinessServiceEntity parent = new BusinessServiceEntityBuilder().name("Parent Web Servers").addAttribute("dc", "RDU").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).addIpService(getMonitoredServiceFromNode1(), new IdentityEntity()).reduceFunction(m_highestSeverity).addChildren(child1, new IdentityEntity()).toEntity();
m_businessServiceDao.save(child2);
m_businessServiceDao.save(child1);
m_businessServiceDao.save(parent);
m_businessServiceDao.flush();
assertEquals(3, m_businessServiceDao.countAll());
assertEquals(3, m_reductionFunctionDao.countAll());
assertEquals(6, m_edgeDao.countAll());
// Deletion of child does not delete the edges referencing to that child
// remove all parent -> child associations manually
BusinessServiceChildEdgeEntity parentToChild1Edge = parent.getChildEdges().iterator().next();
parent.removeEdge(parentToChild1Edge);
m_edgeDao.delete(parentToChild1Edge);
// edges do not need to be deleted manually, deletes will be cascaded
m_businessServiceDao.delete(child1);
m_businessServiceDao.flush();
assertEquals(2, m_businessServiceDao.countAll());
assertEquals(2, m_reductionFunctionDao.countAll());
assertEquals(4, m_edgeDao.countAll());
// Deletion of parent should delete all references
m_businessServiceDao.delete(parent);
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(1, m_reductionFunctionDao.countAll());
assertEquals(1, m_edgeDao.countAll());
// Deletion of Child 2 should also work
m_businessServiceDao.delete(child2);
assertEquals(0, m_businessServiceDao.countAll());
assertEquals(0, m_reductionFunctionDao.countAll());
assertEquals(0, m_edgeDao.countAll());
}
Aggregations