use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class NodeRestServiceIT method testNode.
@Test
@JUnitTemporaryDatabase
public void testNode() throws Exception {
// Testing POST
createNode();
String url = "/nodes";
// Testing GET Collection
String xml = sendRequest(GET, url, 200);
assertTrue(xml.contains("Darwin TestMachine 9.4.0 Darwin Kernel Version 9.4.0"));
OnmsNodeList list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
assertEquals(1, list.size());
assertEquals(xml, "TestMachine0", list.get(0).getLabel());
// Testing orderBy
xml = sendRequest(GET, url, parseParamData("orderBy=sysObjectId"), 200);
list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
assertEquals(1, list.size());
assertEquals("TestMachine0", list.get(0).getLabel());
// Add 4 more nodes
for (m_nodeCounter = 1; m_nodeCounter < 5; m_nodeCounter++) {
createNode();
}
// Testing limit/offset
xml = sendRequest(GET, url, parseParamData("limit=3&offset=0&orderBy=label"), 200);
list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
assertEquals(3, list.size());
assertEquals(Integer.valueOf(3), list.getCount());
assertEquals(Integer.valueOf(5), list.getTotalCount());
assertEquals("TestMachine0", list.get(0).getLabel());
assertEquals("TestMachine1", list.get(1).getLabel());
assertEquals("TestMachine2", list.get(2).getLabel());
// This filter should match
xml = sendRequest(GET, url, parseParamData("comparator=like&label=%25Test%25"), 200);
LOG.info(xml);
list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
assertEquals(Integer.valueOf(5), list.getCount());
assertEquals(Integer.valueOf(5), list.getTotalCount());
// This filter should fail (return 0 results)
xml = sendRequest(GET, url, parseParamData("comparator=like&label=%25DOES_NOT_MATCH%25"), 200);
LOG.info(xml);
list = JaxbUtils.unmarshal(OnmsNodeList.class, xml);
assertEquals(null, list.getCount());
assertEquals(Integer.valueOf(0), list.getTotalCount());
// Testing PUT
url += "/1";
sendPut(url, "sysContact=OpenNMS&assetRecord.manufacturer=Apple&assetRecord.operatingSystem=MacOSX Leopard", 204);
// Testing GET Single Object
xml = sendRequest(GET, url, 200);
assertTrue(xml.contains("<sysContact>OpenNMS</sysContact>"));
assertTrue(xml.contains("<operatingSystem>MacOSX Leopard</operatingSystem>"));
// Testing DELETE
m_mockEventIpcManager.getEventAnticipator().reset();
m_mockEventIpcManager.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.DELETE_NODE_EVENT_UEI, "Test").setNodeid(1).getEvent());
sendRequest(DELETE, url, 204);
m_mockEventIpcManager.getEventAnticipator().waitForAnticipated(10000);
m_mockEventIpcManager.getEventAnticipator().verifyAnticipated();
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class NodeRestServiceIT method testSnmpInterfaceJson.
@Test
@JUnitTemporaryDatabase
public void testSnmpInterfaceJson() throws Exception {
createSnmpInterface();
String url = "/nodes/1/snmpinterfaces";
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);
final JSONArray ja = jo.getJSONArray("snmpInterface");
assertEquals(1, ja.length());
jo = ja.getJSONObject(0);
assertEquals(6, jo.getInt("ifIndex"));
assertEquals(1, jo.getInt("ifOperStatus"));
assertEquals("en1", jo.getString("ifDescr"));
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class OutageDaoIT method testGetMatchingOutages.
@Test
@JUnitTemporaryDatabase
public void testGetMatchingOutages() {
m_transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
m_nodeDao.save(node);
insertEntitiesAndOutage("172.16.1.1", "ICMP", node);
}
});
/*
* We need to flush and finish the transaction because JdbcFilterDao
* gets its own connection from the DataSource and won't see our data
* otherwise.
*/
m_transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
String[] svcs = new String[] { "ICMP" };
ServiceSelector selector = new ServiceSelector("ipAddr IPLIKE 172.16.1.1", Arrays.asList(svcs));
Collection<OnmsOutage> outages = m_outageDao.matchingCurrentOutages(selector);
assertEquals("outage count", 1, outages.size());
}
});
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class OutageDaoIT method testGetMatchingOutagesWithEmptyServiceList.
@Test
@JUnitTemporaryDatabase
public void testGetMatchingOutagesWithEmptyServiceList() {
m_transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
m_nodeDao.save(node);
insertEntitiesAndOutage("172.16.1.1", "ICMP", node);
}
});
/*
* We need to flush and finish the transaction because JdbcFilterDao
* gets its own connection from the DataSource and won't see our data
* otherwise.
*/
m_transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
ServiceSelector selector = new ServiceSelector("ipAddr IPLIKE 172.16.1.1", new ArrayList<String>(0));
Collection<OnmsOutage> outages = m_outageDao.matchingCurrentOutages(selector);
assertEquals(1, outages.size());
}
});
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class HibernateCriteriaConverterIT method testNodeQuery.
@Test
@JUnitTemporaryDatabase
public void testNodeQuery() throws Exception {
List<OnmsNode> nodes;
// first, try with OnmsCriteria
final OnmsCriteria crit = new OnmsCriteria(OnmsNode.class);
crit.add(org.hibernate.criterion.Restrictions.isNotNull("id"));
nodes = m_nodeDao.findMatching(crit);
assertEquals(6, nodes.size());
// then the same with the builder
final CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
cb.isNotNull("id");
nodes = m_nodeDao.findMatching(cb.toCriteria());
assertEquals(6, nodes.size());
cb.eq("label", "node1").join("ipInterfaces", "ipInterface").eq("ipInterface.ipAddress", "192.168.1.1");
nodes = m_nodeDao.findMatching(cb.toCriteria());
assertEquals(1, nodes.size());
}
Aggregations