Example usage for org.springframework.mock.web MockHttpServletResponse getHeader

List of usage examples for org.springframework.mock.web MockHttpServletResponse getHeader

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletResponse getHeader.

Prototype

@Override
@Nullable
public String getHeader(String name) 

Source Link

Document

Return the primary value for the given header as a String, if any.

Usage

From source file:org.geoserver.rest.catalog.StyleControllerTest.java

@Test
public void testPostAsSLD() throws Exception {
    String xml = newSLDXML();//ww  w.j av  a  2 s. c  o m

    MockHttpServletResponse response = postAsServletResponse(RestBaseController.ROOT_PATH + "/styles", xml,
            SLDHandler.MIMETYPE_10);
    assertEquals(201, response.getStatus());
    assertNotNull(response.getHeader("Location"));
    assertTrue(response.getHeader("Location").endsWith("/styles/foo"));

    assertNotNull(catalog.getStyleByName("foo"));
}

From source file:org.geoserver.rest.catalog.StyleControllerTest.java

@Test
public void testPostAsSLDToWorkspace() throws Exception {
    assertNull(catalog.getStyleByName("gs", "foo"));

    String xml = newSLDXML();/*from  w w  w. j a va2s.  c  om*/

    MockHttpServletResponse response = postAsServletResponse(
            RestBaseController.ROOT_PATH + "/workspaces/gs/styles", xml, SLDHandler.MIMETYPE_10);
    assertEquals(201, response.getStatus());
    assertNotNull(response.getHeader("Location"));
    assertTrue(response.getHeader("Location").endsWith("/workspaces/gs/styles/foo"));

    assertNotNull(catalog.getStyleByName("gs", "foo"));

    GeoServerResourceLoader rl = getResourceLoader();
    assertNotNull(rl.find("workspaces", "gs", "styles", "foo.sld"));
}

From source file:org.geoserver.rest.catalog.StyleControllerTest.java

@Test
public void testPostAsSLDWithName() throws Exception {
    String xml = newSLDXML();/*from  w w w .  j a  v  a 2s. c o  m*/

    MockHttpServletResponse response = postAsServletResponse(RestBaseController.ROOT_PATH + "/styles?name=bar",
            xml, SLDHandler.MIMETYPE_10);
    assertEquals(201, response.getStatus());
    assertNotNull(response.getHeader("Location"));
    assertTrue(response.getHeader("Location").endsWith("/styles/bar"));

    assertNotNull(catalog.getStyleByName("bar"));
}

From source file:org.geoserver.rest.catalog.StyleControllerTest.java

@Test
public void testStyleWithSpaceInName() throws Exception {
    String xml = newSLDXML();//  w  ww  .j  a  v a 2 s.c om

    MockHttpServletResponse response = postAsServletResponse(
            RestBaseController.ROOT_PATH + "/styles?name=Default%20Styler", xml, SLDHandler.MIMETYPE_10);
    assertEquals(201, response.getStatus());
    assertNotNull(response.getHeader("Location"));
    assertThat(response.getHeader("Location"), endsWith("/styles/Default%20Styler"));

    assertNotNull(catalog.getStyleByName("Default Styler"));

    // now delete it, using a + instead of %20, the old code supported it
    response = deleteAsServletResponse(RestBaseController.ROOT_PATH + "/styles/Default+Styler");
    assertEquals(200, response.getStatus());
}

From source file:org.geoserver.rest.catalog.StyleControllerTest.java

@Test
@Ignore/*from  w  ww .j  a  v  a 2s  .com*/
public void testPostAsPSL() throws Exception {
    Properties props = new Properties();
    props.put("type", "point");
    props.put("color", "ff0000");

    StringWriter out = new StringWriter();
    props.store(out, "comment!");

    MockHttpServletResponse response = postAsServletResponse(RestBaseController.ROOT_PATH + "/styles?name=foo",
            out.toString(), PropertyStyleHandler.MIMETYPE);
    assertEquals(201, response.getStatus());
    assertNotNull(response.getHeader("Location"));
    assertTrue(response.getHeader("Location").endsWith("/styles/foo"));

    assertNotNull(catalog.getStyleByName("foo"));

    Resource style = getDataDirectory().style(getCatalog().getStyleByName("foo"));
    InputStream in = style.in();

    props = new Properties();
    try {
        props.load(in);
        assertEquals("point", props.getProperty("type"));
    } finally {
        in.close();
    }

    in = style.in();
    try {
        out = new StringWriter();
        IOUtils.copy(in, out);
        assertFalse(out.toString().startsWith("#comment!"));
    } finally {
        in.close();
    }
}

From source file:org.geoserver.rest.catalog.StyleControllerTest.java

@Test
@Ignore/*from w  w  w. j av  a 2  s  . c  o m*/
public void testPostAsPSLRaw() throws Exception {
    Properties props = new Properties();
    props.put("type", "point");
    props.put("color", "ff0000");

    StringWriter out = new StringWriter();
    props.store(out, "comment!");

    MockHttpServletResponse response = postAsServletResponse(
            RestBaseController.ROOT_PATH + "/styles?name=foo&raw=true", out.toString(),
            PropertyStyleHandler.MIMETYPE);
    assertEquals(201, response.getStatus());
    assertNotNull(response.getHeader("Location"));
    assertTrue(response.getHeader("Location").endsWith("/styles/foo"));

    // check style on disk to ensure the exact contents was preserved
    Resource style = getDataDirectory().style(getCatalog().getStyleByName("foo"));
    try (InputStream in = style.in()) {
        out = new StringWriter();
        IOUtils.copy(in, out);
        assertTrue(out.toString().startsWith("#comment!"));
    }
}

From source file:org.geoserver.rest.catalog.StyleControllerTest.java

@Test
public void testPostAsSE() throws Exception {
    String xml = "<StyledLayerDescriptor xmlns=\"http://www.opengis.net/sld\" "
            + "       xmlns:se=\"http://www.opengis.net/se\" version=\"1.1.0\"> " + " <NamedLayer> "
            + "  <UserStyle> " + "   <se:Name>UserSelection</se:Name> " + "   <se:FeatureTypeStyle> "
            + "    <se:Rule> " + "     <se:PolygonSymbolizer> " + "      <se:Fill> "
            + "       <se:SvgParameter name=\"fill\">#FF0000</se:SvgParameter> " + "      </se:Fill> "
            + "     </se:PolygonSymbolizer> " + "    </se:Rule> " + "   </se:FeatureTypeStyle> "
            + "  </UserStyle> " + " </NamedLayer> " + "</StyledLayerDescriptor>";

    MockHttpServletResponse response = postAsServletResponse(RestBaseController.ROOT_PATH + "/styles?name=foo",
            xml, SLDHandler.MIMETYPE_11);
    assertEquals(201, response.getStatus());
    assertNotNull(response.getHeader("Location"));
    assertTrue(response.getHeader("Location").endsWith("/styles/foo"));

    StyleInfo style = catalog.getStyleByName("foo");
    assertNotNull(style);//from w  w  w. j  a v  a2s .c o m

    assertEquals("sld", style.getFormat());
    assertEquals(SLDHandler.VERSION_11, style.getFormatVersion());
}

From source file:org.geoserver.rest.resources.ResourceControllerTest.java

@Test
public void testResourceHeaders() throws Exception {
    MockHttpServletResponse response = getAsServletResponse(
            RestBaseController.ROOT_PATH + "/resource/mydir2/fake.png");
    Assert.assertEquals(FORMAT_HEADER.format(getDataDirectory().get("/mydir2/fake.png").lastmodified()),
            response.getHeader("Last-Modified"));
    Assert.assertEquals("http://localhost:8080/geoserver" + RestBaseController.ROOT_PATH + "/resource/mydir2",
            response.getHeader("Resource-Parent"));
    Assert.assertEquals("resource", response.getHeader("Resource-Type"));
    assertContentType("image/png", response);
}

From source file:org.geoserver.rest.resources.ResourceControllerTest.java

@Test
public void testResourceHead() throws Exception {
    MockHttpServletResponse response = headAsServletResponse(
            RestBaseController.ROOT_PATH + "/resource/mydir2/fake.png");
    Assert.assertEquals(FORMAT_HEADER.format(getDataDirectory().get("/mydir2/fake.png").lastmodified()),
            response.getHeader("Last-Modified"));
    Assert.assertEquals("http://localhost:8080/geoserver" + RestBaseController.ROOT_PATH + "/resource/mydir2",
            response.getHeader("Resource-Parent"));
    Assert.assertEquals("resource", response.getHeader("Resource-Type"));
    assertContentType("image/png", response);
}

From source file:org.geoserver.rest.resources.ResourceControllerTest.java

@Test
public void testSpecialCharacterNames() throws Exception {
    // if the file system encoded the file with a ? we need to skip this test
    Assume.assumeTrue(/* w  w  w . j av a 2  s . c  o  m*/
            SystemUtils.IS_OS_WINDOWS || getDataDirectory().get("po?zie").getType() == Type.UNDEFINED);
    Assert.assertEquals(Type.DIRECTORY, getDataDirectory().get("pozie").getType());
    XMLUnit.setXpathNamespaceContext(NS_XML);
    Document doc = getAsDOM(RestBaseController.ROOT_PATH + "/resource/po%c3%abzie?format=xml");
    XMLAssert.assertXpathEvaluatesTo(
            "http://localhost:8080/geoserver" + RestBaseController.ROOT_PATH
                    + "/resource/po%C3%ABzie/caf%C3%A9",
            "/ResourceDirectory/children/child/atom:link/@href", doc);

    MockHttpServletResponse response = getAsServletResponse(
            RestBaseController.ROOT_PATH + "/resource/po%c3%abzie/caf%c3%a9?format=xml");
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("resource", response.getHeader("Resource-Type"));
    Assert.assertEquals(
            "http://localhost:8080/geoserver" + RestBaseController.ROOT_PATH + "/resource/po%C3%ABzie",
            response.getHeader("Resource-Parent"));
}