Search in sources :

Example 71 with JUnitTemporaryDatabase

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);
}
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 72 with JUnitTemporaryDatabase

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);
}
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 73 with JUnitTemporaryDatabase

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);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 74 with JUnitTemporaryDatabase

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);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 75 with JUnitTemporaryDatabase

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']");
}
Also used : HashMap(java.util.HashMap) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

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