Search in sources :

Example 96 with JUnitTemporaryDatabase

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();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNodeList(org.opennms.netmgt.model.OnmsNodeList) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 97 with JUnitTemporaryDatabase

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);
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 98 with JUnitTemporaryDatabase

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());
    }
}
Also used : OnmsMonitoredServiceDetailList(org.opennms.netmgt.model.OnmsMonitoredServiceDetailList) OnmsMonitoredServiceDetail(org.opennms.netmgt.model.OnmsMonitoredServiceDetail) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 99 with JUnitTemporaryDatabase

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);
}
Also used : OnmsMonitoredServiceDetail(org.opennms.netmgt.model.OnmsMonitoredServiceDetail) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 100 with JUnitTemporaryDatabase

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);
}
Also used : JSONObject(org.json.JSONObject) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FileInputStream(java.io.FileInputStream) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)106 Test (org.junit.Test)102 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 JSONObject (org.json.JSONObject)16 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)8 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)8 AlarmIdFilter (org.opennms.web.alarm.filter.AlarmIdFilter)7 HashMap (java.util.HashMap)6 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)6 OutageCriteria (org.opennms.web.outage.filter.OutageCriteria)6 StringReader (java.io.StringReader)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 JSONArray (org.json.JSONArray)4