Example usage for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod

List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod.

Prototype

public DeleteMethod(String paramString) 

Source Link

Usage

From source file:org.apache.wink.itest.exceptionmappers.JAXRSExceptionsMappedProvidersTest.java

/**
 * Tests a method that throws a NullPointerException inside a called method.
 * /*w  ww  .  jav a 2 s  .  c  o  m*/
 * @throws Exception
 */
public void testNullPointerExceptionMappedProvider() throws Exception {
    HttpClient client = new HttpClient();

    DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/10000");
    client.executeMethod(postMethod);
    assertEquals(451, postMethod.getStatusCode());

    CommentError c = (CommentError) JAXBContext.newInstance(CommentError.class.getPackage().getName())
            .createUnmarshaller().unmarshal(postMethod.getResponseBodyAsStream());
    assertEquals("The comment did not previously exist.", c.getErrorMessage());
}

From source file:org.apache.wink.itest.exceptionmappers.JAXRSExceptionsMappedProvidersTest.java

/**
 * Tests a method that throws an error.// ww  w .  j a va  2  s  . c om
 * 
 * @throws Exception
 */
public void testErrorMappedProvider() throws Exception {
    HttpClient client = new HttpClient();

    DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/-99999");
    client.executeMethod(postMethod);
    assertEquals(453, postMethod.getStatusCode());

    CommentError c = (CommentError) JAXBContext.newInstance(CommentError.class.getPackage().getName())
            .createUnmarshaller().unmarshal(postMethod.getResponseBodyAsStream());
    assertEquals("Simulated error", c.getErrorMessage());
}

From source file:org.apache.wink.itest.exceptionmappers.JAXRSExceptionsNoMapperTest.java

/**
 * Tests a method that throws a runtime exception.
 * //from  w  w w.  ja  v  a 2 s  .  c  o m
 * @throws Exception
 */
public void testRuntimeExceptionNoMappingProvider() throws Exception {
    HttpClient client = new HttpClient();

    /*
     * abcd is an invalid ID so a NumberFormatException will be thrown in
     * the resource
     */
    DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/abcd");
    client.executeMethod(postMethod);
    assertEquals(500, postMethod.getStatusCode());

    // assertLogContainsException("java.lang.NumberFormatException: For input string: \"abcd\"");
}

From source file:org.apache.wink.itest.exceptionmappers.JAXRSExceptionsNoMapperTest.java

/**
 * Tests a method that throws a NullPointerException inside a called method.
 * /*  www  .  j  a  v a 2s.co  m*/
 * @throws Exception
 */
public void testNullPointerExceptionNoMappingProvider() throws Exception {
    HttpClient client = new HttpClient();

    DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/10000");
    client.executeMethod(postMethod);
    assertEquals(500, postMethod.getStatusCode());

    // assertLogContainsException("java.lang.NullPointerException: The comment did not previously exist.");
}

From source file:org.apache.wink.itest.exceptionmappers.JAXRSExceptionsNoMapperTest.java

/**
 * Tests a method that throws an error./*from w ww  . j a va 2s.  c om*/
 * 
 * @throws Exception
 */
public void testErrorNoMappingProvider() throws Exception {
    HttpClient client = new HttpClient();

    DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/-99999");
    client.executeMethod(postMethod);
    assertEquals(500, postMethod.getStatusCode());
    // assertLogContainsException("java.lang.Error: Simulated error");
}

From source file:org.apache.wink.itest.exceptionmappers.JAXRSExceptionsNullConditionsTest.java

/**
 * Tests that a <code>WebApplicationException</code> constructed with a
 * cause and response status will return the response status and empty
 * response body by default.//  w w w  .  j a v a2 s  .  c o  m
 * 
 * @throws Exception
 */
public void testWebExceptionWithCauseAndResponseStatus() throws Exception {
    HttpClient client = new HttpClient();

    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/webappexceptionwithcauseandresponsestatus");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), deleteMethod.getStatusCode());
        ServerContainerAssertions.assertExceptionBodyFromServer(400, deleteMethod.getResponseBodyAsString());
    } finally {
        deleteMethod.releaseConnection();
    }
}

From source file:org.apache.wink.itest.exceptionmappers.JAXRSExceptionsNullConditionsTest.java

/**
 * Tests that a Throwable can propagate throughout the code.
 * //w  ww. java 2  s .c  o m
 * @throws Exception
 */
public void testThrowableCanBeThrown() throws Exception {
    HttpClient client = new HttpClient();

    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/throwsthrowable");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), deleteMethod.getStatusCode());
        // assertLogContainsException("jaxrs.tests.exceptions.nullconditions.server.GuestbookResource$1: Throwable was thrown");
    } finally {
        deleteMethod.releaseConnection();
    }
}

From source file:org.apache.wink.itest.InheritanceTest.java

public void testSubResourceLocaterInheritance() throws Exception {
    DeleteMethod deleteMethod = new DeleteMethod(PARKING_LOT_URI + "/cars/remove/ParkingLot");
    GetMethod getMethod = new GetMethod(FRUIT_URI + "/fruit%20suffix");
    PostMethod postMethod = new PostMethod(FRUIT_URI + "/orange%20suffix");
    try {//from ww  w .ja va2 s .  c  o  m
        // ParkingLot classes. Sub resource classes are potential root
        // resources
        httpClient.executeMethod(deleteMethod);
        Header header = deleteMethod.getResponseHeader("Invoked");
        assertNotNull(header);
        assertEquals("ParkingLot.removeCar", header.getValue());
        deleteMethod.releaseConnection();
        deleteMethod = new DeleteMethod(PARKING_LOT_URI + "/cars/remove/ParkingGarage");
        httpClient.executeMethod(deleteMethod);
        header = deleteMethod.getResponseHeader("Invoked");
        assertNotNull(header);
        assertEquals("ParkingGarage.removeCar", header.getValue());
        deleteMethod.releaseConnection();
        deleteMethod = new DeleteMethod(PARKING_LOT_URI + "/cars/remove/CarFerry");
        httpClient.executeMethod(deleteMethod);
        assertEquals(405, deleteMethod.getStatusCode());

        // Fruit classes. Sub resource classes are not potential root
        // resources
        httpClient.executeMethod(getMethod);
        String response = getMethod.getResponseBodyAsString();
        assertEquals("org.apache.wink.itest.fruits.Fruit;fruit%20suffix", response);
        getMethod.releaseConnection();
        getMethod = new GetMethod(FRUIT_URI + "/apple%20suffix");
        httpClient.executeMethod(getMethod);
        response = getMethod.getResponseBodyAsString();
        assertEquals("org.apache.wink.itest.fruits.Apple;apple suffix", // parameters
                // on
                // class
                // are
                // not
                // inherited
                response);
        getMethod.releaseConnection();
        getMethod = new GetMethod(FRUIT_URI + "/orange%20suffix");
        httpClient.executeMethod(getMethod);
        assertEquals(405, getMethod.getStatusCode());
        httpClient.executeMethod(postMethod);
        response = postMethod.getResponseBodyAsString();
        assertEquals("org.apache.wink.itest.fruits.Orange;orange suffix", response);
        assertEquals(200, postMethod.getStatusCode());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    } finally {
        deleteMethod.releaseConnection();
        getMethod.releaseConnection();
    }
}

From source file:org.apache.wink.itest.lifecycles.LifeCycleTest.java

/**
 * Tests that providers are singletons no matter what.
 * /*  w w  w  .j ava  2 s .co  m*/
 * @throws HttpException
 * @throws IOException
 */
public void testProvidersAreSingleton() throws HttpException, IOException {
    StringBuffer sb = new StringBuffer();
    for (long c = 0; c < 5000; ++c) {
        sb.append("a");
    }

    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/jaxrs/tests/lifecycles");
    client.executeMethod(deleteMethod);
    assertEquals(204, deleteMethod.getStatusCode());

    for (int counter = 0; counter < 100; ++counter) {
        PostMethod postMethod = new PostMethod(getBaseURI() + "/jaxrs/tests/lifecycles");
        try {
            postMethod.setRequestEntity(new StringRequestEntity(sb.toString(), "text/plain", null));
            client.executeMethod(postMethod);
            assertEquals(200, postMethod.getStatusCode());
            assertEquals(sb.toString(), postMethod.getResponseBodyAsString());
        } finally {
            postMethod.releaseConnection();
        }
    }

    GetMethod getMethod = new GetMethod(getBaseURI() + "/jaxrs/tests/lifecycles");
    client.executeMethod(getMethod);
    assertEquals(200, getMethod.getStatusCode());
    assertEquals("1:100:100:101:100:1", getMethod.getResponseBodyAsString());
}

From source file:org.apache.wink.itest.nofindmethods.DoNotUseMethodNamesForHTTPVerbsTest.java

/**
 * Negative tests that method names that begin with HTTP verbs are not
 * invoked on a root resource.//from w  w  w.  j  a v a  2  s.  co m
 * 
 * @throws HttpException
 * @throws IOException
 */
public void testMethodsNotValid() throws HttpException, IOException {
    HttpMethod method = new PostMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource");
    try {
        client.executeMethod(method);
        assertEquals(405, method.getStatusCode());
    } finally {
        method.releaseConnection();
    }

    method = new GetMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource");
    try {
        client.executeMethod(method);
        assertEquals(405, method.getStatusCode());
    } finally {
        method.releaseConnection();
    }

    method = new PutMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource");
    try {
        client.executeMethod(method);
        assertEquals(405, method.getStatusCode());
    } finally {
        method.releaseConnection();
    }

    method = new DeleteMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource");
    try {
        client.executeMethod(method);
        assertEquals(405, method.getStatusCode());
    } finally {
        method.releaseConnection();
    }

    method = new GetMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/counter/root");
    try {
        client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        assertEquals("0", method.getResponseBodyAsString());
    } finally {
        method.releaseConnection();
    }
}