Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AuthenticationTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AuthenticationTest.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AuthenticationTest.java (revision 0) @@ -0,0 +1,69 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import java.net.MalformedURLException; + +import org.apache.xmlrpc.XmlRpcException; +import org.junit.Test; +import org.xwiki.xmlrpc.model.ServerInfo; + +public class AuthenticationTest +{ + @Test + public void loginLogout() throws MalformedURLException, XmlRpcException + { + XWikiXmlRpcClient rpc = + new XWikiXmlRpcClient(TestConstants.ENDPOINT, TestConstants.ENDPOINT_HANDLER); + rpc.login(TestConstants.USERNAME, TestConstants.PASSWORD); + rpc.logout(); + } + + @Test(expected = XmlRpcException.class) + public void loginWithInvalidUser() throws MalformedURLException, XmlRpcException + { + XWikiXmlRpcClient rpc = + new XWikiXmlRpcClient(TestConstants.ENDPOINT, TestConstants.ENDPOINT_HANDLER); + rpc.login("thisUserShouldNotExist", "foo"); + } + + @Test(expected = XmlRpcException.class) + public void xwikiXmlRpcServiceWithoutLogin() throws MalformedURLException, XmlRpcException + { + XWikiXmlRpcClient rpc = + new XWikiXmlRpcClient(TestConstants.ENDPOINT, TestConstants.ENDPOINT_HANDLER); + rpc.getSpaces(); + } + + @Test + public void getServerInfo() throws MalformedURLException, XmlRpcException + { + XWikiXmlRpcClient rpc = + new XWikiXmlRpcClient(TestConstants.ENDPOINT, TestConstants.ENDPOINT_HANDLER); + rpc.login(TestConstants.USERNAME, TestConstants.PASSWORD); + + ServerInfo serverInfo = rpc.getServerInfo(); + TestUtils.banner("TEST: getServerInfo()"); + System.out.format("%s\n", serverInfo); + + rpc.logout(); + } +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/PagesTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/PagesTest.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/PagesTest.java (revision 0) @@ -0,0 +1,419 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.xmlrpc.XmlRpcException; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xwiki.xmlrpc.model.Page; +import org.xwiki.xmlrpc.model.PageHistorySummary; +import org.xwiki.xmlrpc.model.PageSummary; +import org.xwiki.xmlrpc.model.SpaceSummary; +import org.xwiki.xmlrpc.model.Utils; + +public class PagesTest extends AbstractXWikiXmlRpcTest +{ + @BeforeClass + public static void setupPage() throws XmlRpcException + { + try { + rpc.getPage(TestConstants.TEST_PAGE); + } catch (Exception e) { + Page page = + new Page(TestConstants.TEST_PAGE, + TestConstants.TEST_SPACE, + "Test page", + "Test page"); + rpc.storePage(page); + } + + try { + rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS); + } catch (Exception e) { + Page page = + new Page(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, + TestConstants.TEST_SPACE, + "Test page for translations", + "Test page for translations"); + rpc.storePage(page); + } + } + + @Test + public void getPages() throws XmlRpcException + { + List spaces = rpc.getSpaces(); + List pages = rpc.getPages(spaces.get(0).getKey()); + + TestUtils.banner("TEST: getPages()"); + for (PageSummary pageSummary : pages) { + System.out.format("%s\n", pageSummary); + } + + assertFalse(pages.isEmpty()); + } + + @Test + public void getPagesWithNoRightsOnSpace() throws XmlRpcException + { + if (TestConstants.USERNAME.equals("Admin")) { + /* If the username is Admin this test will fail. Just return to make it pass. */ + return; + } + + List pages = rpc.getPages(TestConstants.SPACE_WITH_NO_ACCESS_RIGHTS); + assertTrue(pages.isEmpty()); + } + + @Test + public void getPage() throws XmlRpcException + { + List spaces = rpc.getSpaces(); + List pages = rpc.getPages(spaces.get(0).getKey()); + Page page = rpc.getPage(pages.get(0).getId()); + + TestUtils.banner("TEST: getPage()"); + System.out.format("%s\n", page); + + assertEquals(page.getId(), pages.get(0).getId()); + } + + @Test + public void storePage() throws XmlRpcException + { + Page page = rpc.getPage(TestConstants.TEST_PAGE); + + String content = String.format("Modified by org.xwiki.xmlrpc @ %s\n", new Date()); + + page.setContent(content); + Page storedPage = rpc.storePage(page); + + TestUtils.banner("TEST: storePage()"); + System.out.format("Content sent: '%s'\n", Utils.truncateToFirstLine(content)); + System.out.format("%s\n", storedPage); + + assertEquals(storedPage.getContent(), content); + assertTrue(storedPage.getVersion() == (page.getVersion() + 1)); + assertEquals(page.getLanguage(), storedPage.getLanguage()); + } + + @Test + public void changeParentId() throws XmlRpcException + { + List pages = rpc.getPages(TestConstants.TEST_SPACE); + PageSummary pageSummary1 = pages.get(0); + PageSummary pageSummary2 = null; + for (PageSummary ps : pages) { + if (!pageSummary1.getParentId().equals(ps.getId())) { + pageSummary2 = ps; + } + } + + TestUtils.banner("TEST: changeParentId()"); + System.out.format("Setting page '%s' parent id to '%s'. Now: '%s'\n", pageSummary1 + .getId(), pageSummary2.getId(), pageSummary1.getParentId()); + Page page = rpc.getPage(pageSummary1.getId()); + assertNotSame(pageSummary2.getId(), page.getParentId()); + + page.setParentId(pageSummary2.getId()); + page = rpc.storePage(page); + + System.out.format("New page: %s\n", page); + + assertEquals(pageSummary2.getId(), page.getParentId()); + } + + @Test + public void storeNewPageTranslation() throws XmlRpcException + { + /* Get the current page and all its available translations */ + Page page = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS); + Map before = new HashMap(); + before.put(page.getLanguage(), page); + for (String l : page.getTranslations()) { + Page p = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, l); + before.put(l, p); + } + + /* Add a translation in a fake language */ + String fakeLanguage = (String.format("%d", Math.abs(random.nextInt()))).substring(0, 4); + String translatedContent = + String.format("This is the content in the '%s' language.", fakeLanguage); + Page translatedPage = + new Page(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, + TestConstants.TEST_SPACE, + "Translated page", + translatedContent, + fakeLanguage); + translatedPage = rpc.storePage(translatedPage); + + /* Re-get the page and all its translations */ + page = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS); + Map after = new HashMap(); + after.put(page.getLanguage(), page); + for (String l : page.getTranslations()) { + Page p = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, l); + after.put(l, p); + } + + TestUtils.banner("TEST: storeNewPageTranslation()"); + System.out.format("Adding the '%s' translation...\n", fakeLanguage); + System.out.format("*********************************\n"); + System.out.format("Before: %s\n", before); + System.out.format("*********************************\n"); + System.out.format("After: %s\n", after); + + /* Check for correctenss */ + assertFalse(before.containsKey(fakeLanguage)); + assertTrue(after.containsKey(fakeLanguage)); + assertEquals(translatedContent, after.get(fakeLanguage).getContent()); + + for (String l : before.keySet()) { + assertTrue(after.containsKey(l)); + Page b = before.get(l); + Page a = after.get(l); + + assertEquals(b.getVersion(), a.getVersion()); + assertEquals(b.getContent(), a.getContent()); + } + } + + @Test + public void storePageTranslation() throws XmlRpcException + { + Page page = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS); + + Map translatedContents = new HashMap(); + translatedContents.put(Page.DEFAULT_LANGUAGE, page.getContent()); + for (String l : page.getTranslations()) { + Page p = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, l); + translatedContents.put(l, p.getContent()); + } + + TestUtils.banner("TEST: storeTranslatedPage()"); + System.out.format("%s\n", page); + + String targetLanguage = page.getTranslations().get(0); + String content = + String.format("This is a new translation for language '%s' @ %s", targetLanguage, + new Date()); + + Page translatedPage = + new Page(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, + TestConstants.TEST_SPACE, + "Translated page", + content, + targetLanguage); + translatedPage = rpc.storePage(translatedPage); + + System.out.format("New content: %s\n", content); + System.out.format("%s\n", page); + + /* The following command could be removed. Check it! */ + translatedPage = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS); + Map newTranslatedContents = new HashMap(); + newTranslatedContents.put(Page.DEFAULT_LANGUAGE, page.getContent()); + for (String l : page.getTranslations()) { + Page p = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, l); + newTranslatedContents.put(l, p.getContent()); + } + + System.out.format("Old translations: %s\n", translatedContents); + System.out.format("New translations: %s\n", newTranslatedContents); + + assertEquals(translatedContents.keySet(), newTranslatedContents.keySet()); + + for (String l : newTranslatedContents.keySet()) { + if (!l.equals(targetLanguage)) { + assertEquals(translatedContents.get(l), newTranslatedContents.get(l)); + } else { + assertEquals(content, newTranslatedContents.get(l)); + } + } + } + + @Test + public void getPageWithTranslations() throws XmlRpcException + { + Page page = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS); + + TestUtils.banner("TEST: getPageWithTranslations()"); + System.out.format("%s\n", page); + + assertFalse(page.getTranslations().isEmpty()); + } + + @Test + public void getPageTranslations() throws XmlRpcException + { + Page page = rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS); + + TestUtils.banner("TEST: getPageTranslations()"); + + for (String language : page.getTranslations()) { + Page translatedPage = + rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, language); + System.out.format("Page for language '%s': %s\n", language, translatedPage); + + assertEquals(language, translatedPage.getLanguage()); + } + } + + @Test + public void createPage() throws XmlRpcException + { + String pageId = + String.format("%s.%s-%d", TestConstants.TEST_SPACE, TestConstants.TEST_PREFIX, Math + .abs(random.nextInt())); + String content = String.format("Modified by org.xwiki.xmlrpc @ %s\n", new Date()); + Page page = null; + + TestUtils.banner("TEST: createPage()"); + + try { + page = rpc.getPage(pageId); + throw new RuntimeException(String.format("Page %s exists!", pageId)); + } catch (Exception e) { + System.out.format("Page %s does not exist... Good!\n", pageId); + } + + page = new Page(pageId, TestConstants.TEST_SPACE, "Test page", content); + Page storedPage = rpc.storePage(page); + + System.out.format("Content sent: '%s'\n", Utils.truncateToFirstLine(content)); + System.out.format("%s\n", storedPage); + + assertEquals(storedPage.getContent(), content); + + /* + * This is normal since on the server side the getDocument actually creates the empty + * document with version 1, and the doc.save() store the actual content by incrementing the + * version + */ + assertTrue(storedPage.getVersion() == 2); + assertEquals(page.getLanguage(), storedPage.getLanguage()); + } + + @Test(expected = XmlRpcException.class) + public void createPageInSpaceWithNoAccessRights() throws XmlRpcException + { + if (TestConstants.USERNAME.equals("Admin")) { + /* If the username is Admin this test will fail. Throw an exception to make it pass. */ + throw new XmlRpcException("User admin can always access everything"); + } + + String pageId = + String.format("%s.%s-%d", TestConstants.SPACE_WITH_NO_ACCESS_RIGHTS, + TestConstants.TEST_PREFIX, Math.abs(random.nextInt())); + String content = String.format("Modified by org.xwiki.xmlrpc @ %s\n", new Date()); + Page page = null; + + TestUtils.banner("TEST: createPageInSpaceWithNoAccessRights()"); + + try { + page = rpc.getPage(pageId); + throw new RuntimeException(String.format("Page %s exists!", pageId)); + } catch (Exception e) { + System.out.format("Page %s does not exist... Good!\n", pageId); + } + + page = new Page(pageId, TestConstants.TEST_SPACE, "Test page", content); + rpc.storePage(page); + } + + @Test + public void removePage() throws XmlRpcException + { + List pages = rpc.getPages(TestConstants.TEST_SPACE); + PageSummary pageToBeDeleted = null; + for (PageSummary pageSummary : pages) { + if (pageSummary.getName().startsWith(TestConstants.TEST_PREFIX)) { + pageToBeDeleted = pageSummary; + break; + } + } + + Boolean result = rpc.removePage(pageToBeDeleted); + TestUtils.banner("TEST: removePage()"); + System.out.format("Page %s removed: %b\n", pageToBeDeleted.getId(), result); + + pages = rpc.getPages(TestConstants.TEST_SPACE); + boolean removed = true; + for (PageSummary pageSummary : pages) { + if (pageSummary.getId().equals(pageToBeDeleted.getId())) { + removed = false; + break; + } + } + + assertTrue(removed); + } + + @Test + public void getPageHistory() throws XmlRpcException + { + List pageHistorySummaries = + rpc.getPageHistory(TestConstants.TEST_PAGE); + + TestUtils.banner("TEST: getPageHistory()"); + for (PageHistorySummary pageHistorySummary : pageHistorySummaries) { + System.out.format("%s\n", pageHistorySummary); + } + + assertFalse(pageHistorySummaries.isEmpty()); + } + + @Test + public void getPageAtVersion() throws XmlRpcException + { + List pageHistorySummaries = + rpc.getPageHistory(TestConstants.TEST_PAGE); + PageHistorySummary pageHistorySummary = + pageHistorySummaries.get(random.nextInt(pageHistorySummaries.size())); + + Page page = rpc.getPage(TestConstants.TEST_PAGE, pageHistorySummary.getVersion()); + TestUtils.banner("TEST: getPageAtVersion()"); + System.out.format("%s\n", pageHistorySummary); + System.out.format("%s\n", page); + + assertEquals(pageHistorySummary.getVersion(), page.getVersion()); + assertEquals(pageHistorySummary.getModifier(), page.getModifier()); + + /* + * This test occasionally fails because the version returned as the modification date by + * XWiki when getting a page with a given version is always equal to the current date/time. + * So if the previous version to getPageHistory is made, let's say at 12:53:59 and the + * subsequent getPage at 12:54:01 then the date in the pageHistory item will differ from the + * one in the actual page and the test will fail. Let's disable this check. + */ + // assertEquals(pageHistorySummary.getModified(), page.getModified()); + } +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/TestUtils.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/TestUtils.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/TestUtils.java (revision 0) @@ -0,0 +1,52 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +public class TestUtils +{ + public static void banner(String message) + { + banner(message, 80); + } + + public static void banner(String message, int size) + { + System.out.println(); + + for (int i = 0; i < size; i++) { + System.out.print("*"); + } + + System.out.format("\n* %s ", message); + + for (int i = 0; i < (size - message.length() - 3); i++) { + System.out.print("*"); + } + + System.out.println(); + + for (int i = 0; i < size; i++) { + System.out.print("*"); + } + + System.out.println(); + } +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AbstractXWikiXmlRpcTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AbstractXWikiXmlRpcTest.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AbstractXWikiXmlRpcTest.java (revision 0) @@ -0,0 +1,50 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import java.net.MalformedURLException; +import java.util.Random; + +import org.apache.xmlrpc.XmlRpcException; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class AbstractXWikiXmlRpcTest +{ + protected static XWikiXmlRpcClient rpc; + + protected static Random random; + + @BeforeClass + public static void setupClass() throws MalformedURLException, XmlRpcException + { + rpc = new XWikiXmlRpcClient(TestConstants.ENDPOINT, TestConstants.ENDPOINT_HANDLER); + rpc.login(TestConstants.USERNAME, TestConstants.PASSWORD); + random = new Random(); + } + + @AfterClass + public static void tearDownClass() throws XmlRpcException + { + rpc.logout(); + rpc = null; + } +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/CommentsTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/CommentsTest.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/CommentsTest.java (revision 0) @@ -0,0 +1,103 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; + +import java.util.List; + +import org.apache.xmlrpc.XmlRpcException; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xwiki.xmlrpc.model.Comment; +import org.xwiki.xmlrpc.model.Page; + +public class CommentsTest extends AbstractXWikiXmlRpcTest +{ + @BeforeClass + public static void setupPage() throws XmlRpcException + { + try { + rpc.getPage(TestConstants.TEST_PAGE_WITH_COMMENTS); + } catch (Exception e) { + Page page = + new Page(TestConstants.TEST_PAGE_WITH_COMMENTS, + TestConstants.TEST_SPACE, + "Test page for comments", + "Test page for comments"); + rpc.storePage(page); + } + } + + @Test + public void addComment() throws XmlRpcException + { + String content = String.format("This is a new comment!!! %s", random.nextInt()); + Comment comment = new Comment(TestConstants.TEST_PAGE_WITH_COMMENTS, content); + + comment = rpc.addComment(comment.getPageId(), comment); + TestUtils.banner("TEST: getComments()"); + System.out.format("%s\n", comment); + + assertNotSame("NEW", comment.getId()); + assertEquals(content, comment.getContent()); + assertEquals(String.format("XWiki.%s", TestConstants.USERNAME), comment.getCreator()); + } + + @Test + public void getComments() throws XmlRpcException + { + List comments = rpc.getComments(TestConstants.TEST_PAGE_WITH_COMMENTS); + + TestUtils.banner("TEST: getComments()"); + for (Comment comment : comments) { + System.out.format("%s\n", comment); + } + + assertFalse(comments.isEmpty()); + } + + @Test + public void removeComment() throws XmlRpcException + { + List comments = rpc.getComments(TestConstants.TEST_PAGE_WITH_COMMENTS); + Comment comment = comments.get(random.nextInt(comments.size())); + + Boolean result = + rpc.removeComment(TestConstants.TEST_PAGE_WITH_COMMENTS, comment.getId()); + TestUtils.banner("TEST: removeComment()"); + System.out.format("Comment removed = %b\n", result); + + comments = rpc.getComments(TestConstants.TEST_PAGE_WITH_COMMENTS); + boolean found = false; + for (Comment c : comments) { + if (c.getId().equals(comment.getId())) { + found = true; + break; + } + } + + assertFalse(found); + } + +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/XWikiObjectsTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/XWikiObjectsTest.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/XWikiObjectsTest.java (revision 0) @@ -0,0 +1,168 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.xmlrpc.XmlRpcException; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xwiki.xmlrpc.model.Page; +import org.xwiki.xmlrpc.model.XWikiObject; +import org.xwiki.xmlrpc.model.XWikiObjectSummary; + +public class XWikiObjectsTest extends AbstractXWikiXmlRpcTest +{ + @BeforeClass + public static void setupPage() throws XmlRpcException + { + try { + rpc.getPage(TestConstants.TEST_PAGE_WITH_OBJECTS); + } catch (Exception e) { + Page page = + new Page(TestConstants.TEST_PAGE_WITH_OBJECTS, + TestConstants.TEST_SPACE, + "Test page for objects", + "Test page for objects"); + rpc.storePage(page); + } + } + + @Test + public void createTagsObject() throws XmlRpcException + { + XWikiObject tagsObject = + new XWikiObject(TestConstants.TEST_PAGE_WITH_OBJECTS, "XWiki.TagClass", "PrettyName"); + + List tags = new ArrayList(); + tags.add(String.format("New-%d", random.nextInt())); + tagsObject.set("tags", tags); + + tagsObject = rpc.storeObject(tagsObject); + + TestUtils.banner("createTagsObject()"); + System.out.format("%s\n", tagsObject); + + Assert.assertTrue(tagsObject.getId() != -1); + } + + @Test + public void getXWikiObjects() throws XmlRpcException + { + List xwikiObjects = + rpc.getObjects(TestConstants.TEST_PAGE_WITH_OBJECTS); + + TestUtils.banner("TEST: getXWikiObjects()"); + for (XWikiObjectSummary xwikiObjectSummary : xwikiObjects) { + System.out.format("%s\n", xwikiObjectSummary); + } + + assertFalse(xwikiObjects.isEmpty()); + } + + @Test + public void getXWikiTagObject() throws XmlRpcException + { + List xwikiObjects = + rpc.getObjects(TestConstants.TEST_PAGE_WITH_OBJECTS); + + XWikiObjectSummary tagsObjectSummary = null; + for (XWikiObjectSummary xwikiObjectSummary : xwikiObjects) { + if (xwikiObjectSummary.getClassName().equals("XWiki.TagClass")) { + tagsObjectSummary = xwikiObjectSummary; + } + } + + XWikiObject tagsObject = rpc.getObject(tagsObjectSummary); + + TestUtils.banner("TEST: getXWikiTagObject()"); + System.out.format("%s\n", tagsObject); + + assertEquals(tagsObjectSummary.getPageId(), tagsObject.getPageId()); + assertEquals(tagsObjectSummary.getId(), tagsObject.getId()); + assertEquals(tagsObjectSummary.getClassName(), tagsObject.getClassName()); + } + + @Test + public void setTagsObject() throws XmlRpcException + { + XWikiObject object = + rpc.getObject(TestConstants.TEST_PAGE_WITH_OBJECTS, "XWiki.TagClass", 0); + + TestUtils.banner("TEST: setTagsObject()"); + System.out.format("%s\n", object); + + Object value = object.get("tags"); + assertTrue(value instanceof List); + + List tags = (List) value; + tags.add((new Integer(random.nextInt()).toString())); + + rpc.storeObject(object); + + object = rpc.getObject(TestConstants.TEST_PAGE_WITH_OBJECTS, "XWiki.TagClass", 0); + List newTags = (List) object.get("tags"); + + assertTrue(newTags.size() == tags.size()); + + for (Object t : tags) { + assertTrue(newTags.contains(t)); + } + + } + + @Test + public void removeObject() throws XmlRpcException + { + XWikiObject tagsObject = + new XWikiObject(TestConstants.TEST_PAGE_WITH_OBJECTS, "XWiki.TagClass", "PrettyName"); + + List tags = new ArrayList(); + tags.add(String.format("New-%d", random.nextInt())); + tagsObject.set("tags", tags); + + tagsObject = rpc.storeObject(tagsObject); + + Boolean result = rpc.removeObject(tagsObject); + + TestUtils.banner("removeObjectTest()"); + System.out.format("Object added: %s\n", tagsObject); + System.out.format("Object removed = %b\n", result); + + List objects = rpc.getObjects(tagsObject.getPageId()); + boolean found = false; + for (XWikiObjectSummary object : objects) { + if (object.getClassName().equals(tagsObject.getClassName()) + && object.getId().equals(tagsObject.getId())) { + found = true; + break; + } + } + + Assert.assertFalse(found); + } +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/XWikiClassesTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/XWikiClassesTest.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/XWikiClassesTest.java (revision 0) @@ -0,0 +1,65 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import java.util.List; + +import org.apache.xmlrpc.XmlRpcException; +import org.junit.Test; +import org.xwiki.xmlrpc.model.XWikiClass; +import org.xwiki.xmlrpc.model.XWikiClassSummary; + +public class XWikiClassesTest extends AbstractXWikiXmlRpcTest +{ + @Test + public void getXWikiClasses() throws XmlRpcException + { + List xwikiClasses = rpc.getClasses(); + + TestUtils.banner("TEST: getXWikiClasses()"); + for (XWikiClassSummary xwikiClassSummary : xwikiClasses) { + System.out.format("%s\n", xwikiClassSummary); + } + + assertFalse(xwikiClasses.isEmpty()); + } + + @Test + public void getXWikiClass() throws XmlRpcException + { + List xwikiClasses = rpc.getClasses(); + XWikiClass xwikiClass = rpc.getClass(xwikiClasses.get(0).getId()); + + TestUtils.banner("TEST: getXWikiClass()"); + System.out.format("%s\n", xwikiClass); + + assertEquals(xwikiClasses.get(0).getId(), xwikiClass.getId()); + } + + @Test(expected = XmlRpcException.class) + public void getNonExistentXWikiClass() throws XmlRpcException + { + XWikiClass xwikiClass = rpc.getClass("thisClassShouldNotExist"); + } +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AllTests.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AllTests.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AllTests.java (revision 0) @@ -0,0 +1,33 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses( {AuthenticationTest.class, SpacesTest.class, PagesTest.class, CommentsTest.class, +XWikiClassesTest.class, XWikiObjectsTest.class, AttachmentsTest.class}) +public class AllTests +{ + +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AttachmentsTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AttachmentsTest.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/AttachmentsTest.java (revision 0) @@ -0,0 +1,129 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.apache.xmlrpc.XmlRpcException; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xwiki.xmlrpc.model.Attachment; +import org.xwiki.xmlrpc.model.Page; +import org.xwiki.xmlrpc.model.Utils; + +public class AttachmentsTest extends AbstractXWikiXmlRpcTest +{ + @BeforeClass + public static void setupPage() throws XmlRpcException + { + try { + rpc.getPage(TestConstants.TEST_PAGE_WITH_ATTACHMENTS); + } catch (Exception e) { + Page page = + new Page(TestConstants.TEST_PAGE_WITH_ATTACHMENTS, + TestConstants.TEST_SPACE, + "Test page for attachments", + "Test page for attachments"); + rpc.storePage(page); + } + } + + @Test + public void addAttachment() throws XmlRpcException + { + String attachmentName = String.format("test_attachment_%d.png", random.nextInt()); + byte[] data = (new String("This is a test").getBytes()); + Attachment attachment = new Attachment("Test.Attachments", attachmentName); + attachment = rpc.addAttachment(0, attachment, data); + + TestUtils.banner("TEST: addAttachment()"); + System.out.format("%s\n", attachment); + + assertEquals(attachmentName, attachment.getFileName()); + assertTrue(attachment.getFileSize() == data.length); + } + + @Test + public void getAttachments() throws XmlRpcException + { + List attachments = + rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS); + + TestUtils.banner("TEST: getAttachments()"); + for (Attachment attachment : attachments) { + System.out.format("%s\n", attachment); + } + + assertFalse(attachments.isEmpty()); + } + + @Test + public void getAttachmentData() throws XmlRpcException + { + List attachments = + rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS); + Attachment attachment = attachments.get(0); + + byte[] content = + rpc.getAttachmentData(attachment.getPageId(), attachment.getFileName(), "1.1"); + + TestUtils.banner("getAttachmentData()"); + System.out.format("%s\n", attachment); + System.out.format("Content = %s\n", Utils.truncateToFirstLine(new String(content, + 0, + content.length > 32 ? 32 : content.length))); + + int contentLength = new Integer(attachment.getFileSize()); + assertTrue(content.length == contentLength); + } + + @Test + public void removeAttachment() throws XmlRpcException + { + List attachments = + rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS); + Attachment attachmentToBeRemoved = attachments.get(random.nextInt(attachments.size())); + + TestUtils.banner("TEST: getAttachments()"); + System.out.format("Before: %s\n", attachments); + Boolean result = + rpc.removeAttachment(attachmentToBeRemoved.getPageId(), attachmentToBeRemoved + .getFileName()); + + System.out.format("Result: %b\n", result); + + attachments = rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS); + System.out.format("After: %s\n", attachments); + boolean found = false; + for (Attachment attachment : attachments) { + if (attachment.getFileName().equals(attachmentToBeRemoved.getFileName())) { + found = true; + break; + } + } + + assertFalse(found); + } +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/TestConstants.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/TestConstants.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/TestConstants.java (revision 0) @@ -0,0 +1,57 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +/** + * This class defines the constants that are used when performing the tests. In particular, the + * XWiki instance must have all the pages TEST_PAGE_* existing, and the TEST_PAGE_WITH_ATTACHMENTS + * with some attachments loaded into. + * + * @author fmancinelli + */ +public final class TestConstants +{ + public static final String USERNAME = "Admin"; + + public static final String PASSWORD = "admin"; + + public static final String ENDPOINT = "http://localhost:8080/xwiki/xmlrpc"; + + public static final String ENDPOINT_HANDLER = "confluence1"; + + public static final String SPACE_WITH_NO_ACCESS_RIGHTS = "Scheduler"; + + public static final String PAGE_WITH_NO_ACCESS_RIGHTS = "XWiki.Administration"; + + public static final String TEST_SPACE = "Test"; + + public static final String TEST_PREFIX = "TEST"; + + public static final String TEST_PAGE = "Test.Test"; + + public static final String TEST_PAGE_WITH_TRANSLATIONS = "Test.Translations"; + + public static final String TEST_PAGE_WITH_COMMENTS = "Test.Comments"; + + public static final String TEST_PAGE_WITH_ATTACHMENTS = "Test.Attachments"; + + public static final String TEST_PAGE_WITH_OBJECTS = "Test.Objects"; +} Index: distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/SpacesTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/SpacesTest.java (revision 0) +++ distribution-test/xmlrpc-tests/src/test/it/org/xwiki/xmlrpc/SpacesTest.java (revision 0) @@ -0,0 +1,148 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.xmlrpc; + +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.apache.xmlrpc.XmlRpcException; +import org.junit.Assert; +import org.junit.Test; +import org.xwiki.xmlrpc.model.Space; +import org.xwiki.xmlrpc.model.SpaceSummary; + +public class SpacesTest extends AbstractXWikiXmlRpcTest +{ + @Test + public void getSpaces() throws XmlRpcException + { + List spaces = rpc.getSpaces(); + + TestUtils.banner("TEST: getSpaces()"); + for (SpaceSummary spaceSummary : spaces) { + System.out.format("%s\n", spaceSummary); + } + + Assert.assertTrue(spaces.size() != 0); + } + + @Test + public void getSpace() throws XmlRpcException + { + List spaces = rpc.getSpaces(); + Space space = rpc.getSpace(spaces.get(0).getKey()); + + TestUtils.banner("TEST: getSpaceTest()"); + System.out.format("%s\n", space); + + Assert.assertEquals(space.getKey(), spaces.get(0).getKey()); + } + + @Test(expected = XmlRpcException.class) + public void getNonExistingSpace() throws XmlRpcException + { + Space space = rpc.getSpace("thisSpaceShouldNotExist"); + } + + @Test + public void addSpace() throws XmlRpcException + { + Space space = + new Space(String.format("%s-%d", TestConstants.TEST_PREFIX, Math + .abs(random.nextInt())), "TEST Space", "This is a new space"); + + space = rpc.addSpace(space); + + TestUtils.banner("TEST: addSpace()"); + System.out.format("%s\n", space); + + List spaces = rpc.getSpaces(); + boolean found = false; + for (SpaceSummary spaceSummary : spaces) { + if (spaceSummary.getKey().equals(space.getKey())) { + found = true; + break; + } + } + + Assert.assertTrue(found); + } + + @Test(expected = XmlRpcException.class) + public void addDuplicatedSpace() throws XmlRpcException + { + Space space = + new Space(String.format("%s-%d", TestConstants.TEST_PREFIX, Math + .abs(random.nextInt())), "TEST Space", "This is a new space"); + + space = rpc.addSpace(space); + space = rpc.addSpace(space); + } + + @Test(expected = XmlRpcException.class) + public void getSpaceWithoutRights() throws XmlRpcException + { + if (TestConstants.USERNAME.equals("Admin")) { + /* If the username is Admin this test will fail. Throw an exception to make it pass. */ + throw new XmlRpcException("User admin can always access everything"); + } + + Space space = rpc.getSpace(TestConstants.SPACE_WITH_NO_ACCESS_RIGHTS); + } + + @Test + public void removeSpace() throws XmlRpcException + { + List spaces = rpc.getSpaces(); + SpaceSummary spaceToBeRemoved = null; + for (SpaceSummary spaceSummary : spaces) { + if (spaceSummary.getKey().startsWith(TestConstants.TEST_PREFIX)) { + spaceToBeRemoved = spaceSummary; + break; + } + } + + Boolean result = rpc.removeSpace(spaceToBeRemoved); + + TestUtils.banner("TEST: removeSpace()"); + System.out.format("%s removed: %b\n", spaceToBeRemoved.getKey(), result); + + boolean found = false; + spaces = rpc.getSpaces(); + for (SpaceSummary spaceSummary : spaces) { + if (spaceSummary.getKey().equals(spaceToBeRemoved.getKey())) { + System.out.format("Page still existing: %s\n", spaceSummary); + found = true; + break; + } + } + + Assert.assertFalse(found); + } + + @Test(expected = XmlRpcException.class) + public void removeNonExistingSpace() throws XmlRpcException + { + Boolean result = rpc.removeSpace("thisSpaceShouldNotExist"); + assertTrue(result); + } +} Index: distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/PagesTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/PagesTest.java (revision 9203) +++ distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/PagesTest.java (working copy) @@ -1,233 +0,0 @@ -package com.xpn.xwiki.it.xmlrpc; - -import com.xpn.xwiki.it.xmlrpc.framework.AbstractXmlRpcTestCase; -import com.xpn.xwiki.xmlrpc.client.XWikiClientException; -import com.xpn.xwiki.xmlrpc.client.XWikiClientRemoteException; -import com.xpn.xwiki.xmlrpc.model.Page; -import com.xpn.xwiki.xmlrpc.model.PageHistorySummary; -import com.xpn.xwiki.xmlrpc.model.PageSummary; -import com.xpn.xwiki.xmlrpc.model.Space; -import com.xpn.xwiki.xmlrpc.model.swizzle.PageImpl; -import com.xpn.xwiki.xmlrpc.model.swizzle.SpaceImpl; - -import java.util.List; - - -public class PagesTest extends AbstractXmlRpcTestCase -{ - private String spaceKey; - - public void setUp() throws Exception { - super.setUp(); - - spaceKey = "ContainerSpace"; - Space space = new SpaceImpl(); - space.setKey(spaceKey); - space.setName("Some Name"); - - rpc.addSpace(space); - } - - public void tearDown() throws Exception { - rpc.removeSpace(spaceKey); - - super.tearDown(); - } - - public void testAddModifyRemovePage() throws Exception - { - String title = "SomeNewPage"; - String content = "Some Content"; - - // add the page - Page p = new PageImpl(); - p.setSpace(spaceKey); - p.setTitle(title); - p.setContent(content); - // no id in p means storePage will add - Page resultPage = rpc.storePage(p); - - String id = resultPage.getId(); - - assertEquals(title, resultPage.getTitle()); - assertEquals(spaceKey, resultPage.getSpace()); - assertEquals(content, resultPage.getContent()); - assertNotNull(id); - - // check that the page was added using getPages - List pages = rpc.getPages(spaceKey); - boolean found = false; - for (int i = 0; i < pages.size() && !found; i++) { - PageSummary summary = (PageSummary)pages.get(i); - if (summary.getTitle().equals(title)) { - found = true; - assertEquals(spaceKey, summary.getSpace()); - } - } - assertTrue("Adding page failed. There should be a page entitled \""+ title + "\" in this space", found); - - // also check that the page was added using getPage - Page page = rpc.getPage(id); - assertEquals(id, page.getId()); - assertEquals(title, page.getTitle()); - assertEquals(spaceKey, page.getSpace()); - assertEquals(content, page.getContent()); - - // modify the page - String newContent = "Some Other Content"; - resultPage.setContent(newContent); - Page modifiedPage = rpc.storePage(resultPage); - - // check that the page was modified - assertEquals(id, modifiedPage.getId()); - assertEquals(title, modifiedPage.getTitle()); - assertEquals(spaceKey, modifiedPage.getSpace()); - assertEquals(newContent, modifiedPage.getContent()); - assertTrue(resultPage.getVersion() < modifiedPage.getVersion()); - - // check again in a different way - modifiedPage = rpc.getPage(id); - assertEquals(id, modifiedPage.getId()); - assertEquals(title, modifiedPage.getTitle()); - assertEquals(spaceKey, modifiedPage.getSpace()); - assertEquals(newContent, modifiedPage.getContent()); - assertTrue(resultPage.getVersion() < modifiedPage.getVersion()); - - // check page history - List oldVersions = rpc.getPageHistory(id); - assertEquals(1, oldVersions.size()); - - PageHistorySummary phs0 = (PageHistorySummary)oldVersions.get(0); - assertEquals(resultPage.getVersion(), phs0.getVersion()); - assertNotNull(phs0.getModified()); - assertNotNull(phs0.getId()); - Page page0 = rpc.getPage(phs0.getId()); - assertEquals(page.getContent(), page0.getContent()); - assertEquals(page.getVersion(), page0.getVersion()); - - // search for the page -// List searchResults = rpc.search(title, 1); -// assertEquals(1, searchResults.size()); -// SearchResult searchResult = (SearchResult)searchResults.get(0); -// assertEquals(id, searchResult.getId()); -// assertNotNull(searchResult.getExcerpt()); -// assertEquals(title, searchResult.getTitle()); -// assertEquals("page", searchResult.getType()); -// assertNotNull(searchResult.getUrl()); - - // remove the page - rpc.removePage(id); - - // check that the page was really removed - pages = rpc.getPages(spaceKey); - found = false; - for (int i = 0; i < pages.size() && !found; i++) { - PageSummary summary = (PageSummary)pages.get(i); - assertFalse("Remove page failed. Page still present.", summary.getId().equals(id)); - } - } - - public void testGetPageHistory() throws Exception - { - String title = "SomeOtherPage"; - String content1 = "Content v1"; - - // add the page - Page p = new PageImpl(); - p.setSpace(spaceKey); - p.setTitle(title); - p.setContent(content1); - Page page1 = rpc.storePage(p); - - // modify the page - String content2 = "Content v2"; - p.setContent(content2); - p.setId(page1.getId()); - p.setVersion(page1.getVersion()); - Page page2 = rpc.storePage(p); - - // modify the page again - String content3 = "Content v3"; - p.setContent(content3); - p.setId(page2.getId()); - p.setVersion(page2.getVersion()); - Page page3 = rpc.storePage(p); - - // get page history - List historyObjs = rpc.getPageHistory(page3.getId()); - assertEquals(2, historyObjs.size()); - PageHistorySummary phs1 = (PageHistorySummary)historyObjs.get(1); - assertEquals(page1.getVersion(), phs1.getVersion()); - Page p1 = rpc.getPage(phs1.getId()); - assertEquals(page1.getVersion(), p1.getVersion()); - assertEquals(page1.getContent(), p1.getContent()); - assertEquals(page1.getCreated(), p1.getCreated()); - assertEquals(page1.getCreator(), p1.getCreator()); - assertEquals(page1.getModified(), p1.getModified()); - assertEquals(page1.getModifier(), p1.getModifier()); - assertEquals(page1.getParentId(), p1.getParentId()); - assertEquals(page1.getSpace(), p1.getSpace()); - assertEquals(page1.getTitle(), p1.getTitle()); - assertFalse(page1.getUrl().equals(p1.getUrl())); - - PageHistorySummary phs2 = (PageHistorySummary)historyObjs.get(0); - assertEquals(page2.getVersion(), phs2.getVersion()); - Page p2 = rpc.getPage(phs2.getId()); - assertEquals(page2.getVersion(), p2.getVersion()); - assertEquals(page2.getContent(), p2.getContent()); - assertEquals(page2.getCreated(), p2.getCreated()); - assertEquals(page2.getCreator(), p2.getCreator()); - assertEquals(page2.getModified(), p2.getModified()); - assertEquals(page2.getModifier(), p2.getModifier()); - assertEquals(page2.getParentId(), p2.getParentId()); - assertEquals(page2.getSpace(), p2.getSpace()); - assertEquals(page2.getTitle(), p2.getTitle()); - assertFalse(page2.getUrl().equals(p2.getUrl())); - - // get history of page from history - // confluence does not allow this - // ("This is not the most recent version of this page") - historyObjs = rpc.getPageHistory(p2.getId()); - assertEquals(1, historyObjs.size()); - phs1 = (PageHistorySummary)historyObjs.get(0); - assertEquals(page1.getVersion(), phs1.getVersion()); - p1 = rpc.getPage(phs1.getId()); - assertEquals(page1.getVersion(), p1.getVersion()); - assertEquals(page1.getContent(), p1.getContent()); - assertEquals(page1.getCreated(), p1.getCreated()); - assertEquals(page1.getCreator(), p1.getCreator()); - assertEquals(page1.getModified(), p1.getModified()); - assertEquals(page1.getModifier(), p1.getModifier()); - assertEquals(page1.getParentId(), p1.getParentId()); - assertEquals(page1.getSpace(), p1.getSpace()); - assertEquals(page1.getTitle(), p1.getTitle()); - - p2.setContent("New content"); - try { - rpc.storePage(p2); - fail("You should only be able to edit the latest version of a page"); - } catch (XWikiClientException ce) { - // ok, continue - } - try { - rpc.removePage(p2.getId()); - fail("You should not be able to remove an old version of a page"); - } catch (XWikiClientException ce) { - // ok, continue - } - } - - /** - * Verify that pageId must be of the form Space.Page when the xmlrpc server is XWiki. - */ - public void testRenderContentWithInvalidPageId() - { - try { - rpc.renderContent("unused", "InvalidPageId", "Dummy content"); - fail("Should have received an exception here since the page id format is invalid"); - } catch (Exception expected) { - assertTrue(expected.getMessage().contains("The page format for [InvalidPageId] is invalid. A page id " - + "must be of the form Space.Page")); - } - } -} Index: distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java (revision 9203) +++ distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/XhtmlValidityTest.java (working copy) @@ -1,324 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package com.xpn.xwiki.it.xmlrpc; - -import com.xpn.xwiki.plugin.packaging.Package; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.commons.codec.binary.Base64; -import org.codehaus.swizzle.confluence.Confluence; -import org.codehaus.swizzle.confluence.Page; -import org.dom4j.Document; -import org.dom4j.Element; -import org.dom4j.io.SAXReader; -import org.w3c.css.css.DocumentParser; -import org.w3c.css.css.StyleReport; -import org.w3c.css.css.StyleReportFactory; -import org.w3c.css.css.StyleSheet; -import org.w3c.css.util.ApplContext; -import org.w3c.css.util.HTTPURL; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -import javax.xml.XMLConstants; -import javax.xml.transform.Source; -import javax.xml.transform.sax.SAXSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; -import javax.xml.validation.Validator; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -/** - * Verifies that all pages in the default wiki are valid XHTML documents using the Confluence XMLRPC - * API. - * - * @version $Id: $ - */ -public class XhtmlValidityTest extends TestCase implements ErrorHandler -{ - private String fullPageName; - - private static Validator xv; - - // private static Validator rv; - - private Confluence rpc; - - private int errors = 0; - - /** - * We save the stdout stream since we replace it with our own in order to verify that XWiki - * doesn't generated any error while validating documents and we fail the build if it does. - */ - private PrintStream stdout; - - /** - * The new stdout stream we're using to replace the default console output. - */ - private ByteArrayOutputStream out; - - /** - * We save the stderr stream since we replace it with our own in order to verify that XWiki - * doesn't generated any error while validating documents and we fail the build if it does. - */ - private PrintStream stderr; - - /** - * The new stderr stream we're using to replace the default console output. - */ - private ByteArrayOutputStream err; - - public XhtmlValidityTest(String fullPageName) - { - super("testValidityOfDocument"); - - this.fullPageName = fullPageName; - } - - public static Test suite() throws Exception - { - TestSuite suite = new TestSuite(); - - String path = - System.getProperty("localRepository") + "/" + System.getProperty("pathToXWikiXar"); - - String patternFilter = System.getProperty("documentsToTest"); - - List pageNames = readXarContents(path, patternFilter); - Iterator it = pageNames.iterator(); - while (it.hasNext()) { - suite.addTest(new XhtmlValidityTest((String) it.next())); - } - - // Prepare validators only once, as this is a costly process - System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema", - "org.apache.xerces.jaxp.validation.XMLSchemaFactory"); - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema xhtmlSchema = sf.newSchema( - XhtmlValidityTest.class.getClassLoader().getResource("xhtml1-strict.xsd")); - // Schema rssSchema = sf.newSchema(new File("rdf.xsd")); - xv = xhtmlSchema.newValidator(); - // rv = rssSchema.newValidator(); - // rv.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", - // "http://purl.org/dc/elements/1.1/ dc.xsd http://www.w3.org/1999/xhtml xhtml1-strict.xsd - // http://purl.org/rss/1.0/ rss.rdf"); - - return suite; - } - - public String getName() - { - return "Validating " + fullPageName; - } - - protected void setUp() throws Exception - { - super.setUp(); - - rpc = new Confluence("http://127.0.0.1:8080/xwiki/xmlrpc"); - rpc.login("Admin", "admin"); - - // TODO Until we find a way to incrementally display the result of tests this stays - System.out.println(getName()); - - // We redirect the stdout and the stderr in order to detect (server-side) error/warning - // messages like the ones generated by the velocity parser - this.stdout = System.out; - this.out = new ByteArrayOutputStream(); - System.setOut(new PrintStream(this.out)); - this.stderr = System.err; - this.err = new ByteArrayOutputStream(); - System.setErr(new PrintStream(this.err)); - } - - protected void tearDown() throws Exception - { - // Restore original stdout and stderr streams. - String output = this.out.toString(); - String errput = this.err.toString(); - - System.setOut(this.stdout); - System.out.print(output); - System.setErr(this.stderr); - System.err.print(errput); - - // Detect server-side error/warning messages from the stdout - assertFalse("Errors found in the stdout output", hasErrors(output)); - assertFalse("Warnings found in the stdout output", hasWarnings(output)); - - // Detect server-side error/warning messages from the stderr - assertFalse("Errors found in the stderr output", hasErrors(errput)); - assertFalse("Warnings found in the stderr output", hasWarnings(errput)); - - rpc.logout(); - - super.tearDown(); - } - - public void testValidityOfDocument() throws Exception - { - Page page = rpc.getPage(fullPageName); - String renderedContent = rpc.renderContent(page); - assertNotNull(renderedContent); - - if (renderedContent.indexOf("= 0 || output.indexOf("ERR") >= 0; - } - - private boolean hasWarnings(String output) - { - return output.indexOf("WARNING") >= 0 || output.indexOf("WARN") >= 0; - } - - public static List readXarContents(String fileName, String patternFilter) throws Exception - { - FileInputStream fileIS = new FileInputStream(fileName); - ZipInputStream zipIS = new ZipInputStream(fileIS); - - ZipEntry entry; - Document tocDoc = null; - while ((entry = zipIS.getNextEntry()) != null) { - if (entry.getName().compareTo(Package.DefaultPackageFileName) == 0) { - SAXReader reader = new SAXReader(); - tocDoc = reader.read(zipIS); - break; - } - } - - if (tocDoc == null) { - return new ArrayList(); - } - - List result = new ArrayList(); - - Element filesElement = tocDoc.getRootElement().element("files"); - List fileElementList = filesElement.elements("file"); - Iterator it = fileElementList.iterator(); - while (it.hasNext()) { - Element el = (Element) it.next(); - String docFullName = el.getStringValue(); - - if (patternFilter == null || docFullName.matches(patternFilter)) { - result.add(docFullName); - } - } - - return result; - } - - private static String completeXhtml(String title, String content) - { - return "\n" - + "\n" - + "\n" + "" + title + "\n" + "\n" + "\n
\n" - + content.replaceAll(" ", " ") + "\n
\n\n"; - } - - private static int assertCssValid(String url) throws Exception - { - ApplContext ac = new ApplContext("en"); - ac.setProfile("css21"); - ac.setCssVersion("css21"); - ac.setMedium("all"); - ac.setCredential("Basic " + new String(Base64.encodeBase64("Admin:admin".getBytes()))); - String output = "text"; - int warningLevel = 2; - - String encoding = ac.getMsg().getString("output-encoding-name"); - PrintWriter out; - if (encoding != null) { - out = new PrintWriter(new OutputStreamWriter(System.out, encoding)); - } else { - out = new PrintWriter(new OutputStreamWriter(System.out)); - } - String uri = HTTPURL.getURL(url).toString(); - DocumentParser URLparser = new DocumentParser(ac, uri); - - StyleSheet styleSheet = URLparser.getStyleSheet(); - if (styleSheet == null) { - throw new IOException(ac.getMsg().getServletString("process") + " " + uri); - } - - styleSheet.findConflicts(ac); // this is bogus ? - - StyleReport style = - StyleReportFactory.getStyleReport(ac, uri, styleSheet, output, warningLevel); - - int errors = styleSheet.getErrors().getErrorCount(); - if (errors > 0) { - style.print(out); - } - return errors; - } - - public void error(SAXParseException exception) throws SAXException - { - this.errors++; - System.out.println(exception.getMessage()); - } - - public void fatalError(SAXParseException exception) throws SAXException - { - this.errors++; - System.out.println(exception.getMessage()); - exception.printStackTrace(); - } - - public void warning(SAXParseException exception) throws SAXException - { - System.out.println(exception.getMessage()); - } -} Index: distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/CommentsTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/CommentsTest.java (revision 9203) +++ distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/CommentsTest.java (working copy) @@ -1,106 +0,0 @@ -package com.xpn.xwiki.it.xmlrpc; - -import com.xpn.xwiki.it.xmlrpc.framework.AbstractXmlRpcTestCase; -import com.xpn.xwiki.xmlrpc.model.Comment; -import com.xpn.xwiki.xmlrpc.model.Page; -import com.xpn.xwiki.xmlrpc.model.Space; -import com.xpn.xwiki.xmlrpc.model.swizzle.CommentImpl; -import com.xpn.xwiki.xmlrpc.model.swizzle.PageImpl; -import com.xpn.xwiki.xmlrpc.model.swizzle.SpaceImpl; - - -public class CommentsTest extends AbstractXmlRpcTestCase -{ - private String spaceKey; - - private String pageTitle; - - private String pageId; - - public void setUp() throws Exception { - super.setUp(); - - spaceKey = "SomeContainerSpace"; - Space space = new SpaceImpl(); - space.setKey(spaceKey); - space.setName("Some Name"); - - rpc.addSpace(space); - - pageTitle = "SomeContainerPage"; - Page p = new PageImpl(); - p.setSpace(spaceKey); - p.setTitle(pageTitle); - p.setContent(""); - // no id in pageProperties means storePage will add - Page resultPage = rpc.storePage(p); - pageId = resultPage.getId(); - - // add and remove one comment (makes test more realistic) - Comment comment = new CommentImpl(); - comment.setPageId(pageId); - comment.setContent("Dummy Comment"); - Comment commentResult = rpc.addComment(comment); - rpc.removeComment(commentResult.getId()); - } - - public void tearDown() throws Exception { - rpc.removePage(pageId); - rpc.removeSpace(spaceKey); - - super.tearDown(); - } - - public void testAddGetComments() throws Exception - { - // first check that the page has no comments - assertEquals(0, rpc.getComments(pageId).size()); - - // then add some comments - Comment comment = new CommentImpl(); - comment.setPageId(pageId); - comment.setContent("Comment1"); - Comment c1 = rpc.addComment(comment); - assertNotNull(c1.getId()); - assertEquals(pageId, c1.getPageId()); - assertEquals("Comment1", c1.getContent()); - assertNotNull(c1.getUrl()); - comment.setContent("Comment2"); - Comment c2 = rpc.addComment(comment); - assertNotNull(c2.getId()); - assertEquals(pageId, c2.getPageId()); - assertEquals("Comment2", c2.getContent()); - assertNotNull(c2.getUrl()); - - // check that the page has the comments - assertEquals(2, rpc.getComments(pageId).size()); - Comment c11 = rpc.getComment(c1.getId()); - assertEquals(c1.getId(), c11.getId()); - assertEquals(c1.getTitle(), c11.getTitle()); - assertEquals(c1.getPageId(), c11.getPageId()); - assertEquals(c1.getContent(), c11.getContent()); - assertEquals(c1.getCreated(), c11.getCreated()); - assertEquals(c1.getCreator(), c11.getCreator()); - assertEquals(c1.getUrl(), c11.getUrl()); - Comment c22 = rpc.getComment(c2.getId()); - assertEquals(c2.getId(), c22.getId()); - assertEquals(c2.getTitle(), c22.getTitle()); - assertEquals(c2.getPageId(), c22.getPageId()); - assertEquals(c2.getContent(), c22.getContent()); - assertEquals(c2.getCreated(), c22.getCreated()); - assertEquals(c2.getCreator(), c22.getCreator()); - assertEquals(c2.getUrl(), c22.getUrl()); - - // delete 1st comment - assertTrue(rpc.removeComment(c1.getId())); - // check that 1st comment is still there - assertEquals(1, rpc.getComments(pageId).size()); - assertNotNull(c2.getId()); - assertEquals(pageId, c2.getPageId()); - assertEquals("Comment2", c2.getContent()); - assertNotNull(c2.getUrl()); - // delete 2nd comment - assertTrue(rpc.removeComment(c2.getId())); - assertEquals(0, rpc.getComments(pageId).size()); - } -} Index: distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AnonymousAccessTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AnonymousAccessTest.java (revision 9203) +++ distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AnonymousAccessTest.java (working copy) @@ -1,55 +0,0 @@ -package com.xpn.xwiki.it.xmlrpc; - -import java.util.List; - -import com.xpn.xwiki.xmlrpc.client.XWikiClient; -import com.xpn.xwiki.xmlrpc.client.SwizzleXWikiClient; -import com.xpn.xwiki.xmlrpc.client.XWikiClientException; -import com.xpn.xwiki.xmlrpc.model.PageSummary; -import com.xpn.xwiki.xmlrpc.model.SpaceSummary; - -import junit.framework.TestCase; - -public class AnonymousAccessTest extends TestCase -{ - private XWikiClient rpc; // xml-rpc proxy - - public void setUp() throws Exception - { - super.setUp(); - - // no login = anonymous access - rpc = new SwizzleXWikiClient("http://127.0.0.1:8080/xwiki/xmlrpc"); - } - - public void testReadSomePagesWhenNotLoggedIn() throws Exception - { - List spaces = rpc.getSpaces(); - for (int i = 0; i < spaces.size(); i++) { - SpaceSummary spaceSummary = (SpaceSummary)spaces.get(i); - String key = spaceSummary.getKey(); - - // Only read pages from the Main space in this test since we're sure Guest users - // are allowed to read them. - if (key.equals("Main")) { - List pages = rpc.getPages(key); - for (int j = 0; j < pages.size(); j++) { - PageSummary pageSummary = (PageSummary)pages.get(j); - String id = pageSummary.getId(); - rpc.getPage(id); - } - } - } - } - - public void testReadUnauthorizedPage() throws Exception - { - try { - rpc.getPage("Scheduler.WebHome"); - fail("Should have thrown an exception here"); - } catch (XWikiClientException expected) { - assertTrue(expected.getMessage().contains( - "Access to document Scheduler.WebHome has been denied to user XWiki.XWikiGuest")); - } - } -} Index: distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AllTests.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AllTests.java (revision 9203) +++ distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AllTests.java (working copy) @@ -1,73 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package com.xpn.xwiki.it.xmlrpc; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import com.xpn.xwiki.test.XWikiTestSetup; - -/** - * A class listing all the XMLRPC Functional tests to execute. We need such a class (rather than - * letting the JUnit Runner discover the different TestCases classes by itself) because we want to - * start/stop XWiki before and after the tests start (but only once). - * - * @version $Id: $ - */ -public class AllTests extends TestCase -{ - private static final String PATTERN = ".*" + System.getProperty("pattern", ""); - - public static Test suite() throws Exception - { - TestSuite suite = new TestSuite(); - - // TODO: I don't like listing tests here as it means we can add a new TestCase class and - // forget to add it here and the tests won't be run but we'll not know about it and we'll - // think the tests are all running fine. I haven't found a simple solution to this yet - // (there are complex solutions like searching for all tests by parsing the source tree). - // I think there are TestSuite that do this out there but I haven't looked for them yet. - - addTestCase(suite, AnonymousAccessTest.class); - addTestCase(suite, SpacesTest.class); - addTestCase(suite, PagesTest.class); - addTestCase(suite, CommentsTest.class); - addTestCase(suite, AttachmentsTest.class); - addTest(suite, XhtmlValidityTest.suite(), XhtmlValidityTest.class); - addTest(suite, OrphanedPageTest.suite(), OrphanedPageTest.class); - - return new XWikiTestSetup(suite); - } - - private static void addTestCase(TestSuite suite, Class testClass) throws Exception - { - if (testClass.getName().matches(PATTERN)) { - suite.addTest(new TestSuite(testClass)); - } - } - - private static void addTest(TestSuite suite, Test test, Class testClass) throws Exception - { - if (testClass.getName().matches(PATTERN)) { - suite.addTest(test); - } - } -} Index: distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AttachmentsTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AttachmentsTest.java (revision 9203) +++ distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/AttachmentsTest.java (working copy) @@ -1,160 +0,0 @@ -package com.xpn.xwiki.it.xmlrpc; - -import java.util.List; - -import com.xpn.xwiki.it.xmlrpc.framework.AbstractXmlRpcTestCase; -import com.xpn.xwiki.xmlrpc.model.Attachment; -import com.xpn.xwiki.xmlrpc.model.Page; -import com.xpn.xwiki.xmlrpc.model.Space; -import com.xpn.xwiki.xmlrpc.model.swizzle.AttachmentImpl; -import com.xpn.xwiki.xmlrpc.model.swizzle.PageImpl; -import com.xpn.xwiki.xmlrpc.model.swizzle.SpaceImpl; - -public class AttachmentsTest extends AbstractXmlRpcTestCase -{ - private String pageId; - - private String spaceKey; - - public void setUp() throws Exception - { - super.setUp(); - - spaceKey = "SomeSpaceReally"; - Space space = new SpaceImpl(); - space.setKey(spaceKey); - space.setName("Some Name"); - - rpc.addSpace(space); - - String pageTitle = "SomePage"; - Page p = new PageImpl(); - p.setSpace(spaceKey); - p.setTitle(pageTitle); - p.setContent("Dummy Comment"); - Page resultPage = rpc.storePage(p); - pageId = resultPage.getId(); - } - - public void tearDown() throws Exception - { - rpc.removePage(pageId); - rpc.removeSpace(spaceKey); - - super.tearDown(); - } - - public void testAttachments() throws Exception - { - // Add attachment - Attachment attach0 = new AttachmentImpl(); - String fileName = "test.txt"; - String contentType = "text/plain"; - attach0.setFileName(fileName); - attach0.setPageId(pageId); - attach0.setContentType(contentType); - byte[] data0 = new byte[4]; - data0[0] = 't'; data0[1] = 'e'; data0[2] = 's'; data0[3] = 't'; - Attachment attach00 = rpc.addAttachment(pageId, attach0, data0); - assertEquals(pageId, attach00.getPageId()); - assertEquals(fileName, attach00.getFileName()); - assertEquals(fileName, attach00.getTitle()); - assertEquals(data0.length, attach00.getFileSize()); - assertEquals(contentType, attach00.getContentType()); - - // Get attachment versions - List versions = rpc.getAttachmentVersions(pageId, fileName); - - // Get attachment - Attachment attach000 = rpc.getAttachment(pageId, fileName, (String)versions.get(0)); - assertEquals(attach00.getId(), attach000.getId()); - assertEquals(attach00.getPageId(), attach000.getPageId()); - assertEquals(attach00.getTitle(), attach000.getTitle()); - assertEquals(attach00.getFileName(), attach000.getFileName()); - assertEquals(attach00.getFileSize(), attach000.getFileSize()); - assertEquals(attach00.getContentType(), attach000.getContentType()); - assertEquals(attach00.getCreated(), attach000.getCreated()); - assertEquals(attach00.getCreator(), attach000.getCreator()); - assertEquals(attach00.getUrl(), attach000.getUrl()); - assertEquals(attach00.getComment(), attach000.getComment()); - - // Get attachment data - byte[] data00 = rpc.getAttachmentData(pageId, fileName, (String)versions.get(0)); - assertEquals(data0.length, data00.length); - for (int i = 0; i 0); - } -} Index: distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/SpacesTest.java =================================================================== --- distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/SpacesTest.java (revision 9203) +++ distribution-test/xmlrpc-tests/src/test/it/com/xpn/xwiki/it/xmlrpc/SpacesTest.java (working copy) @@ -1,37 +0,0 @@ -package com.xpn.xwiki.it.xmlrpc; - -import java.util.List; -import java.util.Random; - -import com.xpn.xwiki.it.xmlrpc.framework.AbstractXmlRpcTestCase; -import com.xpn.xwiki.xmlrpc.model.Space; -import com.xpn.xwiki.xmlrpc.model.SpaceSummary; -import com.xpn.xwiki.xmlrpc.model.swizzle.SpaceImpl; - -public class SpacesTest extends AbstractXmlRpcTestCase -{ - public void testAddRemoveSpace() throws Exception - { - String spaceKey = "TestSpace" + (new Random()).nextInt(10000); - Space space = new SpaceImpl(); - space.setKey(spaceKey); - space.setName("Some Name"); - rpc.addSpace(space); - - Space spaceSummary = rpc.getSpace(spaceKey); - - assertEquals(spaceKey, spaceSummary.getKey()); - - rpc.removeSpace(spaceKey); - - List spaces = rpc.getSpaces(); - boolean found = false; - for (int i = 0; i < spaces.size() && !found; i++) { - SpaceSummary summary = (SpaceSummary)spaces.get(i); - if (summary.getKey().equals(spaceKey)) { - found = true; - } - } - assertFalse("Remove space failed (" + spaceKey + " still present)", found); - } -} Index: distribution-test/xmlrpc-tests/pom.xml =================================================================== --- distribution-test/xmlrpc-tests/pom.xml (revision 9203) +++ distribution-test/xmlrpc-tests/pom.xml (working copy) @@ -41,29 +41,16 @@ test - xmlunit - xmlunit - 1.1 - test + org.xwiki.platform + xwiki-xmlrpc-client + ${platform.core.version} - xerces - xercesImpl - 2.8.1 + junit + junit + 4.0 test - - - xmlrpc - xmlrpc-client - 3.0 - test - - - org.w3c.css - css-validator - 2.1-20070528 - test - +