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

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

Introduction

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

Prototype

public void removeParameter(String name) 

Source Link

Document

Remove already registered values for the specified HTTP parameter, if any.

Usage

From source file:org.openmrs.module.logmanager.web.util.WebUtilsTest.java

@Test
public void getSessionedIntParameter() {
    MockHttpServletRequest request = new MockHttpServletRequest();

    // Should sue default when parameter doesn't exist
    Assert.assertEquals(123, WebUtils.getSessionedIntParameter(request, "test1", 123, "test."));

    // Should use request value when it exists
    request.addParameter("test1", "" + 456);
    Assert.assertEquals(456, WebUtils.getSessionedIntParameter(request, "test1", 123, "test."));

    // Should remember in session when request doesn't exist
    request.removeParameter("test1");
    Assert.assertEquals(456, WebUtils.getSessionedIntParameter(request, "test1", 123, "test."));
}

From source file:alpha.portal.webapp.controller.CardAssignFormControllerTest.java

/**
 * Test on submit.//from w w w.  jav  a2s  .c o m
 * 
 * @throws Exception
 *             the exception
 */
@Test
public void testOnSubmit() throws Exception {
    final String cardId = "440e4816-e01b-74d4-a716-449955440092";
    final String caseId = "550e4713-e22b-11d4-a716-446655440000";

    final MockHttpServletRequest request = this.newPost("/cardassignform");
    request.setRemoteUser("admin");
    request.setParameter("card", cardId);
    request.setParameter("case", caseId);
    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setParameter("cancel", "");
    this.form.onSubmit(request, response);

    response = new MockHttpServletResponse();
    request.removeParameter("cancel");
    request.setParameter("user", "-1");
    this.form.onSubmit(request, response);

    boolean found = false;
    for (final ContributorRequest r : this.contrReqManager.getAll()) {
        if (r.getAcceptingUser().getId().equals(-1L)
                && r.getAlphaCard().getAlphaCardIdentifier().getCardId().equals(cardId)
                && r.getRequestingUser().getId().equals(-2L)) {
            found = true;
            break;
        }
    }
    Assert.assertTrue(found);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.PatientController1_8Test.java

@Test
public void shouldRespectStartIndexAndLimit() throws Exception {
    MockHttpServletRequest req = newGetRequest(getURI());
    req.setParameter("q", "Test");
    SimpleObject results = deserialize(handle(req));
    int fullCount = Util.getResultsSize(results);
    assertTrue("This test assumes > 2 matching patients", fullCount > 2);

    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_LIMIT, "2");
    results = deserialize(handle(req));//from  w w w.  j ava2 s .c  o m
    int firstCount = Util.getResultsSize(results);
    assertEquals(2, firstCount);

    req.removeParameter(RestConstants.REQUEST_PROPERTY_FOR_LIMIT);
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_START_INDEX, "2");
    results = deserialize(handle(req));
    int restCount = Util.getResultsSize(results);
    assertEquals(fullCount, firstCount + restCount);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.PatientController1_9Test.java

@Test
public void shouldRespectStartIndexAndLimit() throws Exception {
    MockHttpServletRequest req = newGetRequest(getURI());
    req.setParameter("q", "Test");
    SimpleObject results = deserialize(handle(req));
    int fullCount = Util.getResultsSize(results);
    assertTrue("This test assumes > 2 matching patients", fullCount > 2);

    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_LIMIT, "2");
    results = deserialize(handle(req));/*w w w  .jav a 2s  .  c o m*/
    int firstCount = Util.getResultsSize(results);
    assertEquals(1, firstCount);

    req.removeParameter(RestConstants.REQUEST_PROPERTY_FOR_LIMIT);
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_START_INDEX, "2");
    results = deserialize(handle(req));
    int restCount = Util.getResultsSize(results);
    assertEquals(fullCount, firstCount + restCount);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.PersonController1_8Test.java

@Test
public void shouldRespectStartIndexAndLimit() throws Exception {
    MockHttpServletRequest req = newGetRequest(getURI());
    req.setParameter("q", "Test");
    SimpleObject results = deserialize(handle(req));
    int fullCount = Util.getResultsSize(results);
    assertTrue("This test assumes > 2 matching persons", fullCount > 2);

    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_LIMIT, "2");
    results = deserialize(handle(req));/*from   w w w .  j a va  2s.  c o  m*/
    int firstCount = Util.getResultsSize(results);
    assertEquals(2, firstCount);

    req.removeParameter(RestConstants.REQUEST_PROPERTY_FOR_LIMIT);
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_START_INDEX, "2");
    results = deserialize(handle(req));
    int restCount = Util.getResultsSize(results);
    assertEquals(fullCount, firstCount + restCount);
}

From source file:com.gisgraphy.street.StreetSearchQueryHttpBuilderTest.java

@Test
public void streetSearchQueryFromAnHttpServletRequest() {
    MockHttpServletRequest request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    StreetSearchQuery query = buildQuery(request);
    int firstPaginationIndex = 3;
    assertEquals(firstPaginationIndex, query.getFirstPaginationIndex());
    assertEquals(StreetSearchQuery.DEFAULT_MAX_RESULTS + firstPaginationIndex - 1,
            query.getLastPaginationIndex());
    assertEquals("the pagination should be limit to " + StreetSearchQuery.DEFAULT_MAX_RESULTS,
            StreetSearchQuery.DEFAULT_MAX_RESULTS, query.getMaxNumberOfResults());
    assertEquals(OutputFormat.XML, query.getOutputFormat());
    assertEquals(null, query.getOutputLanguage());
    assertEquals(OutputStyle.getDefault(), query.getOutputStyle());
    assertEquals(City.class, query.getPlaceType());
    assertEquals(1.0, query.getLatitude(), 0.1);
    assertEquals(2.0, query.getLongitude(), 0.1);
    assertEquals(10000D, query.getRadius(), 0.000001);

    // test first pagination index
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(GisgraphyServlet.FROM_PARAMETER);
    query = buildQuery(request);//w  w w  .j ava 2 s  .  c om
    assertEquals("When no " + GisgraphyServlet.FROM_PARAMETER + " is specified, the parameter should be "
            + Pagination.DEFAULT_FROM, Pagination.DEFAULT_FROM, query.getFirstPaginationIndex());
    // with a wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(GisgraphyServlet.FROM_PARAMETER, "-1");
    query = buildQuery(request);
    assertEquals("When a wrong " + GisgraphyServlet.FROM_PARAMETER + " is specified, the parameter should be "
            + Pagination.DEFAULT_FROM, Pagination.DEFAULT_FROM, query.getFirstPaginationIndex());
    // with a non mumeric value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(GisgraphyServlet.FROM_PARAMETER, "a");
    query = buildQuery(request);
    assertEquals("When a wrong " + GisgraphyServlet.FROM_PARAMETER + " is specified, the parameter should be "
            + Pagination.DEFAULT_FROM, Pagination.DEFAULT_FROM, query.getFirstPaginationIndex());

    // test last pagination index
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(GisgraphyServlet.TO_PARAMETER);
    query = buildQuery(request);
    // not specify
    int expectedLastPagination = (StreetSearchQuery.DEFAULT_NB_RESULTS + query.getFirstPaginationIndex() - 1);
    assertEquals(GisgraphyServlet.TO_PARAMETER + " is wrong when no " + GisgraphyServlet.TO_PARAMETER
            + " is specified ", expectedLastPagination, query.getLastPaginationIndex());

    assertEquals(
            "When no " + GisgraphyServlet.TO_PARAMETER + " is specified, the maxnumberOfResults should be "
                    + StreetSearchQuery.DEFAULT_NB_RESULTS,
            StreetSearchQuery.DEFAULT_NB_RESULTS, query.getMaxNumberOfResults());
    // too high
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(GisgraphyServlet.TO_PARAMETER);
    request.setParameter(GisgraphyServlet.TO_PARAMETER, StreetSearchQuery.DEFAULT_MAX_RESULTS + 100 + "");
    query = buildQuery(request);
    expectedLastPagination = (StreetSearchQuery.DEFAULT_MAX_RESULTS + query.getFirstPaginationIndex() - 1);
    assertEquals("when " + GisgraphyServlet.TO_PARAMETER + " is too high " + GisgraphyServlet.TO_PARAMETER
            + " should be limited", expectedLastPagination, query.getLastPaginationIndex());

    assertEquals(
            "when " + GisgraphyServlet.TO_PARAMETER + " is too high " + GisgraphyServlet.TO_PARAMETER
                    + " should be limited",
            StreetSearchQuery.DEFAULT_MAX_RESULTS, query.getMaxNumberOfResults());
    // with a wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(GisgraphyServlet.TO_PARAMETER, "2");// to<from
    query = buildQuery(request);
    expectedLastPagination = (StreetSearchQuery.DEFAULT_NB_RESULTS + query.getFirstPaginationIndex() - 1);
    assertEquals(GisgraphyServlet.TO_PARAMETER + " is wrong when wrong " + GisgraphyServlet.TO_PARAMETER
            + " is specified ", expectedLastPagination, query.getLastPaginationIndex());
    assertEquals("When a wrong " + GisgraphyServlet.TO_PARAMETER
            + " is specified, the maxnumberOfResults should  be  " + StreetSearchQuery.DEFAULT_NB_RESULTS,
            StreetSearchQuery.DEFAULT_NB_RESULTS, query.getMaxNumberOfResults());

    assertEquals("a wrong to does not change the from value", 3, query.getFirstPaginationIndex());
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    // non numeric
    request.setParameter(GisgraphyServlet.TO_PARAMETER, "a");// to<from
    query = buildQuery(request);
    assertEquals("a wrong to does not change the from value", 3, query.getFirstPaginationIndex());
    expectedLastPagination = (StreetSearchQuery.DEFAULT_NB_RESULTS + query.getFirstPaginationIndex() - 1);
    assertEquals(GisgraphyServlet.TO_PARAMETER + " is wrong when non numeric " + GisgraphyServlet.TO_PARAMETER
            + " is specified ", expectedLastPagination, query.getLastPaginationIndex());
    assertEquals("When a wrong " + GisgraphyServlet.TO_PARAMETER
            + " is specified, the maxnumberOfResults should not be > " + StreetSearchQuery.DEFAULT_NB_RESULTS,
            StreetSearchQuery.DEFAULT_NB_RESULTS, query.getMaxNumberOfResults());

    // test indentation
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(GisgraphyServlet.INDENT_PARAMETER);
    query = buildQuery(request);
    assertEquals(
            "When no " + GisgraphyServlet.INDENT_PARAMETER
                    + " is specified, the  parameter should be set to default",
            Output.DEFAULT_INDENTATION, query.isOutputIndented());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(GisgraphyServlet.INDENT_PARAMETER, "UNK");
    query = buildQuery(request);
    assertEquals(
            "When wrong " + GisgraphyServlet.INDENT_PARAMETER
                    + " is specified, the  parameter should be set to false",
            Output.DEFAULT_INDENTATION, query.isOutputIndented());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(GisgraphyServlet.INDENT_PARAMETER, "true");
    query = buildQuery(request);
    assertTrue(GisgraphyServlet.INDENT_PARAMETER + " should be case insensitive  ", query.isOutputIndented());
    // test 'on' value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(GisgraphyServlet.INDENT_PARAMETER, "oN");
    query = buildQuery(request);
    assertTrue(
            GisgraphyServlet.INDENT_PARAMETER
                    + " should be true for 'on' value (case insensitive and on value)  ",
            query.isOutputIndented());

    // test outputFormat
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(GisgraphyServlet.FORMAT_PARAMETER);
    query = buildQuery(request);
    assertEquals("When no " + GisgraphyServlet.FORMAT_PARAMETER
            + " is specified, the  parameter should be set to  " + OutputFormat.getDefault(),
            OutputFormat.getDefault(), query.getOutputFormat());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(GisgraphyServlet.FORMAT_PARAMETER, "UNK");
    query = buildQuery(request);
    assertEquals(
            "When wrong " + GisgraphyServlet.FORMAT_PARAMETER
                    + " is specified, the  parameter should be set to  " + OutputFormat.getDefault(),
            OutputFormat.getDefault(), query.getOutputFormat());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(GisgraphyServlet.FORMAT_PARAMETER, "json");
    query = buildQuery(request);
    assertEquals(GisgraphyServlet.FORMAT_PARAMETER + " should be case insensitive  ", OutputFormat.JSON,
            query.getOutputFormat());
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    request.setParameter(GisgraphyServlet.FORMAT_PARAMETER, "unsupported");
    query = buildQuery(request);
    assertEquals(GisgraphyServlet.FORMAT_PARAMETER + " should set default if not supported  ",
            OutputFormat.getDefault(), query.getOutputFormat());

    // test streeSearchMode
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(StreetServlet.STREET_SEARCH_MODE_PARAMETER);
    query = buildQuery(request);
    assertEquals(
            "When no " + StreetServlet.STREET_SEARCH_MODE_PARAMETER
                    + " is specified, the  parameter should be set to defaultValue",
            StreetSearchMode.getDefault(), query.getStreetSearchMode());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetServlet.STREET_SEARCH_MODE_PARAMETER, "unk");
    query = buildQuery(request);
    assertEquals(
            "When wrong " + StreetServlet.STREET_SEARCH_MODE_PARAMETER
                    + " is specified, the  parameter should be set to the default value ",
            StreetSearchMode.getDefault(), query.getStreetSearchMode());
    //test with good value 
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetServlet.STREET_SEARCH_MODE_PARAMETER, StreetSearchMode.CONTAINS.toString());
    query = buildQuery(request);
    assertEquals(
            "When good " + StreetServlet.STREET_SEARCH_MODE_PARAMETER
                    + " is specified, the  parameter should be set to the Equivalent streetSearchMode ",
            StreetSearchMode.CONTAINS, query.getStreetSearchMode());
    //test case sensitivity
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetServlet.STREET_SEARCH_MODE_PARAMETER,
            StreetSearchMode.CONTAINS.toString().toLowerCase());
    query = buildQuery(request);
    assertEquals(StreetServlet.STREET_SEARCH_MODE_PARAMETER + " should be case sensitive ",
            StreetSearchMode.CONTAINS, query.getStreetSearchMode());
    // test streettype
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(StreetSearchQuery.STREETTYPE_PARAMETER);
    query = buildQuery(request);
    assertNull("When no " + StreetSearchQuery.STREETTYPE_PARAMETER
            + " is specified, the  parameter should be set to null", query.getStreetType());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.STREETTYPE_PARAMETER, "unk");
    query = buildQuery(request);
    assertNull("When wrong " + StreetSearchQuery.STREETTYPE_PARAMETER
            + " is specified, the  parameter should be set to null ", query.getStreetType());
    //test with good value 
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.STREETTYPE_PARAMETER, StreetType.BRIDLEWAY.toString());
    query = buildQuery(request);
    assertEquals(
            "When good " + StreetSearchQuery.STREETTYPE_PARAMETER
                    + " is specified, the  parameter should be set to the Equivalent streettype ",
            StreetType.BRIDLEWAY, query.getStreetType());
    //test case sensitivity
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.STREETTYPE_PARAMETER, StreetType.BRIDLEWAY.toString().toLowerCase());
    query = buildQuery(request);
    assertEquals(StreetSearchQuery.STREETTYPE_PARAMETER + " should be case sensitive ", StreetType.BRIDLEWAY,
            query.getStreetType());

    // test oneWay
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(StreetSearchQuery.ONEWAY_PARAMETER);
    query = buildQuery(request);
    assertNull("When no " + StreetSearchQuery.ONEWAY_PARAMETER
            + " is specified, the  parameter should be set to null", query.getOneWay());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.ONEWAY_PARAMETER, "UNK");
    query = buildQuery(request);
    assertNull("When wrong " + StreetSearchQuery.ONEWAY_PARAMETER
            + " is specified, the  parameter should be set to false", query.getOneWay());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.ONEWAY_PARAMETER, "True");
    query = buildQuery(request);
    assertTrue(StreetSearchQuery.ONEWAY_PARAMETER + " should be case insensitive for true ", query.getOneWay());

    // test With false
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.ONEWAY_PARAMETER, "FaLse");
    query = buildQuery(request);
    assertFalse(StreetSearchQuery.ONEWAY_PARAMETER + " should be case insensitive for false  ",
            query.getOneWay());
    // test 'on' value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.ONEWAY_PARAMETER, "oN");
    query = buildQuery(request);
    assertTrue(StreetSearchQuery.ONEWAY_PARAMETER
            + " should be true for 'on' value (case insensitive and on value)  ", query.getOneWay());

    //name
    //test With good value
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.NAME_PARAMETER, "prefix");
    query = buildQuery(request);
    assertEquals(StreetSearchQuery.NAME_PARAMETER + " should be set when specified",
            request.getParameter(StreetSearchQuery.NAME_PARAMETER), query.getName());

    // empty string
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.NAME_PARAMETER, " ");
    query = buildQuery(request);
    assertNull(StreetSearchQuery.NAME_PARAMETER + " should be null when an empty String is specified",
            query.getName());

    // too long string
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    request.setParameter(StreetSearchQuery.NAME_PARAMETER,
            RandomStringUtils.random(StreetSearchQuery.NAME_MAX_LENGTH) + 1);
    try {
        query = buildQuery(request);
        fail("Name Prefix must have a maximmum length of " + StreetSearchQuery.NAME_MAX_LENGTH);
    } catch (StreetSearchException e) {
    }

    // test Point
    // with missing lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(StreetSearchQuery.LAT_PARAMETER);
    try {
        query = buildQuery(request);
    } catch (RuntimeException e) {
        fail("lattitude should be optionnal");
    }
    // with empty lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LAT_PARAMETER, "");
    try {
        query = buildQuery(request);
        fail("Even if latitude is optional, it should be valid when specified");
    } catch (RuntimeException e) {
    }
    // With wrong lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LAT_PARAMETER, "a");
    try {
        query = buildQuery(request);
        fail("A wrong lat should throw");
    } catch (RuntimeException e) {
    }
    // With too small lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LAT_PARAMETER, "-92");
    try {
        query = buildQuery(request);
        fail("latitude should not accept latitude < -90");
    } catch (RuntimeException e) {
    }

    // With too high lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LAT_PARAMETER, "92");
    try {
        query = buildQuery(request);
        fail("latitude should not accept latitude > 90");
    } catch (RuntimeException e) {
    }

    // with missing long
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(StreetSearchQuery.LONG_PARAMETER);
    try {
        query = buildQuery(request);
    } catch (RuntimeException e) {
        fail("longitude should be optional");
    }
    // with empty long
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LONG_PARAMETER, "");
    try {
        query = buildQuery(request);
        fail("longitude should be valid even if optional");
    } catch (RuntimeException e) {
    }
    // With wrong Long
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LONG_PARAMETER, "a");
    try {
        query = buildQuery(request);
        fail("Even if latitude is optional, it should be valid when specified");
    } catch (RuntimeException e) {
    }

    // with too small long
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LONG_PARAMETER, "-182");
    try {
        query = buildQuery(request);
        fail("longitude should not accept longitude < -180");
    } catch (RuntimeException e) {
    }

    // with too high long
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LONG_PARAMETER, "182");
    try {
        query = buildQuery(request);
        fail("longitude should not accept longitude > 180");
    } catch (RuntimeException e) {
    }

    // with long with comma
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LONG_PARAMETER, "10,3");
    try {
        query = buildQuery(request);
        Assert.assertEquals("request should accept longitude with comma", 10.3D,
                query.getLongitude().doubleValue(), 0.1);

    } catch (RuntimeException e) {
    }

    // with long with point
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LONG_PARAMETER, "10.3");
    try {
        query = buildQuery(request);
        Assert.assertEquals("request should accept longitude with comma", 10.3D,
                query.getLongitude().doubleValue(), 0.1);

    } catch (RuntimeException e) {
    }

    // with lat with comma
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LAT_PARAMETER, "10,3");
    try {
        query = buildQuery(request);
        Assert.assertEquals("request should accept latitude with comma", 10.3D,
                query.getLatitude().doubleValue(), 0.1);

    } catch (RuntimeException e) {
    }

    // with lat with point
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.LAT_PARAMETER, "10.3");
    try {
        query = buildQuery(request);
        Assert.assertEquals("request should accept latitude with point", 10.3D,
                query.getLatitude().doubleValue(), 0.1);

    } catch (RuntimeException e) {
    }

    // test radius
    // with missing radius
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.removeParameter(StreetSearchQuery.RADIUS_PARAMETER);
    query = buildQuery(request);
    assertEquals("When no " + StreetSearchQuery.RADIUS_PARAMETER
            + " is specified, the  parameter should be set to  " + GeolocQuery.DEFAULT_RADIUS,
            GeolocQuery.DEFAULT_RADIUS, query.getRadius(), 0.1);
    // With wrong radius
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.RADIUS_PARAMETER, "a");
    query = buildQuery(request);
    assertEquals(
            "When wrong " + StreetSearchQuery.RADIUS_PARAMETER
                    + " is specified, the  parameter should be set to  " + GeolocQuery.DEFAULT_RADIUS,
            GeolocQuery.DEFAULT_RADIUS, query.getRadius(), 0.1);
    // radius with comma
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.RADIUS_PARAMETER, "1,4");
    query = buildQuery(request);
    assertEquals("Radius should accept comma as decimal separator", 1.4D, query.getRadius(), 0.1);

    // radius with point
    request = GisgraphyTestHelper.createMockHttpServletRequestForStreetGeoloc();
    request.setParameter(StreetSearchQuery.RADIUS_PARAMETER, "1.4");
    query = buildQuery(request);
    assertEquals("Radius should accept point as decimal separator", 1.4D, query.getRadius(), 0.1);

    // distanceField default value
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    query = buildQuery(request);
    assertTrue("By default distanceField should be true", query.hasDistanceField());

    // distanceField case insensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    request.setParameter(GeolocQuery.DISTANCE_PARAMETER, "falSE");
    query = buildQuery(request);
    assertFalse("distanceField should be set when specified", query.hasDistanceField());

    // distanceField with off value
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    request.setParameter(GeolocQuery.DISTANCE_PARAMETER, "oFF");
    query = buildQuery(request);
    assertFalse("distanceField should take off value into account", query.hasDistanceField());

    // distanceField with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    request.setParameter(GeolocQuery.DISTANCE_PARAMETER, "wrong value");
    query = buildQuery(request);
    assertTrue("distanceField should be kept to his default value if specified with wrong value",
            query.hasDistanceField());

    //callback not set
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    query = buildQuery(request);
    assertNull("callback should be null when not set", query.getCallback());

    //callback set with non alpha value
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    request.setParameter(GeolocQuery.CALLBACK_PARAMETER, "doit(");
    query = buildQuery(request);
    assertNull("callback should not be set when not alphanumeric", query.getCallback());

    //callback set with alpha value
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    request.setParameter(GeolocQuery.CALLBACK_PARAMETER, "doit");
    query = buildQuery(request);
    assertEquals("callback should not be set when alphanumeric", "doit", query.getCallback());

    //apiKey
    request = GisgraphyTestHelper.createMockHttpServletRequestForGeoloc();
    request.setParameter(GisgraphyServlet.APIKEY_PARAMETER, "apiKey");
    query = buildQuery(request);
    Assert.assertEquals("apiKey", query.getApikey());

}

From source file:org.openmrs.module.htmlformentry.ObsTagTest.java

@Test
public void dynamicAutocomplete_shouldVoidAllExistingObsIfEmpty() throws Exception {
    new RegressionTestHelper() {

        @Override/*  w w w  .ja  va 2s  .  c o  m*/
        public String getFormName() {
            return "singleObsFormWithMultiAutocomplete";
        }

        public Patient getPatient() {
            return patient;
        }

        @Override
        public String[] widgetLabels() {
            return new String[] { "Date:", "Location:", "Provider:", "Coded:" };
        }

        @Override
        public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
            request.addParameter(widgets.get("Date:"), dateAsString(new Date()));
            request.addParameter(widgets.get("Location:"), "2");
            request.addParameter(widgets.get("Provider:"), "502");
            request.addParameter(widgets.get("Coded:"), "2"); // in the dynamic autocomplete, the widget value is just the count of the number of entries
            request.addParameter("w8span_0_hid", "1001");
            request.addParameter("w8span_1_hid", "1002");
        }

        @Override
        public boolean doEditEncounter() {
            return true;
        }

        @Override
        public String[] widgetLabelsForEdit() {
            return new String[] { "Coded:" };
        }

        @Override
        public void setupEditRequest(MockHttpServletRequest request, Map<String, String> widgets) {
            request.setParameter(widgets.get("Coded:"), "0"); // in the dynamic autocomplete, the widget value is just the count of the number of entries
            request.removeParameter("w8span_0_hid");
            request.removeParameter("w8span_1_hid");
        }

        @Override
        public void testEditedResults(SubmissionResults results) {

            results.assertNoErrors();
            Encounter encounter = results.getEncounterCreated();

            assertThat(encounter.getAllObs(false).size(), is(0)); // no none-voided obs
            assertThat(encounter.getAllObs(true).size(), is(2)); // the existing obs should have been voided
        }

    }.run();
}

From source file:org.openmrs.module.htmlformentry.ObsTagTest.java

@Test
public void dynamicAutocomplete_shouldEditExistingObsWhenSomeObsAreRemoved() throws Exception {
    new RegressionTestHelper() {

        @Override/*  w w w .jav a 2  s . c o  m*/
        public String getFormName() {
            return "singleObsFormWithMultiAutocomplete";
        }

        public Patient getPatient() {
            return patient;
        }

        @Override
        public String[] widgetLabels() {
            return new String[] { "Date:", "Location:", "Provider:", "Coded:" };
        }

        @Override
        public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
            request.addParameter(widgets.get("Date:"), dateAsString(new Date()));
            request.addParameter(widgets.get("Location:"), "2");
            request.addParameter(widgets.get("Provider:"), "502");
            request.addParameter(widgets.get("Coded:"), "2"); // in the dynamic autocomplete, the widget value is just the count of the number of entries
            request.addParameter("w8span_0_hid", "1001");
            request.addParameter("w8span_1_hid", "1002");
        }

        @Override
        public boolean doEditEncounter() {
            return true;
        }

        @Override
        public String[] widgetLabelsForEdit() {
            return new String[] { "Coded:" };
        }

        @Override
        public void setupEditRequest(MockHttpServletRequest request, Map<String, String> widgets) {
            request.setParameter(widgets.get("Coded:"), "1"); // in the dynamic autocomplete, the widget value is just the count of the number of entries
            request.setParameter("w8span_0_hid", "1003");
            request.removeParameter("w8span_1_hid");
        }

        @Override
        public void testEditedResults(SubmissionResults results) {

            results.assertNoErrors();
            Encounter encounter = results.getEncounterCreated();

            assertThat(encounter.getAllObs(false).size(), is(1)); // should be one non-voided obs of value 1003
            assertThat(encounter.getAllObs(true).size(), is(3)); // should be three obs included the voided obs for 1001 and 1002

            Set<Integer> valueCoded = new HashSet<Integer>();

            for (Obs obs : encounter.getAllObs(true)) {
                if (!obs.isVoided()) {
                    assertThat(obs.getValueCoded().getId(), is(1003));
                } else {
                    valueCoded.add(obs.getValueCoded().getId());
                }
            }

            assertTrue(valueCoded.contains(1002));
            assertTrue(valueCoded.contains(1001));
        }

    }.run();
}

From source file:com.openmeap.services.ServletManagementServletTest.java

@Test
public void testRefreshApplication() throws Exception {
    MockHttpServletRequest request = new Request();
    MockHttpServletResponse response = new MockHttpServletResponse();
    String randomUuid = UUID.randomUUID().toString();

    GlobalSettings settings = modelManager.getGlobalSettings();

    /////////////////
    // validate that finding the application, modifying it, and then finding it again 
    // will return an object with the same modifications.
    Application app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
    app.setName(randomUuid);//from  w  w w. ja v a 2s.  com
    Assert.assertTrue(modelManager.getModelService().findByPrimaryKey(Application.class, 1L).getName()
            .equals(randomUuid));

    modelManager.refresh(app, null);
    app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
    Assert.assertTrue(!modelManager.getModelService().findByPrimaryKey(Application.class, 1L).getName()
            .equals(randomUuid));

    ServiceManagementServlet servlet = new ServiceManagementServlet();
    servlet.setModelManager(modelManager);
    servlet.setModelServiceRefreshHandler(new ModelServiceRefreshHandler());
    servlet.getModelServiceRefreshHandler().setModelManager(modelManager);

    ////////////////////
    // validate the happy path of providing all the required information
    String authSalt = servlet.getAuthSalt();
    String authToken = AuthTokenProvider.newAuthToken(authSalt);
    request.setParameter(UrlParamConstants.REFRESH_TYPE, "Application");
    request.setParameter(UrlParamConstants.REFRESH_OBJ_PKID, "1");
    request.setParameter(UrlParamConstants.AUTH_TOKEN, authToken);
    request.setParameter(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
    servlet.service(request, response);
    String contentString = response.getContentAsString();
    JSONObjectBuilder job = new JSONObjectBuilder();
    Result result = (Result) job.fromJSON(new JSONObject(contentString), new Result());
    Assert.assertTrue(result.getStatus().equals(Result.Status.SUCCESS));
    Assert.assertTrue(!modelManager.getModelService().findByPrimaryKey(Application.class, 1L).getName()
            .equals(randomUuid));

    ////////////////////
    // validate that failing to provide auth token fails to refresh cache
    app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
    app.setName(randomUuid);
    response = new MockHttpServletResponse();
    request.removeParameter(UrlParamConstants.AUTH_TOKEN);
    request.setParameter(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
    request.setParameter(UrlParamConstants.REFRESH_TYPE, "Application");
    request.setParameter(UrlParamConstants.REFRESH_OBJ_PKID, "1");
    servlet.service(request, response);
    contentString = response.getContentAsString();
    result = (Result) job.fromJSON(new JSONObject(contentString), new Result());
    Assert.assertTrue(result.getStatus().equals(Result.Status.FAILURE));
    Assert.assertTrue(modelManager.getModelService().findByPrimaryKey(Application.class, 1L).getName()
            .equals(randomUuid));

}

From source file:com.gisgraphy.fulltext.FulltextQueryHttpBuilderTest.java

@Test
public void testFulltextQueryFromAnHttpServletRequest() {

    MockHttpServletRequest request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    FulltextQuery query = buildQuery(request);

    // test Point
    // with empty lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LAT_PARAMETER, "");
    try {//from   ww  w  .ja v  a2s .c o m
        query = buildQuery(request);
    } catch (RuntimeException e) {
        fail("When there is empty latitude, query should throw");
    }
    // With wrong lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LAT_PARAMETER, "a");
    try {
        query = buildQuery(request);
        fail("A null lat should throw");
    } catch (RuntimeException e) {
    }
    // With too small lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LAT_PARAMETER, "-92");
    try {
        query = buildQuery(request);
        fail("latitude should not accept latitude < -90");
    } catch (RuntimeException e) {
    }

    // With too high lat
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LAT_PARAMETER, "92");
    try {
        query = buildQuery(request);
        fail("latitude should not accept latitude > 90");
    } catch (RuntimeException e) {
    }

    // with empty long
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LONG_PARAMETER, "");
    try {
        query = buildQuery(request);
    } catch (RuntimeException e) {
        fail("When there is empty longitude, query should throw");
    }
    // With wrong Long
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LONG_PARAMETER, "a");
    try {
        query = buildQuery(request);
        fail("A null lat should throw");
    } catch (RuntimeException e) {
    }

    // with too small long
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LONG_PARAMETER, "-182");
    try {
        query = buildQuery(request);
        fail("longitude should not accept longitude < -180");
    } catch (RuntimeException e) {
    }

    // with too high long
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LONG_PARAMETER, "182");
    try {
        query = buildQuery(request);
        fail("longitude should not accept longitude > 180");
    } catch (RuntimeException e) {
    }

    // with long with comma
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LONG_PARAMETER, "10,3");
    try {
        query = buildQuery(request);
        Assert.assertEquals("request should accept longitude with comma", 10.3D,
                query.getLongitude().doubleValue(), 0.1);

    } catch (RuntimeException e) {
    }

    // with long with point
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LONG_PARAMETER, "10.3");
    try {
        query = buildQuery(request);
        Assert.assertEquals("request should accept longitude with comma", 10.3D,
                query.getLongitude().doubleValue(), 0.1);

    } catch (RuntimeException e) {
    }

    // with lat with comma
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LAT_PARAMETER, "10,3");
    try {
        query = buildQuery(request);
        Assert.assertEquals("request should accept latitude with comma", 10.3D,
                query.getLatitude().doubleValue(), 0.1);

    } catch (RuntimeException e) {
    }

    // with lat with point
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LAT_PARAMETER, "10.3");
    try {
        query = buildQuery(request);
        Assert.assertEquals("request should accept latitude with point", 10.3D,
                query.getLatitude().doubleValue(), 0.1);

    } catch (RuntimeException e) {
    }

    // test radius
    // with missing radius
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.RADIUS_PARAMETER);
    query = buildQuery(request);
    assertEquals("When no " + FulltextQuery.RADIUS_PARAMETER
            + " is specified, the  parameter should be set to  " + FulltextQuery.DEFAULT_RADIUS,
            FulltextQuery.DEFAULT_RADIUS, query.getRadius(), 0.1);
    // With wrong radius
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.RADIUS_PARAMETER, "a");
    query = buildQuery(request);
    assertEquals("When wrong " + FulltextQuery.RADIUS_PARAMETER
            + " is specified, the  parameter should be set to  " + FulltextQuery.DEFAULT_RADIUS,
            FulltextQuery.DEFAULT_RADIUS, query.getRadius(), 0.1);
    // radius with comma
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.RADIUS_PARAMETER, "1,4");
    query = buildQuery(request);
    assertEquals("Radius should accept comma as decimal separator", 1.4D, query.getRadius(), 0.1);

    // radius with point
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.RADIUS_PARAMETER, "1.4");
    query = buildQuery(request);
    assertEquals("Radius should accept point as decimal separator", 1.4D, query.getRadius(), 0.1);

    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    query = buildQuery(request);
    int firstPaginationIndex = 3;
    assertEquals(firstPaginationIndex, query.getFirstPaginationIndex());
    assertEquals(DEFAULT_MAX_RESULTS + firstPaginationIndex - 1, query.getLastPaginationIndex());
    assertEquals("the pagination should be limit to " + DEFAULT_MAX_RESULTS, DEFAULT_MAX_RESULTS,
            query.getMaxNumberOfResults());
    assertEquals("FR", query.getCountryCode());
    assertEquals(OutputFormat.XML, query.getOutputFormat());
    assertEquals("FR", query.getOutputLanguage());
    assertEquals(OutputStyle.FULL, query.getOutputStyle());
    assertEquals(City.class, query.getPlaceTypes()[0]);
    assertEquals("query", query.getQuery());

    //test trim
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextServlet.FROM_PARAMETER,
            " " + request.getParameter(FulltextQuery.QUERY_PARAMETER) + " ");
    query = buildQuery(request);
    Assert.assertTrue("query parameter shoud be trimed", !query.getQuery().endsWith(" "));
    Assert.assertTrue("query parameter shoud be trimed", !query.getQuery().startsWith(" "));

    // test first pagination index
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextServlet.FROM_PARAMETER);
    query = buildQuery(request);
    assertEquals("When no " + FulltextServlet.FROM_PARAMETER + " is specified, the parameter should be "
            + Pagination.DEFAULT_FROM, Pagination.DEFAULT_FROM, query.getFirstPaginationIndex());
    // with a wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextServlet.FROM_PARAMETER, "-1");
    query = buildQuery(request);
    assertEquals("When a wrong " + FulltextServlet.FROM_PARAMETER + " is specified, the parameter should be "
            + Pagination.DEFAULT_FROM, Pagination.DEFAULT_FROM, query.getFirstPaginationIndex());
    // with a non mumeric value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextServlet.FROM_PARAMETER, "a");
    query = buildQuery(request);
    assertEquals("When a wrong " + FulltextServlet.FROM_PARAMETER + " is specified, the parameter should be "
            + Pagination.DEFAULT_FROM, Pagination.DEFAULT_FROM, query.getFirstPaginationIndex());

    // test last pagination index
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextServlet.TO_PARAMETER);
    query = buildQuery(request);
    int expectedLastPagination = (FulltextQuery.DEFAULT_NB_RESULTS + query.getFirstPaginationIndex() - 1);
    assertEquals(GisgraphyServlet.TO_PARAMETER + " is wrong when no " + GisgraphyServlet.TO_PARAMETER
            + " is specified ", expectedLastPagination, query.getLastPaginationIndex());

    // with too high value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextServlet.TO_PARAMETER);
    request.setParameter(FulltextServlet.TO_PARAMETER, "100");
    query = buildQuery(request);
    expectedLastPagination = (FulltextQuery.DEFAULT_MAX_RESULTS + query.getFirstPaginationIndex() - 1);
    assertEquals(GisgraphyServlet.TO_PARAMETER + " is too high, to should be limited ", expectedLastPagination,
            query.getLastPaginationIndex());
    assertEquals(
            "When no " + FulltextServlet.TO_PARAMETER
                    + " is specified, the  parameter should be set to limit results to "
                    + FulltextQuery.DEFAULT_MAX_RESULTS,
            FulltextQuery.DEFAULT_MAX_RESULTS, query.getMaxNumberOfResults());

    // with a wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextServlet.TO_PARAMETER, "2");// to<from
    query = buildQuery(request);
    expectedLastPagination = (FulltextQuery.DEFAULT_NB_RESULTS + query.getFirstPaginationIndex() - 1);
    assertEquals(GisgraphyServlet.TO_PARAMETER + " is wrong when wrong " + GisgraphyServlet.TO_PARAMETER
            + " is specified ", expectedLastPagination, query.getLastPaginationIndex());
    assertEquals(
            "When a wrong " + FulltextServlet.TO_PARAMETER
                    + " is specified, the number of results should be default nb results",
            FulltextQuery.DEFAULT_NB_RESULTS, query.getMaxNumberOfResults());
    assertEquals("a wrong to does not change the from value", 3, query.getFirstPaginationIndex());
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    //non numeric
    request.setParameter(FulltextServlet.TO_PARAMETER, "a");
    query = buildQuery(request);
    expectedLastPagination = (FulltextQuery.DEFAULT_NB_RESULTS + query.getFirstPaginationIndex() - 1);
    assertEquals(GisgraphyServlet.TO_PARAMETER + " is wrong when non numeric " + GisgraphyServlet.TO_PARAMETER
            + " is specified ", expectedLastPagination, query.getLastPaginationIndex());
    assertEquals("a wrong to does not change the from value", 3, query.getFirstPaginationIndex());
    assertEquals(
            "When a wrong " + FulltextServlet.TO_PARAMETER + " is specified, the numberOf results should be "
                    + FulltextQuery.DEFAULT_NB_RESULTS,
            FulltextQuery.DEFAULT_NB_RESULTS, query.getMaxNumberOfResults());

    // test countrycode
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.COUNTRY_PARAMETER);
    query = buildQuery(request);
    Assert.assertNull(
            "When no " + FulltextQuery.COUNTRY_PARAMETER + " is specified, the parameter should be set to null",
            query.getCountryCode());
    // with a wrong value
    // can not have a wrong value=>always a string

    // test outputFormat
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextServlet.FORMAT_PARAMETER);
    query = buildQuery(request);
    assertEquals("When no " + FulltextServlet.FORMAT_PARAMETER
            + " is specified, the  parameter should be set to  " + OutputFormat.getDefault(),
            OutputFormat.getDefault(), query.getOutputFormat());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextServlet.FORMAT_PARAMETER, "UNK");
    query = buildQuery(request);
    assertEquals(
            "When wrong " + FulltextServlet.FORMAT_PARAMETER
                    + " is specified, the  parameter should be set to  " + OutputFormat.getDefault(),
            OutputFormat.getDefault(), query.getOutputFormat());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextServlet.FORMAT_PARAMETER, "json");
    query = buildQuery(request);
    assertEquals(FulltextServlet.FORMAT_PARAMETER + " should be case insensitive  ", OutputFormat.JSON,
            query.getOutputFormat());
    //with unsupported value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(GisgraphyServlet.FORMAT_PARAMETER, "unsupported");
    query = buildQuery(request);
    assertEquals(GisgraphyServlet.FORMAT_PARAMETER + " should set default if not supported  ",
            OutputFormat.getDefault(), query.getOutputFormat());
    // test language
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.LANG_PARAMETER);
    query = buildQuery(request);
    assertNull(FulltextQuery.LANG_PARAMETER + " should be null when not specified  ",
            query.getOutputLanguage());
    // with empty string
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LANG_PARAMETER, " ");
    query = buildQuery(request);
    assertEquals(FulltextQuery.LANG_PARAMETER + " should be null when not specified  ",
            Output.DEFAULT_LANGUAGE_CODE, query.getOutputLanguage());

    // test uppercase
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.LANG_PARAMETER, "fr");
    query = buildQuery(request);
    assertEquals(FulltextQuery.LANG_PARAMETER + " should be uppercase  ", "FR", query.getOutputLanguage());

    // test placetype
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.PLACETYPE_PARAMETER);
    query = buildQuery(request);
    assertNull("When no " + FulltextQuery.PLACETYPE_PARAMETER
            + " is specified, the  parameter should be set null ", query.getPlaceTypes());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.PLACETYPE_PARAMETER);
    request.setParameter(FulltextQuery.PLACETYPE_PARAMETER, "unk");
    query = buildQuery(request);
    assertNull("When wrong " + FulltextQuery.PLACETYPE_PARAMETER
            + " is specified, the  parameter should be set null ", query.getPlaceTypes()[0]);
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.PLACETYPE_PARAMETER, "ciTy");
    query = buildQuery(request);
    assertEquals(FulltextQuery.PLACETYPE_PARAMETER + " should be case insensitive  ", City.class,
            query.getPlaceTypes()[0]);

    // test with multipleplacetype
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.PLACETYPE_PARAMETER, new String[] { "city", "adm" });
    query = buildQuery(request);
    assertEquals(FulltextQuery.PLACETYPE_PARAMETER + " should accept several placetype  ", 2,
            query.getPlaceTypes().length);
    List<Class<?>> placetypeList = Arrays.asList(query.getPlaceTypes());

    assertTrue(FulltextQuery.PLACETYPE_PARAMETER + " should accept several placetype  ",
            placetypeList.contains(City.class));
    assertTrue(FulltextQuery.PLACETYPE_PARAMETER + " should accept several placetype  ",
            placetypeList.contains(Adm.class));

    // test with multipleplacetype with wrong values
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.PLACETYPE_PARAMETER, new String[] { "city", "unk" });
    query = buildQuery(request);
    assertEquals(FulltextQuery.PLACETYPE_PARAMETER + " should accept several placetype  ", 2,
            query.getPlaceTypes().length);
    placetypeList = Arrays.asList(query.getPlaceTypes());

    assertTrue(FulltextQuery.PLACETYPE_PARAMETER + " should accept several placetype  ",
            placetypeList.contains(City.class));
    assertTrue(FulltextQuery.PLACETYPE_PARAMETER + " should accept several placetype  ",
            placetypeList.contains(null));

    // test output style
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.STYLE_PARAMETER);
    query = buildQuery(request);
    assertEquals("When no " + FulltextQuery.STYLE_PARAMETER + " is specified, the  parameter should be set to  "
            + OutputStyle.getDefault(), OutputStyle.getDefault(), query.getOutputStyle());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.STYLE_PARAMETER, "UNK");
    query = buildQuery(request);
    assertEquals("When wrong " + FulltextQuery.STYLE_PARAMETER
            + " is specified, the  parameter should be set to  " + OutputStyle.getDefault(),
            OutputStyle.getDefault(), query.getOutputStyle());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.STYLE_PARAMETER, "medium");
    query = buildQuery(request);
    assertEquals(FulltextQuery.STYLE_PARAMETER + " should be case insensitive  ", OutputStyle.MEDIUM,
            query.getOutputStyle());

    // test indentation
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(GisgraphyServlet.INDENT_PARAMETER);
    query = buildQuery(request);
    assertEquals(
            "When no " + GisgraphyServlet.INDENT_PARAMETER
                    + " is specified, the  parameter should be set to default",
            Output.DEFAULT_INDENTATION, query.isOutputIndented());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(GisgraphyServlet.INDENT_PARAMETER, "UNK");
    query = buildQuery(request);
    assertEquals(
            "When wrong " + GisgraphyServlet.INDENT_PARAMETER
                    + " is specified, the  parameter should be set to default",
            Output.DEFAULT_INDENTATION, query.isOutputIndented());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(GisgraphyServlet.INDENT_PARAMETER, "True");
    query = buildQuery(request);
    assertTrue(GisgraphyServlet.INDENT_PARAMETER + " should be case insensitive  ", query.isOutputIndented());
    // test with on value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(GisgraphyServlet.INDENT_PARAMETER, "oN");
    query = buildQuery(request);
    assertTrue(
            GisgraphyServlet.INDENT_PARAMETER
                    + " should be true for 'on' value (case insensitive and on value)  ",
            query.isOutputIndented());

    // test suggest
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.SUGGEST_PARAMETER);
    query = buildQuery(request);
    assertEquals("When no " + FulltextQuery.SUGGEST_PARAMETER
            + " is specified, the  parameter should be set to default", false, query.isSuggest());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.SUGGEST_PARAMETER, "UNK");
    query = buildQuery(request);
    assertEquals("When wrong " + FulltextQuery.SUGGEST_PARAMETER
            + " is specified, the  parameter should be set to default", false, query.isSuggest());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.SUGGEST_PARAMETER, "True");
    query = buildQuery(request);
    assertTrue(FulltextQuery.SUGGEST_PARAMETER + " should be case insensitive  ", query.isSuggest());
    // test with on value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.SUGGEST_PARAMETER, "oN");
    query = buildQuery(request);
    assertTrue(FulltextQuery.SUGGEST_PARAMETER
            + " should be true for 'on' value (case insensitive and on value)  ", query.isSuggest());

    // test allwordsRequired
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.ALLWORDSREQUIRED_PARAMETER);
    query = buildQuery(request);
    assertEquals(
            "When no " + FulltextQuery.ALLWORDSREQUIRED_PARAMETER
                    + " is specified, the  parameter should be set to default",
            FulltextQuery.ALL_WORDS_REQUIRED_DEFAULT_OPTION, query.isAllwordsRequired());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.ALLWORDSREQUIRED_PARAMETER, "UNK");
    query = buildQuery(request);
    assertEquals(
            "When wrong " + FulltextQuery.ALLWORDSREQUIRED_PARAMETER
                    + " is specified, the  parameter should be set to default",
            FulltextQuery.ALL_WORDS_REQUIRED_DEFAULT_OPTION, query.isAllwordsRequired());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.ALLWORDSREQUIRED_PARAMETER, "False");
    query = buildQuery(request);
    assertFalse(FulltextQuery.ALLWORDSREQUIRED_PARAMETER + " should be case insensitive  ",
            query.isAllwordsRequired());
    // test with on value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.ALLWORDSREQUIRED_PARAMETER, "oN");
    query = buildQuery(request);
    assertTrue(
            FulltextQuery.ALLWORDSREQUIRED_PARAMETER
                    + " should be true for 'on' value (case insensitive and on value)  ",
            query.isAllwordsRequired());

    // test spellchecking
    // with no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.SPELLCHECKING_PARAMETER);
    query = buildQuery(request);
    assertEquals(
            "When no " + FulltextQuery.SPELLCHECKING_PARAMETER
                    + " is specified, the  parameter should be the default one",
            SpellCheckerConfig.activeByDefault, query.hasSpellChecking());
    // with wrong value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.SPELLCHECKING_PARAMETER, "UNK");
    query = buildQuery(request);
    assertEquals(
            "When wrong " + FulltextQuery.SPELLCHECKING_PARAMETER
                    + " is specified, the  parameter should be set to the default one",
            SpellCheckerConfig.activeByDefault, query.hasSpellChecking());
    // test case sensitive
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.SPELLCHECKING_PARAMETER,
            String.valueOf(!SpellCheckerConfig.activeByDefault).toUpperCase());
    query = buildQuery(request);
    assertEquals(FulltextQuery.SPELLCHECKING_PARAMETER + " should be case insensitive  ",
            !SpellCheckerConfig.activeByDefault, query.hasSpellChecking());
    // test with on value

    boolean savedSpellCheckingValue = SpellCheckerConfig.activeByDefault;
    try {
        SpellCheckerConfig.activeByDefault = false;
        request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
        request.setParameter(FulltextQuery.SPELLCHECKING_PARAMETER, "oN");
        query = buildQuery(request);
        assertTrue(
                FulltextQuery.SPELLCHECKING_PARAMETER
                        + " should be true for 'on' value (case insensitive and on value)  ",
                query.hasSpellChecking());
    } catch (RuntimeException e) {
        Assert.fail(e.getMessage());
    } finally {
        //reset the last value
        SpellCheckerConfig.activeByDefault = savedSpellCheckingValue;
    }

    //apiKey
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(GisgraphyServlet.APIKEY_PARAMETER, "apiKey");
    query = buildQuery(request);
    Assert.assertEquals("apiKey", query.getApikey());

    // test query
    //test with good value
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    query = buildQuery(request);
    assertEquals("query should be set when specified", request.getParameter(FulltextQuery.QUERY_PARAMETER),
            query.getQuery());

    // With no value specified
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.removeParameter(FulltextQuery.QUERY_PARAMETER);
    try {
        query = buildQuery(request);
        fail("A null query should throw");
    } catch (RuntimeException e) {
    }
    // empty string
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.QUERY_PARAMETER, " ");
    try {
        query = buildQuery(request);
        fail("An empty query should throw");
    } catch (RuntimeException e) {
    }
    // too long string
    request = GisgraphyTestHelper.createMockHttpServletRequestForFullText();
    request.setParameter(FulltextQuery.QUERY_PARAMETER,
            RandomStringUtils.random(FulltextQuery.QUERY_MAX_LENGTH) + 1);
    try {
        query = buildQuery(request);
        fail("query must have a maximmum length of " + FulltextQuery.QUERY_MAX_LENGTH);
    } catch (RuntimeException e) {
    }

}