use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class TemporaryDatabaseExecutionListener method afterTestMethod.
@Override
public void afterTestMethod(final TestContext testContext) throws Exception {
Throwable closeThrowable = null;
// System.err.println(String.format("TemporaryDatabaseExecutionListener.afterTestMethod(%s)", testContext));
final JUnitTemporaryDatabase jtd = findAnnotation(testContext);
if (jtd == null) {
return;
}
// Close down the data sources that are referenced by the static DataSourceFactory helper classes
try {
DataSourceFactory.close();
XADataSourceFactory.close();
} catch (Throwable t) {
closeThrowable = t;
}
try {
if (m_createNewDatabases && m_database != null) {
m_database.drop();
}
} finally {
//
if (jtd.dirtiesContext()) {
testContext.markApplicationContextDirty(HierarchyMode.CURRENT_LEVEL);
testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
} else {
if (m_database != m_databases.peek()) {
testContext.markApplicationContextDirty(HierarchyMode.CURRENT_LEVEL);
testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
}
}
}
if (closeThrowable != null) {
throw new Exception("Caught a Throwable while closing database connections after test. Pickup after yourself! " + closeThrowable, closeThrowable);
}
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class ProvisionerIT method testImportWithGeoData.
@Test(timeout = 300000)
@JUnitTemporaryDatabase
public void testImportWithGeoData() throws Exception {
importFromResource("classpath:/tec_dump.xml", Boolean.TRUE.toString());
final NodeDao nodeDao = getNodeDao();
OnmsNode node = nodeDao.findByForeignId("empty", "4243");
nodeDao.initialize(node.getAssetRecord());
nodeDao.initialize(node.getAssetRecord().getGeolocation());
OnmsGeolocation geolocation = new OnmsGeolocation();
geolocation.setAddress1("220 Chatham Business Dr.");
geolocation.setCity("Pittsboro");
geolocation.setState("NC");
geolocation.setZip("27312");
geolocation.setLatitude(35.715723);
geolocation.setLongitude(-79.162261);
node.getAssetRecord().setGeolocation(geolocation);
nodeDao.saveOrUpdate(node);
nodeDao.flush();
node = nodeDao.findByForeignId("empty", "4243");
geolocation = node.getAssetRecord().getGeolocation();
assertNotNull(geolocation.getLatitude());
assertNotNull(geolocation.getLongitude());
assertEquals(Float.valueOf(35.715723f).doubleValue(), geolocation.getLatitude().doubleValue(), 0.1d);
assertEquals(Float.valueOf(-79.162261f).doubleValue(), geolocation.getLongitude().doubleValue(), 0.1d);
System.err.println("=================================================================BLEARGH");
importFromResource("classpath:/tec_dump.xml", Boolean.TRUE.toString());
node = nodeDao.findByForeignId("empty", "4243");
geolocation = node.getAssetRecord().getGeolocation();
// Ensure it is reset
assertNull(geolocation.asAddressString());
assertNull(geolocation.getLatitude());
assertNull(geolocation.getLongitude());
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class ProvisionerIT method testImportWithNodeCategoryEvents.
@Test(timeout = 300000)
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testImportWithNodeCategoryEvents() throws Exception {
final int nextNodeId = m_nodeDao.getNextNodeId();
final MockNetwork network = new MockNetwork();
final MockNode node = network.addNode(nextNodeId, "test");
network.addInterface("172.16.1.1");
network.addService("ICMP");
anticipateCreationEvents(node);
m_eventAnticipator.anticipateEvent(getNodeCategoryEvent(nextNodeId, "test"));
m_eventAnticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_UPDATED_EVENT_UEI, "Test").setNodeid(nextNodeId).getEvent());
// we should not get category update events on a re-import now, that happens during the scan phase
// m_eventAnticipator.anticipateEvent(getNodeCategoryEvent(nextNodeId, "test"));
importFromResource("classpath:/requisition_with_node_categories.xml", Boolean.TRUE.toString());
importFromResource("classpath:/requisition_with_node_categories_changed.xml", Boolean.TRUE.toString());
m_eventAnticipator.verifyAnticipated();
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AlarmStatsRestServiceIT method testGetAlarmStatsJson.
/**
* TODO: Doesn't test firstAutomationTime, lastAutomationTime, reductionKey,
* reductionKeyMemo, suppressedTime, suppressedUntil, clearKey, or stickyMemo
* fields.
*/
@Test
@JUnitTemporaryDatabase
public void testGetAlarmStatsJson() throws Exception {
createAlarm(OnmsSeverity.CLEARED, "admin");
createAlarm(OnmsSeverity.MAJOR, "admin");
createAlarm(OnmsSeverity.CRITICAL, "admin");
createAlarm(OnmsSeverity.CRITICAL, null);
createAlarm(OnmsSeverity.MINOR, null);
createAlarm(OnmsSeverity.NORMAL, null);
// GET all users
MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, "/stats/alarms");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
String json = sendRequest(jsonRequest, 200);
JSONObject restObject = new JSONObject(json);
JSONObject expectedObject = new JSONObject(IOUtils.toString(new FileInputStream("src/test/resources/v1/stats_alarms.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AvailabilityRestServiceIT method testGetAvailabilityJson.
@Test
@JUnitTemporaryDatabase
public void testGetAvailabilityJson() throws Exception {
String url = "/availability";
// GET all items
MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url);
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
String json = sendRequest(jsonRequest, 200);
// TODO: The comment and last-updated fields are blank in the objects that are
// fetched. Figure out how to get them to populate so that we can test serialization
// of those values.
//
JSONObject restObject = new JSONObject(json);
JSONObject expectedObject = new JSONObject(IOUtils.toString(new FileInputStream("src/test/resources/v1/availability.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
// GET node item
jsonRequest = createRequest(m_servletContext, GET, url + "/nodes/" + m_populator.getNode1().getId());
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
json = sendRequest(jsonRequest, 200);
restObject = new JSONObject(json);
expectedObject = new JSONObject(IOUtils.toString(new FileInputStream("src/test/resources/v1/availability_node.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
Aggregations