List of usage examples for org.apache.commons.httpclient HttpStatus SC_ACCEPTED
int SC_ACCEPTED
To view the source code for org.apache.commons.httpclient HttpStatus SC_ACCEPTED.
Click Source Link
From source file:org.xwiki.test.rest.PageResourceTest.java
@Test public void testPUTPageWithTextPlain() throws Exception { final String CONTENT = String.format("This is a content (%d)", System.currentTimeMillis()); Page originalPage = getFirstPage();/*w w w . j a v a2 s. c o m*/ Link link = getFirstLinkByRelation(originalPage, Relations.SELF); Assert.assertNotNull(link); PutMethod putMethod = executePut(link.getHref(), CONTENT, MediaType.TEXT_PLAIN, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode()); Page modifiedPage = (Page) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream()); Assert.assertEquals(CONTENT, modifiedPage.getContent()); }
From source file:org.xwiki.test.rest.PageResourceTest.java
@Test public void testPOSTPageFormUrlEncoded() throws Exception { final String CONTENT = String.format("This is a content (%d)", System.currentTimeMillis()); final String TITLE = String.format("Title (%s)", UUID.randomUUID().toString()); Page originalPage = getFirstPage();/*from ww w. ja v a 2s. c o m*/ Link link = getFirstLinkByRelation(originalPage, Relations.SELF); Assert.assertNotNull(link); NameValuePair[] nameValuePairs = new NameValuePair[2]; nameValuePairs[0] = new NameValuePair("title", TITLE); nameValuePairs[1] = new NameValuePair("content", CONTENT); PostMethod postMethod = executePostForm(String.format("%s?method=PUT", link.getHref()), nameValuePairs, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.getStatusCode()); Page modifiedPage = (Page) unmarshaller.unmarshal(postMethod.getResponseBodyAsStream()); Assert.assertEquals(CONTENT, modifiedPage.getContent()); Assert.assertEquals(TITLE, modifiedPage.getTitle()); }
From source file:org.xwiki.test.rest.PageResourceTest.java
@Test public void testPUTPageSyntax() throws Exception { Page originalPage = getFirstPage();/*from w w w . j av a 2 s . co m*/ // Use the plain/1.0 syntax since we are sure that the test page does not already use it. String newSyntax = "plain/1.0"; originalPage.setSyntax(newSyntax); Link link = getFirstLinkByRelation(originalPage, Relations.SELF); Assert.assertNotNull(link); PutMethod putMethod = executePutXml(link.getHref(), originalPage, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode()); Page modifiedPage = (Page) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream()); Assert.assertEquals(newSyntax, modifiedPage.getSyntax()); }
From source file:org.xwiki.test.rest.TagsResourceTest.java
@Override @Test//from w w w. jav a 2 s .c o m public void testRepresentation() throws Exception { String tagName = UUID.randomUUID().toString(); createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME, "Test"); GetMethod getMethod = executeGet( buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME) .toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); Tags tags = objectFactory.createTags(); Tag tag = objectFactory.createTag(); tag.setName(tagName); tags.getTags().add(tag); PutMethod putMethod = executePutXml( buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString(), tags, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode()); getMethod = executeGet(buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); tags = (Tags) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); boolean found = false; for (Tag t : tags.getTags()) { if (tagName.equals(t.getName())) { found = true; break; } } Assert.assertTrue(found); getMethod = executeGet(buildURI(TagsResource.class, getWiki()).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); tags = (Tags) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); found = false; for (Tag t : tags.getTags()) { if (tagName.equals(t.getName())) { found = true; break; } } Assert.assertTrue(found); getMethod = executeGet(buildURI(PagesForTagsResource.class, getWiki(), tagName).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); Pages pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); found = false; for (PageSummary pageSummary : pages.getPageSummaries()) { if (pageSummary.getFullName().equals( String.format("%s.%s", TestConstants.TEST_SPACE_NAME.get(0), TestConstants.TEST_PAGE_NAME))) { found = true; } } Assert.assertTrue(found); getMethod = executeGet( buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME) .toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); Link tagsLink = getFirstLinkByRelation(page, Relations.TAGS); Assert.assertNotNull(tagsLink); }
From source file:org.xwiki.test.rest.TagsResourceTest.java
@Test public void testPUTTagsWithTextPlain() throws Exception { createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME, "Test"); String tagName = UUID.randomUUID().toString(); GetMethod getMethod = executeGet(//from ww w .ja v a 2s. co m buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME) .toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); PutMethod putMethod = executePut( buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString(), tagName, MediaType.TEXT_PLAIN, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode()); getMethod = executeGet(buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); Tags tags = (Tags) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); boolean found = false; for (Tag t : tags.getTags()) { if (tagName.equals(t.getName())) { found = true; break; } } Assert.assertTrue(found); }
From source file:org.xwiki.test.rest.TagsResourceTest.java
@Test public void testPUTTagsFormUrlEncoded() throws Exception { createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME, "Test"); String tagName = UUID.randomUUID().toString(); GetMethod getMethod = executeGet(/*from ww w . ja va 2 s .c o m*/ buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME) .toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); NameValuePair[] nameValuePairs = new NameValuePair[1]; nameValuePairs[0] = new NameValuePair("tags", tagName); PostMethod postMethod = executePostForm( String.format("%s?method=PUT", buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString()), nameValuePairs, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.getStatusCode()); getMethod = executeGet(buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); Tags tags = (Tags) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); boolean found = false; for (Tag t : tags.getTags()) { if (tagName.equals(t.getName())) { found = true; break; } } Assert.assertTrue(found); }