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

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

Introduction

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

Prototype

@Override
    public int getStatus() 

Source Link

Usage

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

@Test
public void testDeleteAllGranules() throws Exception {
    Document dom = getAsDOM(RestBaseController.ROOT_PATH
            + "/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml", 200);
    assertXpathEvaluatesTo("2", "count(//gf:watertemp)", dom);
    // print(dom);

    MockHttpServletResponse response = deleteAsServletResponse(RestBaseController.ROOT_PATH
            + "/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules");
    assertEquals(200, response.getStatus());

    // check it's gone from the index
    dom = getAsDOM(RestBaseController.ROOT_PATH
            + "/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml");
    assertXpathEvaluatesTo("0", "count(//gf:watertemp)", dom);
}

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

@Test
public void testDeleteByFilter() throws Exception {
    Document dom = getAsDOM(RestBaseController.ROOT_PATH
            + "/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml");
    assertXpathEvaluatesTo("2", "count(//gf:watertemp)", dom);
    // print(dom);

    MockHttpServletResponse response = deleteAsServletResponse(
            RestBaseController.ROOT_PATH + "/workspaces/wcs/coveragestores/watertemp/coverages"
                    + "/watertemp/index/granules?filter=ingestion=2008-11-01T00:00:00Z");
    assertEquals(200, response.getStatus());

    // check it's gone from the index
    dom = getAsDOM(RestBaseController.ROOT_PATH
            + "/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml");
    // print(dom);
    assertXpathEvaluatesTo("1", "count(//gf:watertemp)", dom);
    assertXpathEvaluatesTo("2008-10-31T00:00:00Z",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/gf:ingestion", dom);
    assertXpathEvaluatesTo("0",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/gf:elevation", dom);
}

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

@Test
public void testHarvestSingle() throws Exception {
    File file = movedFiles.get(0);
    File target = new File(mosaic, file.getName());
    assertTrue(file.renameTo(target));/*  w  ww .  j  a  va 2  s  . c o m*/

    URL url = DataUtilities.fileToURL(target.getCanonicalFile());
    String body = url.toExternalForm();
    MockHttpServletResponse response = postAsServletResponse(
            RestBaseController.ROOT_PATH + "/workspaces/wcs/coveragestores/watertemp/external.imagemosaic",
            body, "text/plain");
    assertEquals(202, response.getStatus());

    Document dom = getAsDOM(RestBaseController.ROOT_PATH
            + "/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml");
    // print(dom);
    assertXpathEvaluatesTo("3", "count(//gf:watertemp)", dom);
    assertXpathEvaluatesTo("1", "count(//gf:watertemp[gf:location = '" + file.getName() + "'])", dom);
}

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

@Test
public void testHarvestMulti() throws Exception {
    for (File file : movedFiles) {
        File target = new File(mosaic, file.getName());
        assertTrue(file.renameTo(target));
    }/*  ww w .jav a2  s .c  o m*/

    // re-harvest the entire mosaic (two files refreshed, two files added)
    URL url = DataUtilities.fileToURL(mosaic.getCanonicalFile());
    String body = url.toExternalForm();
    MockHttpServletResponse response = postAsServletResponse(
            RestBaseController.ROOT_PATH + "/workspaces/wcs/coveragestores/watertemp/external.imagemosaic",
            body, "text/plain");
    assertEquals(202, response.getStatus());

    Document dom = getAsDOM(RestBaseController.ROOT_PATH
            + "/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml");
    // print(dom);
    assertXpathEvaluatesTo("4", "count(//gf:watertemp)", dom);
    assertXpathEvaluatesTo("2008-10-31T00:00:00Z",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/gf:ingestion", dom);
    assertXpathEvaluatesTo("0",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/gf:elevation", dom);
    assertXpathEvaluatesTo("2008-11-01T00:00:00Z",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081101T0000000_12.tiff']/gf:ingestion", dom);
    assertXpathEvaluatesTo("0",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081101T0000000_12.tiff']/gf:elevation", dom);
    assertXpathEvaluatesTo("2008-10-31T00:00:00Z",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_100_20081031T0000000_12.tiff']/gf:ingestion", dom);
    assertXpathEvaluatesTo("100",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_100_20081031T0000000_12.tiff']/gf:elevation", dom);
    assertXpathEvaluatesTo("2008-11-01T00:00:00Z",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_100_20081101T0000000_12.tiff']/gf:ingestion", dom);
    assertXpathEvaluatesTo("100",
            "//gf:watertemp[gf:location = 'NCOM_wattemp_100_20081101T0000000_12.tiff']/gf:elevation", dom);
}

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

@Test
public void testGetWrongStyle() throws Exception {
    // Parameters for the request
    String ws = "gs";
    String style = "foooooo";
    // Request path
    String requestPath = RestBaseController.ROOT_PATH + "/styles/" + style + ".html";
    String requestPath2 = RestBaseController.ROOT_PATH + "/workspaces/" + ws + "/styles/" + style + ".html";
    // Exception path
    String exception = "No such style: " + style;
    String exception2 = "No such style " + style + " in workspace " + ws;

    // CASE 1: No workspace set

    // First request should thrown an exception
    MockHttpServletResponse response = getAsServletResponse(requestPath);
    assertEquals(404, response.getStatus());
    assertTrue(response.getContentAsString().contains(exception));

    // Same request with ?quietOnNotFound should not throw an exception
    response = getAsServletResponse(requestPath + "?quietOnNotFound=true");
    assertEquals(404, response.getStatus());
    assertFalse(response.getContentAsString().contains(exception));
    // No exception thrown
    assertTrue(response.getContentAsString().isEmpty());

    // CASE 2: workspace set

    // First request should thrown an exception
    response = getAsServletResponse(requestPath2);
    assertEquals(404, response.getStatus());
    assertTrue(response.getContentAsString().contains(exception2));

    // Same request with ?quietOnNotFound should not throw an exception
    response = getAsServletResponse(requestPath2 + "?quietOnNotFound=true");
    assertEquals(404, response.getStatus());
    assertFalse(response.getContentAsString().contains(exception2));
    // No exception thrown
    assertTrue(response.getContentAsString().isEmpty());
}

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

@Test
public void testGetFromWorkspace() throws Exception {
    MockHttpServletResponse resp = getAsServletResponse(
            RestBaseController.ROOT_PATH + "/workspaces/gs/styles/foo.xml");
    assertEquals(404, resp.getStatus());

    addStyleToWorkspace("foo");

    resp = getAsServletResponse(RestBaseController.ROOT_PATH + "/workspaces/gs/styles/foo.xml");
    assertEquals(200, resp.getStatus());

    Document dom = getAsDOM(RestBaseController.ROOT_PATH + "/workspaces/gs/styles/foo.xml");
    assertXpathEvaluatesTo("foo", "/style/name", dom);
    assertXpathEvaluatesTo("gs", "/style/workspace/name", dom);
}

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

@Test
public void testPostAsSLD() throws Exception {
    String xml = newSLDXML();//  w  w  w .ja v a2  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 testPostExternalEntityAsSLD() throws Exception {
    String xml = IOUtils.toString(TestData.class.getResource("externalEntities.sld"), "UTF-8");

    MockHttpServletResponse response = postAsServletResponse(RestBaseController.ROOT_PATH + "/styles", xml,
            SLDHandler.MIMETYPE_10);//from  w  ww . j  av a 2 s . c  o  m
    assertEquals(500, response.getStatus());
    String message = response.getContentAsString();
    assertThat(message, containsString("Entity resolution disallowed"));
    assertThat(message, containsString("/this/file/does/not/exist"));
}

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

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

    String xml = newSLDXML();//ww w  .j av  a2 s .  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  ava2s  .co  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"));
}