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);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class IfServicesRestServiceIT method testGetServicesJson.
@Test
@JUnitTemporaryDatabase
public void testGetServicesJson() throws Exception {
String url = "/ifservices";
// GET all users
MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url);
jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON);
jsonRequest.setQueryString("orderBy=id");
String json = sendRequest(jsonRequest, 200);
JSONObject restObject = new JSONObject(json);
JSONObject expectedObject = new JSONObject(IOUtils.toString(new FileInputStream("src/test/resources/v1/ifservices.json")));
JSONAssert.assertEquals(expectedObject, restObject, true);
}
Aggregations