List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod
public DeleteMethod(String paramString)
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 sublocator method./*from w w w . ja va 2 s . c o m*/ * * @throws HttpException * @throws IOException */ public void testSublocatorMethodsNotValid() throws HttpException, IOException { HttpMethod method = new PostMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new GetMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new PutMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new DeleteMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new GetMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/counter/sublocator"); try { client.executeMethod(method); assertEquals(200, method.getStatusCode()); assertEquals("0", method.getResponseBodyAsString()); } finally { method.releaseConnection(); } }
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. * /*from ww w . j a v a 2s .com*/ * @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./* w w w . ja v a 2s. c o m*/ * * @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 .ja va2s .c o m*/ * @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 {/*from w w w . ja v a 2s.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"); } }
From source file:org.apache.wookie.tests.functional.ParticipantsControllerTest.java
@Test public void deleteParticipant_InvalidAPIKey() { try {/*from w w w . j a va 2 s .com*/ HttpClient client = new HttpClient(); DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID); post.setQueryString("api_key=" + API_KEY_INVALID + "&widgetid=" + WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest"); client.executeMethod(post); int code = post.getStatusCode(); assertEquals(401, code); post.releaseConnection(); } catch (Exception e) { e.printStackTrace(); fail("post failed"); } }
From source file:org.apache.wookie.tests.functional.ParticipantsControllerTest.java
@Test public void deleteParticipant_InvalidParticipant() { try {// w ww.j ava2s . c om 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=99"); client.executeMethod(post); int code = post.getStatusCode(); assertEquals(404, code); post.releaseConnection(); } catch (Exception e) { e.printStackTrace(); fail("post failed"); } }
From source file:org.apache.wookie.tests.functional.ParticipantsControllerTest.java
@Test public void deleteParticipant_InvalidInstance() { try {// w w w . ja va2 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=participantstestinvalidkey&participant_id=1"); client.executeMethod(post); int code = post.getStatusCode(); assertEquals(400, code); post.releaseConnection(); } catch (Exception e) { e.printStackTrace(); fail("post failed"); } }
From source file:org.apache.wookie.tests.functional.PropertiesControllerTest.java
@Test public void removeProperty() { try {//from w w w . j av a 2 s. co m HttpClient client = new HttpClient(); DeleteMethod delete = new DeleteMethod(TEST_PROPERTIES_SERVICE_URL_VALID); delete.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID + "&userid=test&is_public=true&shareddatakey=propstest&propertyname=cat"); client.executeMethod(delete); int code = delete.getStatusCode(); assertEquals(200, code); delete.releaseConnection(); } catch (Exception e) { fail("delete failed"); } }
From source file:org.apache.wookie.tests.functional.PropertiesControllerTest.java
@Test public void removePropertyNonExisting() { try {// w ww . j av a 2 s. c om HttpClient client = new HttpClient(); DeleteMethod delete = new DeleteMethod(TEST_PROPERTIES_SERVICE_URL_VALID); delete.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID + "&userid=test&is_public=true&shareddatakey=propstest&propertyname=bogus"); client.executeMethod(delete); int code = delete.getStatusCode(); assertEquals(404, code); delete.releaseConnection(); } catch (Exception e) { fail("delete failed"); } }