Search in sources :

Example 86 with JUnitTemporaryDatabase

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);
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 87 with JUnitTemporaryDatabase

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);
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 88 with JUnitTemporaryDatabase

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);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 89 with JUnitTemporaryDatabase

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());
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 90 with JUnitTemporaryDatabase

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);
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)109 Test (org.junit.Test)105 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 Date (java.util.Date)20 JSONObject (org.json.JSONObject)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 Transactional (org.springframework.transaction.annotation.Transactional)14 FileInputStream (java.io.FileInputStream)10 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)10 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)8 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)7 AlarmIdFilter (org.opennms.web.alarm.filter.AlarmIdFilter)7 HashMap (java.util.HashMap)6 OutageCriteria (org.opennms.web.outage.filter.OutageCriteria)6 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 JSONArray (org.json.JSONArray)4 AcknowledgedByFilter (org.opennms.web.alarm.filter.AcknowledgedByFilter)4