use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class NodeRestServiceIT method testMonitoredService.
@Test
@JUnitTemporaryDatabase
public void testMonitoredService() throws Exception {
createService();
String url = "/nodes/1/ipinterfaces/10.10.10.10/services";
String xml = sendRequest(GET, url, 200);
assertTrue(xml.contains("<name>ICMP</name>"));
url += "/ICMP";
sendPut(url, "status=A", 204);
xml = sendRequest(GET, url, 200);
assertTrue(xml.contains("status=\"A\""));
m_mockEventIpcManager.getEventAnticipator().reset();
m_mockEventIpcManager.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.DELETE_SERVICE_EVENT_UEI, "Test").setNodeid(1).setInterface(InetAddressUtils.addr("10.10.10.10")).setService("ICMP").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 testPutNode.
@Test
@JUnitTemporaryDatabase
public void testPutNode() throws Exception {
JAXBContext context = JAXBContext.newInstance(OnmsNodeList.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
// 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 = (OnmsNodeList) unmarshaller.unmarshal(new StringReader(xml));
assertEquals(1, list.size());
assertEquals("TestMachine0", list.get(0).getLabel());
// Testing PUT
url += "/1";
sendPut(url, "sysContact=OpenNMS&assetRecord.manufacturer=Apple&assetRecord.operatingSystem=MacOSX Leopard", 204);
// Testing GET Single Object to make sure that the parameters changed
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 testAnotherNodeJson.
@Test
@JUnitTemporaryDatabase
public void testAnotherNodeJson() 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 restObject = new JSONObject(json);
JSONObject expectedObject = new JSONObject(IOUtils.toString(new FileInputStream("src/test/resources/v1/nodes.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class IfServicesRestServiceIT method testGetServices.
@Test
@JUnitTemporaryDatabase
public void testGetServices() throws Exception {
String url = "/ifservices";
OnmsMonitoredServiceDetailList list = getXmlObject(JaxbUtils.getContextFor(OnmsMonitoredServiceDetailList.class), url, 200, OnmsMonitoredServiceDetailList.class);
for (OnmsMonitoredServiceDetail detail : list.getObjects()) {
assertFalse("F".equals(detail.getStatusCode()));
}
// Mark all services as forced unmanaged
sendPut(url, "status=F", 204);
// Verify that all statuses were updated
list = getXmlObject(JaxbUtils.getContextFor(OnmsMonitoredServiceDetailList.class), url, 200, OnmsMonitoredServiceDetailList.class);
for (OnmsMonitoredServiceDetail detail : list.getObjects()) {
assertEquals("F", detail.getStatusCode());
}
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class IfServicesRestServiceIT method testGetById.
@Test
@JUnitTemporaryDatabase
public void testGetById() throws Exception {
OnmsMonitoredServiceDetail service = getXmlObject(JaxbUtils.getContextFor(OnmsMonitoredServiceDetail.class), "/ifservices/2", 200, OnmsMonitoredServiceDetail.class);
Assert.assertNotNull(service);
Assert.assertEquals("2", service.getId());
// verify that 404 is implemented correctly
sendRequest(GET, "/ifservices/-2", 404);
}
Aggregations