use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AcknowledgmentRestServiceIT method testGetAcksJson.
@Test
@JUnitTemporaryDatabase
public void testGetAcksJson() throws Exception {
String url = "/acks";
// GET all items
MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url);
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/acks.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmsJson.
@Test
@JUnitTemporaryDatabase
public void testAlarmsJson() throws Exception {
String url = "/alarms";
// GET all items
MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url, "admin", Arrays.asList(new String[] { Authentication.ROLE_ADMIN }));
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/alarms.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmClearAsReadOnly.
@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsReadOnly() throws Exception {
setUser("ranger", new String[] { "ROLE_MOBILE", "ROLE_READONLY" });
final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 403);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AlarmRestServiceIT method testAlarmClearAsAdmin.
@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsAdmin() throws Exception {
setUser("admin", new String[] { "ROLE_ADMIN" });
final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 204);
final String xml = sendRequest(GET, "/alarms/" + alarm.getId(), 200);
final OnmsAlarm fromRest = JaxbUtils.unmarshal(OnmsAlarm.class, xml);
assertEquals(fromRest.getSeverity(), OnmsSeverity.CLEARED);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AlarmRestServiceIT method testComplexQuery.
@Test
@JUnitTemporaryDatabase
@Transactional
public void testComplexQuery() throws Exception {
String xml = null;
final Map<String, String> parameters = new HashMap<String, String>();
createAlarm(OnmsSeverity.CRITICAL);
for (final OnmsAlarm alarm : getAlarmDao().findAll()) {
System.err.println("alarm = " + alarm);
}
parameters.put("offset", "00");
parameters.put("limit", "10");
parameters.put("orderBy", "lastEventTime");
parameters.put("order", "desc");
// original requirements:
// http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&lastEventTime=2011-08-19T11:11:11.000-07:00&comparator=gt&severity=MAJOR&comparator=eq
// modified version:
// http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&query=lastEventTime%20%3E%20'2011-08-19T11%3A11%3A11.000-07%3A00'%20AND%20severity%20%3D%20MAJOR
parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity = 3");
xml = sendRequest(GET, "/alarms", parameters, 200);
// assertTrue(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
assertXpathMatches(xml, "//alarm[@severity='NORMAL' and @id='1']");
// assertFalse(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
assertXpathDoesNotMatch(xml, "//alarm[@severity='CRITICAL' and @id='2']");
parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity >= 3");
xml = sendRequest(GET, "/alarms", parameters, 200);
// assertTrue(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
assertXpathMatches(xml, "//alarm[@severity='NORMAL' and @id='1']");
// assertTrue(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
assertXpathMatches(xml, "//alarm[@severity='CRITICAL' and @id='2']");
parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity >= NORMAL");
xml = sendRequest(GET, "/alarms", parameters, 200);
// assertTrue(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
assertXpathMatches(xml, "//alarm[@severity='NORMAL' and @id='1']");
// assertTrue(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
assertXpathMatches(xml, "//alarm[@severity='CRITICAL' and @id='2']");
parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity < NORMAL");
xml = sendRequest(GET, "/alarms", parameters, 200);
// assertFalse(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
assertXpathDoesNotMatch(xml, "//alarm[@severity='NORMAL' and @id='1']");
// assertFalse(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
assertXpathDoesNotMatch(xml, "//alarm[@severity='CRITICAL' and @id='2']");
// assertTrue(xml.contains("count=\"0\""));
assertXpathMatches(xml, "//alarms[@totalCount='0']");
// original requirements:
// http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&lastEventTime=2011-08-19T11:11:11.000-07:00&comparator=gt&severity=MAJOR&comparator=eq&ackUser=myuser&comparator=eq
// acked - modified version:
// http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&query=lastEventTime%20%3E%20'2011-08-19T11%3A11%3A11.000-07%3A00'%20AND%20severity%20%3E%20MAJOR%20AND%20alarmAckUser%20%3D%20'admin'
parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity > MAJOR AND alarmAckUser = 'admin'");
xml = sendRequest(GET, "/alarms", parameters, 200);
// assertFalse(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
assertXpathDoesNotMatch(xml, "//alarm[@severity='NORMAL' and @id='1']");
// assertTrue(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
assertXpathMatches(xml, "//alarm[@severity='CRITICAL' and @id='2']");
// unacked - modified version:
// http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&query=lastEventTime%20%3E%20'2011-08-19T11%3A11%3A11.000-07%3A00'%20AND%20severity%20%3E%20MAJOR%20AND%20alarmAckUser%20IS%20NULL
parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity > MAJOR AND alarmAckUser IS NULL");
xml = sendRequest(GET, "/alarms", parameters, 200);
// assertTrue(xml.contains("count=\"0\""));
assertXpathMatches(xml, "//alarms[@totalCount='0']");
// unacked - modified version:
// http://localhost:8980/opennms/rest/alarms?offset=00&limit=10&orderBy=lastEventTime&order=desc&query=lastEventTime%20%3E%20'2011-08-19T11%3A11%3A11.000-07%3A00'%20AND%20severity%20%3C%20MAJOR%20AND%20alarmAckUser%20IS%20NULL
parameters.put("query", "lastEventTime > '2011-08-19T11:11:11.000-07:00' AND severity < MAJOR AND alarmAckUser IS NULL");
xml = sendRequest(GET, "/alarms", parameters, 200);
// assertTrue(xml.contains("<alarm severity=\"NORMAL\" id=\"1\""));
assertXpathMatches(xml, "//alarm[@severity='NORMAL' and @id='1']");
// assertFalse(xml.contains("<alarm severity=\"CRITICAL\" id=\"2\""));
assertXpathDoesNotMatch(xml, "//alarm[@severity='CRITICAL' and @id='2']");
}
Aggregations