Search in sources :

Example 46 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class NodeRestServiceIT method testIpInterfaceJson.

@Test
@JUnitTemporaryDatabase
public void testIpInterfaceJson() throws Exception {
    createIpInterface();
    String url = "/nodes/1/ipinterfaces";
    final MockHttpServletRequest req = createRequest(m_context, GET, url);
    req.addHeader("Accept", MediaType.APPLICATION_JSON);
    req.addParameter("limit", "0");
    final String json = sendRequest(req, 200);
    assertNotNull(json);
    assertFalse(json.contains("The Owner"));
    JSONObject jo = new JSONObject(json);
    JSONArray ja = jo.getJSONArray("ipInterface");
    assertEquals(1, ja.length());
    jo = ja.getJSONObject(0);
    assertTrue(jo.isNull("ifIndex"));
    assertEquals("10.10.10.10", jo.getString("ipAddress"));
    assertEquals(1, jo.getInt("nodeId"));
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JSONArray(org.json.JSONArray) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 47 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class NodeRestServiceIT method canGetNodesWithFilterRule.

@Test
@JUnitTemporaryDatabase
public void canGetNodesWithFilterRule() throws Exception {
    // Create a node which doesn't have any categories assigned
    createNode();
    // The FilterDao requires requires the node to have at least one IP interface
    createIpInterface();
    String url = "/nodes";
    // Retrieve all nodes with the 'Routers' category, there should be none
    String xml = sendRequest(GET, url, parseParamData("filterRule=catincRouters"), 200);
    OnmsNodeList list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
    assertEquals(0, list.size());
    assertEquals(Integer.valueOf(0), list.getTotalCount());
    // Assign the category to the node
    sendRequest(POST, "/nodes/1/categories/Routers", 201);
    xml = sendRequest(GET, "/nodes/1/categories", 200);
    assertTrue(xml.contains("name=\"Routers\""));
    // Now apply try searching with the filter again, we should get a match
    xml = sendRequest(GET, url, parseParamData("filterRule=catincRouters"), 200);
    list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
    assertEquals(xml, 1, list.size());
    assertEquals(xml, Integer.valueOf(1), list.getTotalCount());
    assertEquals(xml, "TestMachine0", list.get(0).getLabel());
}
Also used : OnmsNodeList(org.opennms.netmgt.model.OnmsNodeList) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 48 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class NodeRestServiceIT method testNodeComboQuery.

@Test
@JUnitTemporaryDatabase
public void testNodeComboQuery() throws Exception {
    String url = "/nodes";
    MockHttpServletRequest request = createRequest(m_context, GET, url);
    request.addParameter("_dc", "1235761409572");
    request.addParameter("start", "0");
    request.addParameter("limit", "10");
    request.addParameter("query", "hell");
    sendRequest(request, 200);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 49 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class NodeRestServiceIT method testNodeJson.

@Test
@JUnitTemporaryDatabase
public void testNodeJson() throws Exception {
    createSnmpInterface();
    final MockHttpServletRequest req = createRequest(m_context, GET, "/nodes");
    req.addHeader("Accept", MediaType.APPLICATION_JSON);
    req.addParameter("limit", "0");
    String json = sendRequest(req, 200);
    JSONObject jo = new JSONObject(json);
    final JSONArray ja = jo.getJSONArray("node");
    assertEquals(1, ja.length());
    jo = ja.getJSONObject(0);
    assertEquals("A", jo.getString("type"));
    assertEquals("TestMachine0", jo.getString("label"));
    assertEquals("Default", jo.getString("location"));
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JSONArray(org.json.JSONArray) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 50 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class EventUtilHibernateIT method testExpandParms.

@Test
@JUnitTemporaryDatabase
public void testExpandParms() {
    String testString = "%uei%:%nodeid%:%nodelabel%:%nodelocation%";
    /*
         * Checking default location
         */
    Event event1 = new EventBuilder("testUei", "testSource").setNodeid(1).getEvent();
    String string1 = eventUtilDaoImpl.expandParms(testString, event1);
    assertEquals("testUei:1:node1:Default", string1);
    /*
         * Checking custom location
         */
    OnmsNode onmsNode = m_populator.getNodeDao().get(2);
    onmsNode.setLocation(m_populator.getMonitoringLocationDao().get("RDU"));
    m_populator.getNodeDao().update(onmsNode);
    Event event2 = new EventBuilder("testUei", "testSource").setNodeid(2).getEvent();
    String string2 = eventUtilDaoImpl.expandParms(testString, event2);
    assertEquals("testUei:2:node2:RDU", string2);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) Event(org.opennms.netmgt.xml.event.Event) 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