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.CollectionsControllerTest.java

@Test
public void testCreateCollectionNotGeoJson() throws Exception {
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections", "{foo: 45}",
            MediaType.APPLICATION_JSON_VALUE);
    assertEquals(400, response.getStatus());
}

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

@Test
public void testCreateInvalidAttributeSyntax() throws Exception {
    String testData = new String(getTestData("/collection.json"), "UTF-8");
    // inject an invalid attribute name
    String invalidTestData = testData.replace("primary", "1:2:primary");
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections", invalidTestData,
            MediaType.APPLICATION_JSON_VALUE);
    assertEquals(400, response.getStatus());
    assertThat(response.getContentAsString(), containsString("1:2:primary"));
}

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

@Test
public void testCreateInvalidAttributePrefix() throws Exception {
    String testData = new String(getTestData("/collection.json"), "UTF-8");
    // inject an invalid attribute name
    String invalidTestData = testData.replace("eo:productType", "abc:productType");
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections", invalidTestData,
            MediaType.APPLICATION_JSON_VALUE);
    assertEquals(400, response.getStatus());
    assertThat(response.getContentAsString(), containsString("abc:productType"));
}

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

@Test
public void testCreateInvalidAttributeName() throws Exception {
    String testData = new String(getTestData("/collection.json"), "UTF-8");
    // inject an invalid attribute name
    String invalidTestData = testData.replace("eo:productType", "eo:newProductType");
    MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections", invalidTestData,
            MediaType.APPLICATION_JSON_VALUE);
    assertEquals(400, response.getStatus());
    assertThat(response.getContentAsString(), containsString("eo:newProductType"));
}

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

@Test
public void testUpdateCollection() throws Exception {
    MockHttpServletResponse response;
    createTest123Collection();//from   w  w  w . j  a v a 2 s. c  om

    // grab the JSON to modify some bits
    JSONObject feature = (JSONObject) getAsJSON("/rest/oseo/collections/TEST123");
    JSONObject properties = feature.getJSONObject("properties");
    properties.element("eo:productType", "PT-123");
    properties.element("timeStart", "2017-01-01T00:00:00Z");

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

    // check the changes
    DocumentContext json = getAsJSONPath("/rest/oseo/collections/TEST123", 200);

    assertEquals("PT-123", json.read("$.properties['eo:productType']"));
    assertEquals("2017-01-01T00:00:00.000+0000", json.read("$.properties['timeStart']"));
}

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

@Test
public void testDeleteCollection() throws Exception {
    MockHttpServletResponse response;
    createTest123Collection();//from   www. j  a  va 2 s  . c  o m

    // it's there
    getAsJSONPath("/rest/oseo/collections/TEST123", 200);

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

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

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

@Test
public void testPutCollectionLinks() throws Exception {
    MockHttpServletResponse response;
    createTest123Collection();//  w w w  .j  ava 2 s  . co  m

    // create the links
    response = putAsServletResponse("rest/oseo/collections/TEST123/ogcLinks",
            getTestData("/test123-links.json"), MediaType.APPLICATION_JSON_VALUE);
    assertEquals(200, response.getStatus());

    // check they are there
    assertTest123Links();
}

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

@Test
public void testDeleteCollectionLinks() throws Exception {
    testPutCollectionLinks();/* w  ww.j av  a2  s.  c o m*/

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

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

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

@Test
public void testGetCollectionMetadata() throws Exception {
    MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/metadata");
    assertEquals(200, response.getStatus());
    assertEquals("text/xml", response.getContentType());
    assertThat(response.getContentAsString(),
            both(containsString("gmi:MI_Metadata")).and(containsString("Sentinel-2")));
}

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

@Test
public void testPutCollectionMetadata() throws Exception {
    MockHttpServletResponse response;
    createTest123Collection();/*from w ww .  j  av  a2  s  . com*/

    // create the metadata
    response = putAsServletResponse("rest/oseo/collections/TEST123/metadata",
            getTestData("/test123-metadata.xml"), MediaType.TEXT_XML_VALUE);
    assertEquals(200, response.getStatus());

    // grab and check
    assertTest123Metadata();
}