List of usage examples for org.springframework.mock.web MockHttpServletRequest getParameter
@Override
@Nullable
public String getParameter(String name)
From source file:fr.paris.lutece.portal.web.upload.UploadServletTest.java
public void testDoPost_NoFiles_Handler2() throws Exception { final String BEAN_NAME = "testAsyncUpMap"; MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); Map<String, List<FileItem>> mapFiles = new HashMap<>(); Map<String, String[]> mapParameters = new HashMap<>(); mapParameters.put("handler", new String[] { BEAN_NAME }); MultipartHttpServletRequest multipartRequest = new MultipartHttpServletRequest(request, mapFiles, mapParameters);/*w w w .j a va2s . c o m*/ clearLuteceSpringCache(); ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) SpringContextService .getContext()).getBeanFactory(); beanFactory.registerSingleton(BEAN_NAME, new IAsynchronousUploadHandler2() { @Override public void process(HttpServletRequest request, HttpServletResponse response, Map<String, Object> mainObject, List<FileItem> fileItems) { mainObject.clear(); mainObject.put("testmap", "valuetestmap"); } @Override public boolean isInvoked(HttpServletRequest request) { return BEAN_NAME.equals(request.getParameter("handler")); } }); try { new UploadServlet().doPost(multipartRequest, response); } catch (Exception e) { throw new RuntimeException(e); } finally { ((DefaultListableBeanFactory) beanFactory).destroySingleton(BEAN_NAME); clearLuteceSpringCache(); } String strResponseJson = response.getContentAsString(); System.out.println(strResponseJson); String strRefJson = "{\"testmap\":\"valuetestmap\"}"; ObjectMapper objectMapper = new ObjectMapper(); JsonNode objectNodeRef = objectMapper.readTree(strRefJson); JsonNode objectNodeJson = objectMapper.readTree(strResponseJson); assertEquals(objectNodeRef, objectNodeJson); }
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 w w w . j a v a 2 s . 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) { } }
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);//from w w w.j a v a 2 s. co m 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()); }