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

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

Introduction

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

Prototype

@Override
public int getStatusCode() 

Source Link

Document

Returns the response status code.

Usage

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

/**
 * Tests a method that throws a NullPointerException inside a called method.
 * /*from   w ww.j a  va2 s.  c o 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 v  a  2  s .  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./*from   ww  w.  j  av a  2  s . co  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  w w . java 2s.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   w w w  .j  a  v a  2 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.
 * /*from  www  .j a v a2s.  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.sequence.SequenceTest.java

/**
 * Calls a resource (which is not a singleton) several times. Verifies that
 * the resource instance is created each time.
 * /* w w w.  j a v a2s . c  om*/
 * @throws Exception
 */
public void testHit100TimesRegularResource() throws Exception {
    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/sequence/static");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(204, deleteMethod.getStatusCode());
    } finally {
        deleteMethod.releaseConnection();
    }

    deleteMethod = new DeleteMethod(getBaseURI() + "/sequence/constructor");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(204, deleteMethod.getStatusCode());
    } finally {
        deleteMethod.releaseConnection();
    }

    for (int c = 0; c < 10; ++c) {
        GetMethod getMethod = new GetMethod(getBaseURI() + "/sequence");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("0", new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/sequence/static");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + c, new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        PostMethod postMethod = new PostMethod(getBaseURI() + "/sequence");
        try {
            client.executeMethod(postMethod);
            assertEquals(200, postMethod.getStatusCode());
            assertEquals("1", new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(),
                    postMethod.getResponseCharSet())).readLine());
        } finally {
            postMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/sequence/static");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + (c + 1), new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/sequence/constructor");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + ((c + 1) * 5), new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }
    }
}

From source file:org.apache.wink.itest.sequence.SequenceTest.java

/**
 * Calls a singleton resource several times. Verifies that the resource
 * instance is re-used each time.//from w  ww . j  ava  2 s. c om
 * 
 * @throws Exception
 */
public void testHit100TimesSingletonResource() throws Exception {
    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/singletonsequence/static");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(204, deleteMethod.getStatusCode());
    } finally {
        deleteMethod.releaseConnection();
    }

    deleteMethod = new DeleteMethod(getBaseURI() + "/singletonsequence/");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(204, deleteMethod.getStatusCode());
    } finally {
        deleteMethod.releaseConnection();
    }

    for (int c = 0; c < 10; ++c) {
        GetMethod getMethod = new GetMethod(getBaseURI() + "/singletonsequence");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + c, new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/singletonsequence/static");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + c, new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        PostMethod postMethod = new PostMethod(getBaseURI() + "/singletonsequence");
        try {
            client.executeMethod(postMethod);
            assertEquals(200, postMethod.getStatusCode());
            assertEquals("" + (c + 1),
                    new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(),
                            postMethod.getResponseCharSet())).readLine());
        } finally {
            postMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/singletonsequence/static");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + (c + 1), new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        /*
         * the constructor for this resource should never be more than 1.
         * note the constructor hit count is never cleared.
         */
        getMethod = new GetMethod(getBaseURI() + "/singletonsequence/constructor");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("1", new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }
    }
}

From source file:org.apache.wink.itest.subresources.JAXRSExceptionsSubresourcesTest.java

/**
 * Test the positive workflow where a comment with a message and author is
 * successfully posted to the Guestbook.
 * //  w  ww. j a v  a2s.  c  om
 * @throws Exception
 */
public void testRuntimeException() throws Exception {
    HttpClient client = new HttpClient();
    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/commentdata/afdsfsdf");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), deleteMethod.getStatusCode());
        // assertLogContainsException("java.lang.NumberFormatException: For input string: \"afdsfsdf\"");
    } finally {
        deleteMethod.releaseConnection();
    }
}

From source file:org.apache.wookie.tests.functional.ParticipantsControllerTest.java

@Test
public void deleteParticipant() {
    try {//  www. j av a 2 s .c  o  m
        HttpClient client = new HttpClient();
        DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
        post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=participantstest&participant_id=1");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(200, code);
        post.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("delete failed");
    }
    // Now lets GET it to make sure it was deleted
    try {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=participantstest");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(200, code);
        String response = get.getResponseBodyAsString();
        assertFalse(response.contains(
                "<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
        get.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("get failed");
    }
}