use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class SnmpAssetProvisioningAdapterFullIT method testUpdateNode.
@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testUpdateNode() throws InterruptedException {
AdapterOperationChecker verifyOperations = new AdapterOperationChecker(2);
m_adapter.getOperationQueue().addListener(verifyOperations);
try {
OnmsNode node = m_nodeDao.get(NODE_ID);
assertNotNull(node);
int firstNodeId = node.getId();
assertNull(node.getAssetRecord().getComment());
m_adapter.addNode(firstNodeId);
m_adapter.updateNode(firstNodeId);
assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS));
assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS));
assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS));
assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(firstNodeId).size());
node = m_nodeDao.get(firstNodeId);
assertNotNull(node);
System.out.println("ID: " + node.getAssetRecord().getId());
System.out.println("Comment: " + node.getAssetRecord().getComment());
assertNotNull("AssetRecord comment is null", node.getAssetRecord().getComment());
assertEquals(EXPECTED_COMMENT_FIELD, node.getAssetRecord().getComment());
} finally {
m_adapter.getOperationQueue().removeListener(verifyOperations);
}
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmUpdates.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testAlarmUpdates() throws Exception {
createAlarm(OnmsSeverity.MAJOR);
OnmsAlarm alarm = getLastAlarm();
alarm.setAlarmAckTime(null);
alarm.setAlarmAckUser(null);
getAlarmDao().saveOrUpdate(alarm);
final Integer alarmId = alarm.getId();
sendPut("/alarms", "ack=true&alarmId=" + alarmId, 204);
String xml = sendRequest(GET, "/alarms/" + alarmId, 200);
assertTrue(xml.contains("ackUser>admin<"));
sendPut("/alarms/" + alarmId, "clear=true", 204);
xml = sendRequest(GET, "/alarms/" + alarmId, 200);
assertTrue(xml.contains("severity=\"CLEARED\""));
sendPut("/alarms/" + alarmId, "escalate=true", 204);
xml = sendRequest(GET, "/alarms/" + alarmId, 200);
assertTrue(xml.contains("severity=\"NORMAL\""));
sendPut("/alarms/" + alarmId, "ticketId=12345", 204);
xml = sendRequest(GET, "/alarms/" + alarmId, 200);
assertTrue(xml.contains("<troubleTicket>12345</troubleTicket>"));
sendPut("/alarms/" + alarmId, "ticketState=UPDATE_PENDING", 204);
xml = sendRequest(GET, "/alarms/" + alarmId, 200);
sendPut("/alarms/" + alarmId, "ticketState=UPDATE_PENDING", 204);
alarm = getLastAlarm();
alarm.setSeverity(OnmsSeverity.MAJOR);
alarm.setAlarmAckTime(null);
alarm.setAlarmAckUser(null);
getAlarmDao().saveOrUpdate(alarm);
// Log in as a normal REST user and attempt to resolve an alarm as a different user.
// This should fail with a 403 forbidden.
setUser("foo", new String[] { "ROLE_REST" });
sendPut("/alarms/" + alarmId, "ack=true&ackUser=bar", 403);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmClearAsUser.
@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsUser() throws Exception {
setUser("ranger", new String[] { "ROLE_USER" });
final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 204);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AcknowledgmentRestServiceIT method testAcknowlegeAlarm.
@Test
@JUnitTemporaryDatabase
public void testAcknowlegeAlarm() throws Exception {
final Pattern p = Pattern.compile("^.*<ackTime>(.*?)</ackTime>.*$", Pattern.DOTALL & Pattern.MULTILINE);
sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1&action=ack", 200);
// Try to fetch a non-existent ack, get 404 Not Found
String xml = sendRequest(GET, "/acks/999999", 404);
xml = sendRequest(GET, "/acks/count", 200);
// {@link DatabasePopulator} adds one ack so we have 2 total
assertEquals("2", xml);
Integer newAckId = null;
for (OnmsAcknowledgment ack : getXmlObject(JaxbUtils.getContextFor(OnmsAcknowledgmentCollection.class), "/acks", 200, OnmsAcknowledgmentCollection.class).getObjects()) {
if (AckType.UNSPECIFIED.equals(ack.getAckType())) {
// Ack from DatabasePopulator
assertEquals(AckAction.UNSPECIFIED, ack.getAckAction());
assertEquals("admin", ack.getAckUser());
} else if (AckType.ALARM.equals(ack.getAckType())) {
// Ack that we just created
assertEquals(new Integer(1), ack.getRefId());
assertEquals(AckAction.ACKNOWLEDGE, ack.getAckAction());
newAckId = ack.getId();
} else {
fail("Unrecognized alarm type: " + ack.getAckType().toString());
}
}
if (newAckId == null) {
fail("Couldn't determine ID of new ack");
}
xml = sendRequest(GET, "/acks/" + newAckId, 200);
xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200);
Matcher m = p.matcher(xml);
assertTrue(m.matches());
assertTrue(m.group(1).length() > 0);
sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1&action=unack", 200);
xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200);
m = p.matcher(xml);
assertFalse(m.matches());
// POST with no argument, this will ack by default
sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1", 200);
xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200);
m = p.matcher(xml);
assertTrue(m.matches());
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AcknowledgmentRestServiceIT method testAcknowlegeNotification.
@Test
@JUnitTemporaryDatabase
public void testAcknowlegeNotification() throws Exception {
final Pattern p = Pattern.compile("^.*<answeredBy>(.*?)</answeredBy>.*$", Pattern.DOTALL & Pattern.MULTILINE);
sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "notifId=1&action=ack", 200);
String xml = sendRequest(GET, "/notifications/1", new HashMap<String, String>(), 200);
Matcher m = p.matcher(xml);
assertTrue(m.matches());
assertTrue(m.group(1).equals("admin"));
sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "notifId=1&action=unack", 200);
xml = sendRequest(GET, "/notifications/1", new HashMap<String, String>(), 200);
m = p.matcher(xml);
assertFalse(m.matches());
}
Aggregations