Search in sources :

Example 81 with JUnitTemporaryDatabase

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

Example 82 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 83 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 84 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 85 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)

Aggregations

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