Example usage for org.springframework.mock.web MockHttpServletRequest setQueryString

List of usage examples for org.springframework.mock.web MockHttpServletRequest setQueryString

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletRequest setQueryString.

Prototype

public void setQueryString(@Nullable String queryString) 

Source Link

Usage

From source file:org.opennms.web.rest.AbstractSpringJerseyRestTestCase.java

protected String sendRequest(final String requestType, final String url, final Map<?, ?> parameters,
        final int expectedStatus, final String expectedUrlSuffix) throws Exception {
    final MockHttpServletRequest request = createRequest(requestType, url);
    request.setParameters(parameters);//from   ww w. ja  v a  2s .  c  om
    request.setQueryString(getQueryString(parameters));
    return sendRequest(request, expectedStatus, expectedUrlSuffix);
}

From source file:org.opennms.web.rest.IfServicesRestServiceTest.java

@Test
@JUnitTemporaryDatabase/*  www.  j  av  a2 s.c om*/
public void testGetServicesJson() throws Exception {
    String url = "/ifservices";

    // GET all users
    MockHttpServletRequest jsonRequest = createRequest(getServletContext(), 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);
}

From source file:org.opennms.web.rest.v1.IfServicesRestServiceIT.java

@Test
@JUnitTemporaryDatabase// w  ww. ja va2s. c  o m
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);
}

From source file:org.opennms.web.rest.v1.OutageRestServiceIT.java

@Test
@JUnitTemporaryDatabase/*w  w  w.j  a  va2 s  .  co  m*/
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// w w  w .java 2  s  . com
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);
}