Search in sources :

Example 41 with JUnitTemporaryDatabase

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

Example 42 with JUnitTemporaryDatabase

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

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());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 44 with JUnitTemporaryDatabase

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

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());
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) 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