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.opensearch.rest.OSEORestTestSupport.java

protected void createTest123Collection() throws Exception, IOException {
    // create the collection
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections",
            getTestData("/collection.json"), MediaType.APPLICATION_JSON_VALUE);
    assertEquals(201, response.getStatus());
    assertEquals("http://localhost:8080/geoserver/rest/oseo/collections/TEST123",
            response.getHeader("location"));
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testGetProductsForNonExistingCollection() throws Exception {
    MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/fooBar/products");
    assertEquals(404, response.getStatus());
    assertThat(response.getContentAsString(), containsString("fooBar"));
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testGetProductsPagingValidation() throws Exception {
    MockHttpServletResponse response = getAsServletResponse(
            "/rest/oseo/collections/SENTINEL2/products?offset=-1");
    assertEquals(400, response.getStatus());
    assertThat(response.getErrorMessage(), containsString("offset"));

    response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/products?limit=-1");
    assertEquals(400, response.getStatus());
    assertThat(response.getErrorMessage(), containsString("limit"));

    response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/products?limit=1000");
    assertEquals(400, response.getStatus());
    assertThat(response.getErrorMessage(), containsString("limit"));
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testNonExistingProduct() throws Exception {
    MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/products/foobar");
    assertEquals(404, response.getStatus());
    assertThat(response.getContentAsString(), containsString("foobar"));
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testCreateProduct() throws Exception {
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections/SENTINEL2/products",
            getTestData("/product.json"), MediaType.APPLICATION_JSON_VALUE);
    assertEquals(201, response.getStatus());
    assertEquals(/*  www . j av a 2 s  .c o m*/
            "http://localhost:8080/geoserver/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04",
            response.getHeader("location"));

    // check it's really there
    assertProductCreated();
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testUpdateProduct() throws Exception {
    // create the product
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections/SENTINEL2/products",
            getTestData("/product.json"), MediaType.APPLICATION_JSON_VALUE);
    assertEquals(201, response.getStatus());
    assertEquals(/*from   w  w w.  j  ava  2  s.  c  om*/
            "http://localhost:8080/geoserver/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04",
            response.getHeader("location"));

    // grab the JSON to modify some bits
    JSONObject feature = (JSONObject) getAsJSON(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04");
    JSONObject properties = feature.getJSONObject("properties");
    properties.element("eop:orbitNumber", 66);
    properties.element("timeStart", "2017-01-01T00:00:00Z");

    // send it back
    response = putAsServletResponse(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04",
            feature.toString(), "application/json");
    assertEquals(200, response.getStatus());

    // check the changes
    DocumentContext json = getAsJSONPath(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04",
            200);
    assertEquals(Integer.valueOf(66), json.read("$.properties['eop:orbitNumber']"));
    assertEquals("2017-01-01T00:00:00.000+0000", json.read("$.properties['timeStart']"));
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testDeleteProduct() throws Exception {
    // create the product
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections/SENTINEL2/products",
            getTestData("/product.json"), MediaType.APPLICATION_JSON_VALUE);
    assertEquals(201, response.getStatus());
    assertEquals(/*from w  w w  .ja v a 2s  . co m*/
            "http://localhost:8080/geoserver/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04",
            response.getHeader("location"));

    // it's there
    getAsJSONPath(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04",
            200);

    // and now kill the poor beast
    response = deleteAsServletResponse(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04");
    assertEquals(200, response.getStatus());

    // no more there
    response = getAsServletResponse(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04");
    assertEquals(404, response.getStatus());
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testPutProductLinks() throws Exception {
    testCreateProduct();//www . ja  v  a  2 s. c o  m

    // create the links
    MockHttpServletResponse response = putAsServletResponse(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/ogcLinks",
            getTestData("/product-links.json"), MediaType.APPLICATION_JSON_VALUE);
    assertEquals(200, response.getStatus());

    // check they are there
    assertProductLinks();
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testDeleteProductLinks() throws Exception {
    testPutProductLinks();/*  w ww  .  j  a va  2 s  .  c  o  m*/

    // delete the links
    MockHttpServletResponse response = deleteAsServletResponse(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/ogcLinks");
    assertEquals(200, response.getStatus());

    // check they are gone
    response = getAsServletResponse(
            "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/ogcLinks");
    assertEquals(404, response.getStatus());
}

From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java

@Test
public void testGetProductMetadata() throws Exception {
    MockHttpServletResponse response = getAsServletResponse(
            "/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20160117T141030_A002979_T32TPL_N02.01/metadata");
    assertEquals(200, response.getStatus());
    assertEquals("text/xml", response.getContentType());
    assertThat(response.getContentAsString(), both(containsString("opt:EarthObservation"))
            .and(containsString("S2A_OPER_MSI_L1C_TL_SGS__20160117T141030_A002979_T32TPL_N02.01")));
}