use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AvailabilityRestServiceIT method testGetAvailabilityNode.
@Test
@JUnitTemporaryDatabase
public void testGetAvailabilityNode() throws Exception {
final OnmsNode node = m_populator.getNode1();
final AvailabilityRestService ars = new AvailabilityRestService();
ars.setNodeDao(m_populator.getNodeDao());
final AvailabilityNode an = ars.getAvailabilityNode(node.getId());
assertNotNull(an);
System.err.println(JaxbUtils.marshal(an));
// Compare the object to the same node fetched via REST
String url = "/availability/nodes/" + node.getId();
AvailabilityNode restNode = getXmlObject(JaxbUtils.getContextFor(AvailabilityNode.class), url, 200, AvailabilityNode.class);
Assert.assertNotNull(restNode);
Assert.assertTrue(an.toString() + " != " + restNode.toString(), an.equals(restNode));
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class CategoryRestServiceIT method testCategoriesJson.
@Test
@JUnitTemporaryDatabase
public void testCategoriesJson() throws Exception {
String url = "/categories";
// GET all users
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/categories.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class IPhoneRestServiceIT method testAcknowlegement.
@Test
@JUnitTemporaryDatabase
public void testAcknowlegement() 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);
String 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());
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class OutageRestServiceIT method testOutagesJson.
@Test
@JUnitTemporaryDatabase
public void testOutagesJson() throws Exception {
String url = "/outages";
// GET all users
MockHttpServletRequest jsonRequest = createRequest(m_context, GET, url);
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
jsonRequest.setQueryString("limit=1&orderBy=id");
String json = sendRequest(jsonRequest, 200);
JSONObject restObject = new JSONObject(json);
JSONObject expectedObject = new JSONObject(IOUtils.toString(new FileInputStream("src/test/resources/v1/outages.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class OutageRestServiceIT method testOutageSearches.
@Test
@JUnitTemporaryDatabase
public void testOutageSearches() throws Exception {
MockHttpServletRequest jsonRequest = createRequest(m_context, GET, "/outages");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
jsonRequest.setQueryString("ipInterface.ipAddress=192.168.1.2");
String json = sendRequest(jsonRequest, 200);
LOG.debug(json);
JSONObject restObject = new JSONObject(json);
assertEquals(1, restObject.getJSONArray("outage").length());
jsonRequest = createRequest(m_context, GET, "/outages");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
// OnmsSeverity.MINOR
jsonRequest.setQueryString("comparator=ge&serviceLostEvent.eventSeverity=5");
json = sendRequest(jsonRequest, 200);
LOG.debug(json);
restObject = new JSONObject(json);
assertEquals(1, restObject.getJSONArray("outage").length());
jsonRequest = createRequest(m_context, GET, "/outages");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
// OnmsSeverity.CLEARED
jsonRequest.setQueryString("comparator=lt&serviceLostEvent.eventSeverity=2");
json = sendRequest(jsonRequest, 200);
LOG.debug(json);
restObject = new JSONObject(json);
assertEquals(2, restObject.getJSONArray("outage").length());
jsonRequest = createRequest(m_context, GET, "/outages");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
jsonRequest.setQueryString("comparator=like&serviceLostEvent.eventLogMsg=Test%25");
json = sendRequest(jsonRequest, 200);
LOG.debug(json);
restObject = new JSONObject(json);
assertEquals(3, restObject.getJSONArray("outage").length());
// Check serviceRegainedEvent filters
jsonRequest = createRequest(m_context, GET, "/outages");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
// OnmsSeverity.CLEARED
jsonRequest.setQueryString("comparator=lt&serviceRegainedEvent.eventSeverity=2");
json = sendRequest(jsonRequest, 200);
LOG.debug(json);
// There is one test outage that has been resolved
restObject = new JSONObject(json);
assertEquals(1, restObject.getJSONArray("outage").length());
jsonRequest = createRequest(m_context, GET, "/outages");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
jsonRequest.setQueryString("comparator=like&serviceRegainedEvent.eventLogMsg=Test%25");
json = sendRequest(jsonRequest, 200);
LOG.debug(json);
// There is one test outage that has been resolved
restObject = new JSONObject(json);
assertEquals(1, restObject.getJSONArray("outage").length());
}
Aggregations