List of usage examples for org.springframework.mock.web MockHttpServletRequest addHeader
public void addHeader(String name, Object value)
From source file:org.opennms.web.rest.v1.NodeRestServiceIT.java
@Test @JUnitTemporaryDatabase//from w w w. j av a2 s.co m 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); }
From source file:org.opennms.web.rest.v1.NodeRestServiceIT.java
@Test @JUnitTemporaryDatabase//from w w w . ja va 2 s. co m public void testIpInterfaceJson() throws Exception { createIpInterface(); String url = "/nodes/1/ipinterfaces"; 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); JSONArray ja = jo.getJSONArray("ipInterface"); assertEquals(1, ja.length()); jo = ja.getJSONObject(0); assertTrue(jo.isNull("ifIndex")); assertEquals("10.10.10.10", jo.getString("ipAddress")); assertEquals(1, jo.getInt("nodeId")); }
From source file:org.opennms.web.rest.v1.NodeRestServiceIT.java
@Test @JUnitTemporaryDatabase//from www .j av a 2 s. c o m 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")); }
From source file:org.opennms.web.rest.v1.NotificationRestServiceIT.java
@Test @JUnitTemporaryDatabase//from w ww . ja va2 s . co m public void testNotificationsJson() throws Exception { String url = "/notifications"; // GET all users MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); String json = sendRequest(jsonRequest, 200); JSONObject restObject = new JSONObject(json); JSONObject expectedObject = new JSONObject( IOUtils.toString(new FileInputStream("src/test/resources/v1/notifications.json"))); JSONAssert.assertEquals(expectedObject, restObject, true); }
From source file:org.opennms.web.rest.v1.OutageRestServiceIT.java
@Test @JUnitTemporaryDatabase//from ww w . j av a2 s . c o m public void testGetAllOutages() throws Exception { String xml = sendRequest(GET, "/outages", 200); Assert.assertNotNull(xml); MockHttpServletRequest jsonRequest = createRequest(m_context, GET, "/outages"); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); String json = sendRequest(jsonRequest, 200); Assert.assertNotNull(json); }
From source file:org.opennms.web.rest.v1.OutageRestServiceIT.java
@Test @JUnitTemporaryDatabase//from w w w. j a v a2 s .com public void testOutageSearches() throws Exception { MockHttpServletRequest jsonRequest = createRequest(m_context, GET, "/outages"); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); jsonRequest.setQueryString("ipInterface.ipAddress=192.168.1.2"); String json = sendRequest(jsonRequest, 200); LOG.debug(json); JSONObject restObject = new JSONObject(json); assertEquals(1, restObject.getJSONArray("outage").length()); jsonRequest = createRequest(m_context, GET, "/outages"); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); jsonRequest.setQueryString("comparator=ge&serviceLostEvent.eventSeverity=5"); // OnmsSeverity.MINOR json = sendRequest(jsonRequest, 200); LOG.debug(json); restObject = new JSONObject(json); assertEquals(1, restObject.getJSONArray("outage").length()); jsonRequest = createRequest(m_context, GET, "/outages"); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); jsonRequest.setQueryString("comparator=lt&serviceLostEvent.eventSeverity=2"); // OnmsSeverity.CLEARED json = sendRequest(jsonRequest, 200); LOG.debug(json); restObject = new JSONObject(json); assertEquals(2, restObject.getJSONArray("outage").length()); jsonRequest = createRequest(m_context, GET, "/outages"); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); jsonRequest.setQueryString("comparator=like&serviceLostEvent.eventLogMsg=Test%25"); json = sendRequest(jsonRequest, 200); LOG.debug(json); restObject = new JSONObject(json); assertEquals(3, restObject.getJSONArray("outage").length()); // Check serviceRegainedEvent filters jsonRequest = createRequest(m_context, GET, "/outages"); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); jsonRequest.setQueryString("comparator=lt&serviceRegainedEvent.eventSeverity=2"); // OnmsSeverity.CLEARED json = sendRequest(jsonRequest, 200); LOG.debug(json); // There is one test outage that has been resolved restObject = new JSONObject(json); assertEquals(1, restObject.getJSONArray("outage").length()); jsonRequest = createRequest(m_context, GET, "/outages"); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); jsonRequest.setQueryString("comparator=like&serviceRegainedEvent.eventLogMsg=Test%25"); json = sendRequest(jsonRequest, 200); LOG.debug(json); // There is one test outage that has been resolved restObject = new JSONObject(json); assertEquals(1, restObject.getJSONArray("outage").length()); }
From source file:org.opennms.web.rest.v1.OutageRestServiceIT.java
@Test @JUnitTemporaryDatabase/*from w ww . j a v a 2 s .c om*/ public void testOutagesJson() throws Exception { String url = "/outages"; // GET all users MockHttpServletRequest jsonRequest = createRequest(m_context, GET, url); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); jsonRequest.setQueryString("limit=1&orderBy=id"); String json = sendRequest(jsonRequest, 200); JSONObject restObject = new JSONObject(json); JSONObject expectedObject = new JSONObject( IOUtils.toString(new FileInputStream("src/test/resources/v1/outages.json"))); JSONAssert.assertEquals(expectedObject, restObject, true); }
From source file:org.opennms.web.rest.v1.RemotePollerAvailabilityRestServiceIT.java
@Test public void testGetLocationsJson() throws Exception { String url = "/remotelocations"; // GET all users MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); String json = sendRequest(jsonRequest, 200); JSONObject restObject = new JSONObject(json); JSONObject expectedObject = new JSONObject( IOUtils.toString(new FileInputStream("src/test/resources/v1/remotelocations.json"))); JSONAssert.assertEquals(expectedObject, restObject, true); }
From source file:org.opennms.web.rest.v1.ResourceRestServiceIT.java
@Test @JUnitTemporaryDatabase/*from w ww. java 2s . com*/ public void testResourcesJson() throws Exception { String url = "/resources"; // GET all users MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); String json = sendRequest(jsonRequest, 200); JSONObject restObject = new JSONObject(json); final String jsonString = IOUtils.toString(new FileInputStream("src/test/resources/v1/resources.json")); JSONObject expectedObject = new JSONObject(jsonString.replace(".jrb", m_extension)); JSONAssert.assertEquals(expectedObject, restObject, true); }
From source file:org.opennms.web.rest.v1.ScheduledOutagesRestServiceIT.java
@Test public void testGetOutageJson() throws Exception { String url = "/sched-outages"; // GET all items MockHttpServletRequest jsonRequest = createRequest(m_servletContext, GET, url); jsonRequest.addHeader("Accept", MediaType.APPLICATION_JSON); String json = sendRequest(jsonRequest, 200); JSONObject restObject = new JSONObject(json); JSONObject expectedObject = new JSONObject( IOUtils.toString(new FileInputStream("src/test/resources/v1/sched-outages.json"))); JSONAssert.assertEquals(expectedObject, restObject, true); }