/**
   * Test a complete scenario. User sends sld file content via POST and gets back the generated file
   * path. Then user asks via GET to get back the sld file stored on the server
   *
   * @throws Exception
   */
  @Test
  public void testSLDService() throws Exception {

    // valid sld file
    String sldContent =
        "<StyledLayerDescriptor version=\"1.1.0\" xsi:schemaLocation=\"http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd\" xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:se=\"http://www.opengis.net/se\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> <NamedLayer><se:Name>OCEANSEA_1M:Foundation</se:Name><UserStyle><se:Name>GEOSYM</se:Name><IsDefault>1</IsDefault><se:FeatureTypeStyle><se:FeatureTypeName>Foundation</se:FeatureTypeName><se:Rule><se:Name>main</se:Name><se:PolygonSymbolizer uom=\"http://www.opengis.net/sld/units/pixel\"><se:Name>MySymbol</se:Name><se:Description><se:Title>Example Symbol</se:Title><se:Abstract>This is just a simple example.</se:Abstract></se:Description><se:Geometry><ogc:PropertyName>GEOMETRY</ogc:PropertyName></se:Geometry><se:Fill><se:SvgParameter name=\"fill\">#96C3F5</se:SvgParameter></se:Fill></se:PolygonSymbolizer></se:Rule></se:FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>";

    _requestPost.setRequestURI(DOMAIN_NAME + DocController.SLD_URL); // fake URI, Rest style
    _requestPost.setContent(sldContent.getBytes()); // fake body containing sld file
    _requestPost.setContentType("application/vnd.ogc.sld+xml");

    _controller.doSLDPost(_requestPost, _responsePost);
    assertEquals(201, _responsePost.getStatus()); // 201 Created

    String sResp = _responsePost.getContentAsString();

    // the response is actually a JSON object
    JSONObject oResp = new JSONObject(sResp);
    String filePath = (String) oResp.get(DocController.FILEPATH_VARNAME);

    // file name contains absolute url + CSV service path
    assertEquals(true, filePath.contains(DocController.SLD_URL));

    _requestGet.setRequestURI(DOMAIN_NAME + filePath); // fake URI, Rest style

    _controller.getSLDFile(_requestGet, _responseGet);
    assertEquals(200, _responseGet.getStatus()); // 200 OK
    assertEquals(sldContent, _responseGet.getContentAsString().trim()); // content sent is
    // back
  }
  /**
   * Test a complete scenario. User sends .wmc file via POST and gets back the generated file path.
   * Then user asks via GET to get back the file stored on the server
   *
   * @throws Exception
   */
  @Test
  public void testWMCService() throws Exception {

    // valid wmc file content
    String fileContent =
        "<ViewContext xmlns=\"http://www.opengis.net/context\" version=\"1.1.0\" id=\"OpenLayers_Context_133\" xsi:schemaLocation=\"http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><General><Window width=\"1233\" height=\"342\"/><BoundingBox minx=\"-201405.7589\" miny=\"2245252.767\" maxx=\"598866.8058\" maxy=\"2467226.179\" SRS=\"EPSG:2154\"/><Title/><Extension><ol:maxExtent xmlns:ol=\"http://openlayers.org/context\" minx=\"47680.03567\" miny=\"2267644.975\" maxx=\"349781.0112\" maxy=\"2444833.970\"/></Extension></General><LayerList><Layer queryable=\"0\" hidden=\"0\"><Server service=\"OGC:WMS\" version=\"1.1.1\"><OnlineResource xlink:type=\"simple\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:href=\"http://drebretagne-geobretagne.int.lsn.camptocamp.com/geoserver/wms\"/></Server><Name>topp:communes_geofla</Name><Title>communes_geofla</Title><FormatList><Format current=\"1\">image/jpeg</Format></FormatList><StyleList><Style current=\"1\"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol=\"http://openlayers.org/context\" minx=\"47680.03567\" miny=\"2267644.975\" maxx=\"349781.0112\" maxy=\"2444833.970\"/><ol:numZoomLevels xmlns:ol=\"http://openlayers.org/context\">16</ol:numZoomLevels><ol:units xmlns:ol=\"http://openlayers.org/context\">m</ol:units><ol:isBaseLayer xmlns:ol=\"http://openlayers.org/context\">true</ol:isBaseLayer><ol:displayInLayerSwitcher xmlns:ol=\"http://openlayers.org/context\">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol=\"http://openlayers.org/context\">false</ol:singleTile></Extension></Layer></LayerList></ViewContext>"; // wmc file to be send

    _requestPost.setRequestURI(DOMAIN_NAME + DocController.WMC_URL); // fake URI, Rest style
    _requestPost.setContent(fileContent.getBytes()); // fake body containing wmc file

    _controller.storeWMCFile(_requestPost, _responsePost);
    assertEquals(201, _responsePost.getStatus()); // 201 Created

    String sResp = _responsePost.getContentAsString();

    // the response is actually a JSON object
    JSONObject oResp = new JSONObject(sResp);
    String filePath = (String) oResp.get(DocController.FILEPATH_VARNAME);

    // file name contains absolute url + CSV service path
    assertEquals(true, filePath.contains(DocController.WMC_URL));

    _requestGet.setRequestURI(DOMAIN_NAME + filePath); // fake URI, Rest style

    _controller.getWMCFile(_requestGet, _responseGet);
    assertEquals(200, _responseGet.getStatus()); // 200 OK
    assertEquals(fileContent, _responseGet.getContentAsString().trim()); // content sent is
    // back
  }
 @Test
 public void getMediaTypeFilenameWithContextPath() {
   request.setContextPath("/project-1.0.0.M3");
   request.setRequestURI("/project-1.0.0.M3/");
   assertTrue("Context path should be excluded", viewResolver.getMediaTypes(request).isEmpty());
   request.setRequestURI("/project-1.0.0.M3");
   assertTrue("Context path should be excluded", viewResolver.getMediaTypes(request).isEmpty());
 }
  /**
   * Test reject from server when the DocController is accessed with GET and does not receive the
   * filename in argument
   */
  @Test
  public void testDocControllerGETNoFilename() throws Exception {

    // take the WMC url but do not provide the filename in argument
    _requestGet.setRequestURI("mapfishapp/" + DocController.WMC_URL);
    _controller.getCSVFile(_requestGet, _responseGet);
    assertEquals(400, _responseGet.getStatus()); // HTTP 400 Bad Request

    // take the CSV url but do not provide the filename in argument
    _requestGet.setRequestURI("mapfishapp/" + DocController.CSV_URL);
    _controller.getCSVFile(_requestGet, _responseGet);
    assertEquals(400, _responseGet.getStatus()); // HTTP 400 Bad Request
  }
 @Test
 public void getMediaTypeFilenameWithEncodedURI() {
   request.setRequestURI("/quo%20vadis%3f.html");
   List<MediaType> result = viewResolver.getMediaTypes(request);
   assertEquals(
       "Invalid content type", Collections.singletonList(new MediaType("text", "html")), result);
 }
  @Test
  public void resolveViewNameFilename() throws Exception {
    request.setRequestURI("/test.html");

    ViewResolver viewResolverMock1 = createMock("viewResolver1", ViewResolver.class);
    ViewResolver viewResolverMock2 = createMock("viewResolver2", ViewResolver.class);
    viewResolver.setViewResolvers(Arrays.asList(viewResolverMock1, viewResolverMock2));

    View viewMock1 = createMock("application_xml", View.class);
    View viewMock2 = createMock("text_html", View.class);

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    expect(viewResolverMock1.resolveViewName(viewName, locale)).andReturn(viewMock1);
    expect(viewResolverMock1.resolveViewName(viewName + ".html", locale)).andReturn(null);
    expect(viewResolverMock2.resolveViewName(viewName, locale)).andReturn(null);
    expect(viewResolverMock2.resolveViewName(viewName + ".html", locale)).andReturn(viewMock2);
    expect(viewMock1.getContentType()).andReturn("application/xml").anyTimes();
    expect(viewMock2.getContentType()).andReturn("text/html;charset=ISO-8859-1").anyTimes();

    replay(viewResolverMock1, viewResolverMock2, viewMock1, viewMock2);

    View result = viewResolver.resolveViewName(viewName, locale);
    assertSame("Invalid view", viewMock2, result);

    verify(viewResolverMock1, viewResolverMock2, viewMock1, viewMock2);
  }
Ejemplo n.º 7
0
 @Test
 public void shouldNotCheckOperatePermissionForEditingConfigurationRequest() throws Exception {
   request.setParameter("pipelineName", "cruise");
   request.setRequestURI("/admin/restful/configuration");
   request.setMethod("post");
   assertThat(permissionInterceptor.preHandle(request, response, null), is(true));
 }
  @Test(timeout = 10000)
  public void testClassifier() throws Exception {

    int minSize = 4;
    int maxSize = 20;
    int classCount = 3;

    StringBuilder jsonRequest = new StringBuilder();
    jsonRequest.append("{");
    jsonRequest.append("type:\"PROP_SYMBOLS\",");
    jsonRequest.append(
        "wfs_url:\"http://sigma.openplans.org/geoserver/wfs?service=WFS&request=GetCapabilities\",");
    jsonRequest.append("layer_name:\"topp:states\",");
    jsonRequest.append("attribute_name:\"PERSONS\",");
    jsonRequest.append("class_count:\"" + classCount + "\",");
    jsonRequest.append("min_size:\"" + minSize + "\",");
    jsonRequest.append("max_size:\"" + maxSize + "\"");
    jsonRequest.append("}");

    _requestPost.setRequestURI(DOMAIN_NAME + DocController.SLD_URL); // fake URI, Rest style
    _requestPost.setContent(jsonRequest.toString().getBytes()); // fake body containing json request
    _requestPost.setContentType("application/json");

    _controller.doSLDPost(_requestPost, _responsePost);

    assertEquals(200, _responseGet.getStatus()); // 200 OK
  }
 @Test
 public void testGetAdminDeploymentPath_when_no_context_path_or_vhost_set() throws Exception {
   MockHttpServletRequest request = new MockHttpServletRequest();
   request.setRequestURI("/site/0/");
   request.setContextPath(null);
   assertEquals("/site/0", DeploymentPathResolver.getSiteDeploymentPath(request));
 }
  @Test
  public void testFilterProcessesUrlVariationsRespected() throws Exception {
    // Setup our HTTP request
    MockHttpServletRequest request = createMockAuthenticationRequest();
    request.setServletPath("/j_OTHER_LOCATION");
    request.setRequestURI("/mycontext/j_OTHER_LOCATION");

    // Setup our filter configuration
    MockFilterConfig config = new MockFilterConfig(null, null);

    // Setup our expectation that the filter chain will not be invoked, as we redirect to
    // defaultTargetUrl
    MockFilterChain chain = new MockFilterChain(false);
    MockHttpServletResponse response = new MockHttpServletResponse();

    // Setup our test object, to grant access
    MockAuthenticationFilter filter = new MockAuthenticationFilter(true);
    filter.setFilterProcessesUrl("/j_OTHER_LOCATION");
    filter.setAuthenticationSuccessHandler(successHandler);

    // Test
    filter.doFilter(request, response, chain);
    assertEquals("/mycontext/logged_in.jsp", response.getRedirectedUrl());
    assertNotNull(SecurityContextHolder.getContext().getAuthentication());
    assertEquals(
        "test", SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
  }
  @Test
  public void resolveViewNameRedirectView() throws Exception {
    request.addHeader("Accept", "application/json");
    request.setRequestURI("/test");

    StaticWebApplicationContext webAppContext = new StaticWebApplicationContext();
    webAppContext.setServletContext(new MockServletContext());
    webAppContext.refresh();

    UrlBasedViewResolver urlViewResolver = new InternalResourceViewResolver();
    urlViewResolver.setApplicationContext(webAppContext);
    ViewResolver xmlViewResolver = createMock(ViewResolver.class);
    viewResolver.setViewResolvers(Arrays.<ViewResolver>asList(xmlViewResolver, urlViewResolver));

    View xmlView = createMock("application_xml", View.class);
    View jsonView = createMock("application_json", View.class);
    viewResolver.setDefaultViews(Arrays.asList(jsonView));

    String viewName = "redirect:anotherTest";
    Locale locale = Locale.ENGLISH;

    expect(xmlViewResolver.resolveViewName(viewName, locale)).andReturn(xmlView);
    expect(jsonView.getContentType()).andReturn("application/json").anyTimes();

    replay(xmlViewResolver, xmlView, jsonView);

    View actualView = viewResolver.resolveViewName(viewName, locale);
    assertEquals("Invalid view", RedirectView.class, actualView.getClass());

    verify(xmlViewResolver, xmlView, jsonView);
  }
  @Test
  public void givenInValidAPIKey_WhenCallingSecureAPI_ThenShouldNotBeAllowed() throws Exception {

    request.setRequestURI("/api/v1/fortress/");
    request.addHeader("api-key", "someKey");
    TestCase.assertFalse(
        "didn't fail pre-flight", apiKeyInterceptor.preHandle(request, response, null));
  }
 /**
  * For the routing to work correctly we need to have a context set and the pathinfo being part of
  * the request uri. Without this the wrong matching got done in {@link
  * org.springframework.web.util.UrlPathHelper.getPathWithinApplication( HttpServletRequest)}
  *
  * @param method The request method (GET/POST/etc)
  * @param pathInfo The path info
  * @return A request to a context of /context with the path info appended.
  */
 public static MockHttpServletRequest newRequest(String method, String pathInfo) {
   MockHttpServletRequest request = new MockHttpServletRequest();
   request.setMethod(method);
   request.setContextPath("/context");
   request.setRequestURI("/context" + pathInfo);
   request.setPathInfo(pathInfo);
   return request;
 }
Ejemplo n.º 14
0
 @Test
 public void shouldCheckOperatePermissionOnFirstStageForForcePipelineRequest() throws Exception {
   request.setParameter("pipelineName", "cruise");
   request.setRequestURI("/admin/force");
   request.setMethod("post");
   assumeUserHasOperatePermissionForFirstStage();
   assertThat(permissionInterceptor.preHandle(request, response, null), is(true));
 }
Ejemplo n.º 15
0
  public void testResolveLongSitePath1() {

    httpServletRequest.setRequestURI("/site/1/About/Jobs/");

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_1, sitePath.getSiteKey());
    assertEquals("/About/Jobs/", sitePath.getLocalPath().toString());
  }
  @Test
  public void testMultiplePathsTheSameEndpoint() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/path1");
    MockHttpServletResponse response = new MockHttpServletResponse();
    Object handler = this.handlerMapping.getHandler(request).getHandler();
    this.handlerAdapter.handle(request, response, handler);
    assertEquals(TEST_STRING_MULTIPLE_PATHS, response.getContentAsString());

    request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/path2");
    response = new MockHttpServletResponse();
    handler = this.handlerMapping.getHandler(request).getHandler();
    this.handlerAdapter.handle(request, response, handler);
    assertEquals(TEST_STRING_MULTIPLE_PATHS, response.getContentAsString());
  }
 @Test
 public void getURI() throws Exception {
   URI uri = new URI("http://example.com/path?query");
   mockRequest.setServerName(uri.getHost());
   mockRequest.setServerPort(uri.getPort());
   mockRequest.setRequestURI(uri.getPath());
   mockRequest.setQueryString(uri.getQuery());
   assertEquals("Invalid uri", uri, request.getURI());
 }
Ejemplo n.º 18
0
  public void testResolveSimpleSitePath1() {

    httpServletRequest.setRequestURI("/site/1/Frontpage");

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_1, sitePath.getSiteKey());
    assertEquals("/Frontpage", sitePath.getLocalPath().toString());
  }
Ejemplo n.º 19
0
  public void testResolveSitePathWithNoPrefix() {

    sitePathResolver.setSitePathPrefix("");
    httpServletRequest.setRequestURI("/1/");

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_1, sitePath.getSiteKey());
    assertEquals("/", sitePath.getLocalPath().toString());
  }
 @Test
 public void givenNoAPIKey_WhenCallingSecureAPI_ThenShouldNotBeAllowed() throws Exception {
   setSecurity(sally_admin); // Sally is Authorised and has not API Key
   request.setRequestURI("/api/v1/fortress/");
   // exception.expect(SecurityException.class);
   // ToDo: Move to MVC tests
   TestCase.assertFalse(apiKeyInterceptor.preHandle(request, response, null));
   TestCase.assertNotNull(response.getErrorMessage());
   TestCase.assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatus());
 }
Ejemplo n.º 21
0
  @Test
  public void startTest() throws Exception {

    request.setRequestURI("/");
    request.setMethod("GET");

    ModelAndView daumModelAndView = handlerAdapter.handle(request, response, daumController);

    assertViewName(daumModelAndView, "index");
  }
Ejemplo n.º 22
0
  public void testResolveIncludePath() {

    httpServletRequest.setAttribute("javax.servlet.include.request_uri", "/site/1/About/Jobs/");
    httpServletRequest.setRequestURI("/About/Jobs/");

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_1, sitePath.getSiteKey());
    assertEquals("/About/Jobs/", sitePath.getLocalPath().toString());
  }
  @Test
  public void testDefaultProcessesFilterUrlMatchesWithPathParameter() {
    MockHttpServletRequest request = createMockAuthenticationRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockAuthenticationFilter filter = new MockAuthenticationFilter();
    filter.setFilterProcessesUrl("/j_spring_security_check");

    request.setRequestURI("/mycontext/j_spring_security_check;jsessionid=I8MIONOSTHOR");
    assertTrue(filter.requiresAuthentication(request, response));
  }
Ejemplo n.º 24
0
  public void testResolveSimpleSitePath123() {

    httpServletRequest.setCharacterEncoding("ISO-8859-1");
    httpServletRequest.setRequestURI("/site/123/Frontpage/");

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_123, sitePath.getSiteKey());
    assertEquals("/Frontpage/", sitePath.getLocalPath().toString());
  }
Ejemplo n.º 25
0
  public void testResolveSimpleSitePathWithNoLocalPathAndNoEndSlash() {

    httpServletRequest.setCharacterEncoding("ISO-8859-1");
    httpServletRequest.setRequestURI("/site/123");

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_123, sitePath.getSiteKey());
    assertEquals("", sitePath.getLocalPath().toString());
  }
Ejemplo n.º 26
0
  public void xtestRussianSitePath_WithDefaultCharacterEncoding_UTF_8() {

    sitePropertiesService.setProperty(
        siteKey_1, SitePropertyNames.URL_DEFAULT_CHARACTER_ENCODING, "UTF-8");
    httpServletRequest.setRequestURI("/site/1/Services%D0%BB/");

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_1, sitePath.getSiteKey());
    assertEquals("/Servicesл/", sitePath.getLocalPath().toString());
  }
Ejemplo n.º 27
0
  public void testRequiresLogoutUrlWorksWithQueryParams() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/context");
    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setServletPath("/logout");
    request.setRequestURI("/context/logout?param=blah");
    request.setQueryString("otherparam=blah");

    assertTrue(filter.requiresLogout(request, response));
  }
Ejemplo n.º 28
0
  public void xtestSweedishSitePath_With_ISO_8859_1() {

    sitePropertiesService.setProperty(
        siteKey_1, SitePropertyNames.URL_DEFAULT_CHARACTER_ENCODING, "ISO-8859-1");
    httpServletRequest.setRequestURI("/site/1/B%F6t/");

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_1, sitePath.getSiteKey());
    assertEquals("/Böt/", sitePath.getLocalPath().toString());
  }
  private MockHttpServletRequest createMockAuthenticationRequest() {
    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setServletPath("/j_mock_post");
    request.setScheme("http");
    request.setServerName("www.example.com");
    request.setRequestURI("/mycontext/j_mock_post");
    request.setContextPath("/mycontext");

    return request;
  }
Ejemplo n.º 30
0
  public void testGetParamWithMultipleValues() {

    httpServletRequest.setRequestURI("/site/1/Frontpage");
    httpServletRequest.setParameter("param1", new String[] {"value0", "value1"});

    SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest);

    assertEquals(siteKey_1, sitePath.getSiteKey());
    assertEquals("/Frontpage", sitePath.getLocalPath().toString());
    assertEquals("value0", sitePath.getParam("param1"));
  }