use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class IfServicesRestServiceIT method testGetServicesJson.
@Test
@JUnitTemporaryDatabase
public void testGetServicesJson() throws Exception {
String url = "/ifservices";
// GET all users
MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url);
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
jsonRequest.setQueryString("orderBy=id");
String json = sendRequest(jsonRequest, 200);
JSONObject restObject = new JSONObject(json);
JSONObject expectedObject = new JSONObject(IOUtils.toString(new FileInputStream("src/test/resources/v1/ifservices.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class NotificationRestServiceIT method testNotificationsJson.
@Test
@JUnitTemporaryDatabase
public void testNotificationsJson() throws Exception {
String url = "/notifications";
// 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/notifications.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class OutageRestServiceIT method testGetAllOutages.
@Test
@JUnitTemporaryDatabase
public void testGetAllOutages() throws Exception {
String xml = sendRequest(GET, "/outages", 200);
Assert.assertNotNull(xml);
MockHttpServletRequest jsonRequest = createRequest(m_context, GET, "/outages");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
String json = sendRequest(jsonRequest, 200);
Assert.assertNotNull(json);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class OutageRestServiceIT method testGetOutagesForNode.
@Test
@JUnitTemporaryDatabase
public void testGetOutagesForNode() throws Exception {
// Test last week (no outages)
MockHttpServletRequest jsonRequest = createRequest(m_context, GET, "/outages/forNode/1");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
String json = sendRequest(jsonRequest, 200);
JSONObject restObject = new JSONObject(json);
// 2 outstanding
Assert.assertEquals(2, restObject.getJSONArray("outage").length());
// Test a range with outages
long start = 1436846400000l;
long end = 1436932800000l;
jsonRequest = createRequest(m_context, GET, "/outages/forNode/1");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
jsonRequest.setQueryString("start=" + start + "&end=" + end);
json = sendRequest(jsonRequest, 200);
restObject = new JSONObject(json);
for (int i = 0; i < restObject.getJSONArray("outage").length(); i++) {
JSONObject obj = restObject.getJSONArray("outage").getJSONObject(i);
Assert.assertTrue(obj.getLong("ifLostService") > start);
Assert.assertTrue(obj.getLong("ifLostService") < end);
}
// Test a range without outages
jsonRequest = createRequest(m_context, GET, "/outages/forNode/1");
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
jsonRequest.setQueryString("start=1436932800000&end=1437019200000");
json = sendRequest(jsonRequest, 200);
restObject = new JSONObject(json);
// 2 outstanding
Assert.assertEquals(2, restObject.getJSONArray("outage").length());
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class ResourceRestServiceIT method testResourcesJson.
@Test
@JUnitTemporaryDatabase
public void testResourcesJson() throws Exception {
String url = "/resources";
// 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);
final String jsonString = IOUtils.toString(new FileInputStream("src/test/resources/v1/resources.json"));
JSONObject expectedObject = new JSONObject(jsonString.replace(".jrb", m_extension));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
Aggregations