List of usage examples for org.apache.commons.httpclient.methods DeleteMethod getStatusCode
@Override public int getStatusCode()
From source file:org.xwiki.test.rest.ObjectsResourceTest.java
@Test public void testDELETEObjectUnAuthorized() throws Exception { Object objectToBeDeleted = createObjectIfDoesNotExists("XWiki.TagClass", MAIN_SPACE, "WebHome"); DeleteMethod deleteMethod = executeDelete(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome", objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString()); Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED, deleteMethod.getStatusCode()); GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), MAIN_SPACE, "WebHome", objectToBeDeleted.getClassName(), objectToBeDeleted.getNumber()).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); }
From source file:org.xwiki.test.rest.PageResourceTest.java
@Test public void testDELETEPage() throws Exception { final String pageName = String.format("Test-%d", random.nextLong()); createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, pageName, "Test page"); DeleteMethod deleteMethod = executeDelete( buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, pageName).toString(), TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode()); GetMethod getMethod = executeGet(/*w w w . ja v a 2 s .c om*/ buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, pageName).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode()); }
From source file:org.xwiki.test.rest.PageResourceTest.java
@Test public void testDELETEPageNoRights() throws Exception { final String pageName = String.format("Test-%d", random.nextLong()); createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, pageName, "Test page"); DeleteMethod deleteMethod = executeDelete( buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, pageName).toString()); Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED, deleteMethod.getStatusCode()); GetMethod getMethod = executeGet(/*from w ww . ja v a 2 s . c o m*/ buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, pageName).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); }
From source file:org.xwiki.test.rest.PageTranslationResourceTest.java
@Test public void testPUTGETDELETETranslation() throws Exception { Page newPage = this.objectFactory.createPage(); newPage.setTitle("fr titre"); newPage.setContent("fr contenue"); newPage.setLanguage(Locale.FRENCH.toString()); assertFalse(this.testUtils.rest().exists(this.referenceDefault)); String uri = buildURI(PageTranslationResource.class, getWiki(), this.spaces, this.pageName, Locale.FRENCH) .toString();//from w w w .ja va2s . c o m // PUT PutMethod putMethod = executePutXml(uri, newPage, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword()); assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode()); Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream()); assertEquals("fr titre", modifiedPage.getTitle()); assertEquals("fr contenue", modifiedPage.getContent()); assertEquals(Locale.FRENCH.toString(), modifiedPage.getLanguage()); assertTrue(this.testUtils.rest().exists(this.referenceFR)); assertFalse(this.testUtils.rest().exists(this.referenceDefault)); // GET GetMethod getMethod = executeGet(uri); assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); assertEquals("fr titre", modifiedPage.getTitle()); assertEquals("fr contenue", modifiedPage.getContent()); assertEquals(Locale.FRENCH.toString(), modifiedPage.getLanguage()); // DELETE DeleteMethod deleteMethod = executeDelete(uri, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword()); assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode()); assertFalse(this.testUtils.rest().exists(this.referenceDefault)); assertFalse(this.testUtils.rest().exists(this.referenceFR)); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testPutValueAndDeleteValueAndBucketOnOtherNode() throws Exception { String bucket = UUID.randomUUID().toString(); TestValue value = new TestValue("value", 1); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value"); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();/*from w ww . j a v a 2 s . co m*/ DeleteMethod deleteValue = makeDeleteMethod(NODE2_PORT, bucket + "/value"); HTTP_CLIENT.executeMethod(deleteValue); assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode()); deleteValue.releaseConnection(); DeleteMethod deleteBucket = makeDeleteMethod(NODE2_PORT, bucket); HTTP_CLIENT.executeMethod(deleteBucket); assertEquals(HttpStatus.SC_NO_CONTENT, deleteBucket.getStatusCode()); deleteBucket.releaseConnection(); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testDeleteValueIsIdempotent() throws Exception { String bucket = UUID.randomUUID().toString(); TestValue value = new TestValue("value", 1); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value"); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();//from ww w.j a va 2s . c o m DeleteMethod deleteValue = makeDeleteMethod(NODE2_PORT, bucket + "/value"); HTTP_CLIENT.executeMethod(deleteValue); assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode()); deleteValue.releaseConnection(); HTTP_CLIENT.executeMethod(deleteValue); assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode()); deleteValue.releaseConnection(); }
From source file:terrastore.server.impl.JsonHttpServerTest.java
@Test public void testRemoveBucket() throws Exception { UpdateService updateService = createMock(UpdateService.class); QueryService queryService = createMock(QueryService.class); BackupService backupService = createMock(BackupService.class); StatsService statsService = createMock(StatsService.class); updateService.removeBucket("bucket"); expectLastCall().once();/*from w w w . j a v a 2 s . c om*/ replay(updateService, queryService, backupService, statsService); JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService); HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod("http://localhost:8080/bucket"); client.executeMethod(method); assertEquals(HttpStatus.SC_NO_CONTENT, method.getStatusCode()); method.releaseConnection(); stopServer(server); verify(updateService, queryService, backupService, statsService); }
From source file:terrastore.server.impl.JsonHttpServerTest.java
@Test public void testRemoveValue() throws Exception { UpdateService updateService = createMock(UpdateService.class); QueryService queryService = createMock(QueryService.class); BackupService backupService = createMock(BackupService.class); StatsService statsService = createMock(StatsService.class); updateService.removeValue("bucket", new Key("test1")); expectLastCall().once();/* w w w . j ava2s .c om*/ replay(updateService, queryService, backupService, statsService); JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService); HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod("http://localhost:8080/bucket/test1"); client.executeMethod(method); assertEquals(HttpStatus.SC_NO_CONTENT, method.getStatusCode()); method.releaseConnection(); stopServer(server); verify(updateService, queryService, backupService, statsService); }
From source file:terrastore.server.impl.JsonHttpServerTest.java
@Test public void testRemoveByRangeWithNoComparator() throws Exception { UpdateService updateService = createMock(UpdateService.class); QueryService queryService = createMock(QueryService.class); BackupService backupService = createMock(BackupService.class); StatsService statsService = createMock(StatsService.class); Range range = new Range(new Key("aaaa"), new Key("ffff"), 0, "", 0); updateService.removeByRange("bucket", range, new Predicate(null)); expectLastCall().andReturn(new Keys(Collections.EMPTY_SET)).once(); replay(updateService, queryService, backupService, statsService); JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService); HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod("http://localhost:8080/bucket/range?startKey=aaaa&endKey=ffff"); client.executeMethod(method);/*from ww w .j a v a2 s.c om*/ assertEquals(HttpStatus.SC_OK, method.getStatusCode()); method.releaseConnection(); stopServer(server); verify(updateService, queryService, backupService, statsService); }
From source file:terrastore.server.impl.JsonHttpServerTest.java
@Test public void testRemoveByRangeWithComparator() throws Exception { UpdateService updateService = createMock(UpdateService.class); QueryService queryService = createMock(QueryService.class); BackupService backupService = createMock(BackupService.class); StatsService statsService = createMock(StatsService.class); Range range = new Range(new Key("aaaa"), new Key("ffff"), 0, "lexical-asc", 0); updateService.removeByRange("bucket", range, new Predicate(null)); expectLastCall().andReturn(new Keys(Collections.EMPTY_SET)).once(); replay(updateService, queryService, backupService, statsService); JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService); HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod( "http://localhost:8080/bucket/range?startKey=aaaa&endKey=ffff&comparator=lexical-asc"); client.executeMethod(method);//from ww w . j ava 2 s . co m assertEquals(HttpStatus.SC_OK, method.getStatusCode()); method.releaseConnection(); stopServer(server); verify(updateService, queryService, backupService, statsService); }