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"));
}
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());
}
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);
}
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"));
}
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);
}
Aggregations