cl = cmnts.comments;
+ assertEquals(2, cl.size());
+ int replyto = cl.get(1).replyTo;
+ assertEquals(0, replyto);
+ }
+ } catch (RestException e) {
+ throw new AssertionFailedError("xmlrpc exception code=" + e.getCode());
+ }
+ }
+
+// public void testCreate06WithAttachment() throws Throwable
+// {
+//
+// Attachment a=new Attachment(attachmentName, af1);
+// doc.addAttachment(a);
+// rao.create(doc);
+// assertNotNull(api.getPageAttachment(wikiName, spaceName, pageName, attachmentName));
+//
+//
+//
+// }
+}
diff --git a/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoDelete.java b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoDelete.java
new file mode 100644
index 0000000..a4b26f7
--- /dev/null
+++ b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoDelete.java
@@ -0,0 +1,78 @@
+//package org.xwiki.android.rest.ral.test;
+//
+//import org.xwiki.android.core.test.properties.Env;
+//import org.xwiki.android.rest.RestConnectionException;
+//import org.xwiki.android.rest.XWikiAPI;
+//import org.xwiki.android.rest.ral.DocumentRao;
+//import org.xwiki.android.rest.ral.RESTfulManager;
+//import org.xwiki.android.rest.ral.RaoException;
+//import org.xwiki.android.rest.ral.XmlRESTFulManager;
+//import org.xwiki.android.svc.cmn.LoginFacade;
+//import org.xwiki.android.xmodel.entity.Document;
+//
+//import android.test.AndroidTestCase;
+//import android.util.Log;
+//
+//public class TestDocumentRaoDelete extends AndroidTestCase
+//{
+//
+// private static final String TAG = TestDocumentRaoDelete.class.getSimpleName();
+// int count;
+//
+// // test org.xwiki.android.test.fixture.teardown.env parameters.
+// String serverUrl, username, password, wikiName, spaceName, pageName;
+//
+// // tested apis
+// RESTfulManager rm;
+// DocumentRao rao;
+// Document doc;
+//
+// // api used for output verification
+// XWikiAPI api;
+//
+//
+// public TestDocumentRaoDelete()
+// {
+// // things that need to run only one time. workaround for @BeforeClass
+// // obtain vars from Var class
+// username = Env.USERNAME;
+// password = Env.PASSWORD;
+// serverUrl = Env.URL;
+//
+// wikiName = Env.WIKI_NAME;
+// spaceName = Env.SPACE_NAME;
+// pageName = Env.PAGE_NAME;
+// count=0;
+// }
+//
+//
+//
+// @Override
+// protected void setUp() throws Exception
+// {
+// super.setUp();
+// rm = new XmlRESTFulManager(serverUrl, username, password);
+// api = rm.getConnection().getBaseAPI();
+// rao = rm.newDocumentRao();
+// doc = new Document(wikiName, spaceName, pageName);
+// doc.setTitle(pageName);
+// }
+//
+// @Override
+// protected void tearDown() throws Exception
+// {
+// super.tearDown();
+// count++;
+// }
+//
+// public void testYourThing1() throws Throwable
+// {
+// assertTrue(true);
+// }
+//
+// public void testYourThing2() throws Throwable
+// {
+// assertTrue(true);
+// }
+//
+//}
diff --git a/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoRetreive.java b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoRetreive.java
new file mode 100644
index 0000000..f8e9fcb
--- /dev/null
+++ b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoRetreive.java
@@ -0,0 +1,102 @@
+//package org.xwiki.android.rest.ral.test;
+//
+//import org.xwiki.android.core.test.properties.Env;
+//import org.xwiki.android.resources.Object;
+//import org.xwiki.android.resources.Property;
+//import org.xwiki.android.rest.RestConnectionException;
+//import org.xwiki.android.rest.XWikiAPI;
+//import org.xwiki.android.rest.ral.DocumentRao;
+//import org.xwiki.android.rest.ral.RESTfulManager;
+//import org.xwiki.android.rest.ral.RaoException;
+//import org.xwiki.android.rest.ral.XmlRESTFulManager;
+//import org.xwiki.android.svc.cmn.LoginFacade;
+//import org.xwiki.android.xmodel.blog.XBlogPost;
+//import org.xwiki.android.xmodel.entity.Document;
+//
+//import android.test.AndroidTestCase;
+//import android.util.Log;
+//
+//public class TestDocumentRaoRetreive extends AndroidTestCase
+//{
+//
+// private static final String TAG = TestDocumentRaoRetreive.class.getSimpleName();
+// // test org.xwiki.android.test.fixture.teardown.env parameters.
+// String serverUrl, username, password, wikiName, spaceName, pageName,objectClassname,propertyName;
+// int objectNumber;
+//
+// // tested apis
+// RESTfulManager rm;
+// DocumentRao rao;
+// Document doc;
+//
+// // api used for output verification
+// XWikiAPI api;
+//
+// static int count=0;
+//
+// public TestDocumentRaoRetreive()
+// {
+// super();
+// username = Env.USERNAME;
+// password = Env.PASSWORD;
+// serverUrl = Env.URL;
+//
+// wikiName = Env.WIKI_NAME;
+// spaceName = Env.SPACE_NAME;
+// pageName = Env.PAGE_NAME;
+// objectClassname=Env.CLASS_NAME;
+// objectNumber=Env.OBJECT_NUMBER;
+// propertyName=Env.OBJECT_PROPERTY_NAME;
+// count=0;
+// }
+//
+//
+//
+// @Override
+// protected void setUp() throws Exception
+// {
+// super.setUp();
+// rm = new XmlRESTFulManager(serverUrl, username, password);
+// api = rm.getConnection().getBaseAPI();
+// rao = rm.newDocumentRao();
+// doc = new Document(wikiName, spaceName, pageName);
+// doc.setTitle(pageName);
+// //check precondition
+// if(count==0){
+// boolean pre=api.existsPage(wikiName, spaceName, pageName);
+// if(!pre){
+// Log.e(TAG, "preconditions failed. Please create a page to retreive. refer Env class");
+// }
+// pre=api.existsObject(wikiName, spaceName, pageName, objectClassname, objectNumber);
+// if(!pre){
+// Log.e(TAG, "preconditions failed. Please create a Object (blogPost) to retreive. refer Env class");
+// }
+//
+// Property p=api.getObjectProperty(wikiName, spaceName, pageName, objectClassname, objectNumber+"", propertyName);
+// assertNotNull(p);
+// assertTrue(pre);
+// }
+// }
+//
+// @Override
+// protected void tearDown() throws Exception
+// {
+// super.tearDown();
+// }
+//
+// public void testRetreive() throws Throwable
+// {
+// boolean success;
+// try {
+// Document docRet=rao.retreive(doc);
+// assertNotNull(docRet);
+// XBlogPost blgPost=(XBlogPost) docRet.getObject(objectClassname+"/"+objectNumber);
+// assertNotNull(blgPost);
+// assertNotNull(blgPost.getContent());
+// }catch (RaoException e) {
+// success=false;
+// }
+//
+// }
+//
+//}
diff --git a/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoUpdate.java b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoUpdate.java
new file mode 100644
index 0000000..a0cfb7d
--- /dev/null
+++ b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoUpdate.java
@@ -0,0 +1,99 @@
+//package org.xwiki.android.rest.ral.test;
+//
+//import org.xwiki.android.core.test.properties.Env;
+//import org.xwiki.android.rest.RestConnectionException;
+//import org.xwiki.android.rest.XWikiAPI;
+//import org.xwiki.android.rest.ral.DocumentRao;
+//import org.xwiki.android.rest.ral.RESTfulManager;
+//import org.xwiki.android.rest.ral.RaoException;
+//import org.xwiki.android.rest.ral.XmlRESTFulManager;
+//import org.xwiki.android.svc.cmn.LoginFacade;
+//import org.xwiki.android.xmodel.blog.XBlogPost;
+//import org.xwiki.android.xmodel.entity.Comment;
+//import org.xwiki.android.xmodel.entity.Document;
+//
+//import android.test.AndroidTestCase;
+//import android.util.Log;
+//
+//public class TestDocumentRaoUpdate extends AndroidTestCase
+//{
+//
+// private static final String TAG = TestDocumentRaoUpdate.class.getSimpleName();
+// // test org.xwiki.android.test.fixture.teardown.env parameters.
+// String serverUrl, username, password, wikiName, spaceName, pageName;
+//
+// int count;
+//
+// // tested apis
+// RESTfulManager rm;
+// DocumentRao rao;
+// Document doc;
+//
+// // api used for output verification
+// XWikiAPI api;
+//
+// public TestDocumentRaoUpdate()
+// {
+// // things that need to run only one time. workaround for @BeforeClass
+// // obtain vars from Var class
+// username = Env.USERNAME;
+// password = Env.PASSWORD;
+// serverUrl = Env.URL;
+//
+// wikiName = Env.WIKI_NAME;
+// spaceName = Env.SPACE_NAME;
+// pageName = Env.PAGE_NAME;
+// count = 0;
+// }
+//
+// @Override
+// protected void setUp() throws Exception
+// {
+// super.setUp();
+// rm = new XmlRESTFulManager(serverUrl, username, password);
+// api = rm.getConnection().getBaseAPI();
+// rao = rm.newDocumentRao();
+// doc = new Document(wikiName, spaceName, pageName);
+// doc.setTitle(pageName);
+// }
+//
+// @Override
+// protected void tearDown() throws Exception
+// {
+// super.tearDown();
+// count++;
+// }
+//
+// public void testUpdate1() throws Throwable
+// {
+// boolean success = false;
+//
+// XBlogPost xb = new XBlogPost();
+// xb.setContent("edited");
+// xb.setNumber(0);
+// doc.setObject(xb);
+//
+// try {
+// rao.update(doc);
+// } catch (RaoException e) {
+// success = false;
+// }
+// assertTrue(success);
+//
+// }
+//
+// public void testUpdate2() throws Throwable
+// {
+// boolean success = false;
+//
+// Comment cmnt = new Comment("hi comment");
+// doc.addComment(cmnt);
+// try {
+// rao.update(doc);
+// } catch (RaoException e) {
+// success = false;
+// }
+// assertTrue(success);
+// }
+//
+//}
diff --git a/xwiki-android-test-fixture-setup/pom.xml b/xwiki-android-test-fixture-setup/pom.xml
new file mode 100644
index 0000000..878b1f9
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/pom.xml
@@ -0,0 +1,127 @@
+
+
+
+
+
+ 4.0.0
+
+ org.xwiki.android
+ xwiki-android
+ 1.0-SNAPSHOT
+
+
+ org.xwiki.android
+ xwiki-android-test-fixture-setup
+ ${parent.version}
+ XWiki Server Startup and external fixture setup
+
+
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.6.6
+
+
+
+ org.apache.ant
+ ant
+ 1.7.0
+
+
+
+ commons-httpclient
+ commons-httpclient
+ 3.1
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.1.2
+
+
+
+ org.apache.httpcomponents
+ httpcore
+ 4.1.2
+
+
+
+
+ commons-configuration
+ commons-configuration
+ 1.8
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.0
+
+
+
+ junit
+ junit
+ 4.10
+
+
+
+ org.xwiki.android
+ xwiki-rest-model-simplexml
+ 1.0-SNAPSHOT
+
+
+
+
+
+ test
+
+
+ resources
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ **/*AllTests.java
+
+
+ **/*Test.java
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+
+
+
+
diff --git a/xwiki-android-test-fixture-setup/resources/a.png b/xwiki-android-test-fixture-setup/resources/a.png
new file mode 100644
index 0000000..fad651f
Binary files /dev/null and b/xwiki-android-test-fixture-setup/resources/a.png differ
diff --git a/xwiki-android-test-fixture-setup/resources/del.png b/xwiki-android-test-fixture-setup/resources/del.png
new file mode 100644
index 0000000..a63fb68
Binary files /dev/null and b/xwiki-android-test-fixture-setup/resources/del.png differ
diff --git a/xwiki-android-test-fixture-setup/resources/log4j.properties b/xwiki-android-test-fixture-setup/resources/log4j.properties
new file mode 100644
index 0000000..b5851ee
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/resources/log4j.properties
@@ -0,0 +1,7 @@
+#log4j.rootLogger=DEBUG, CA
+#log4j.logger.org.apache.http= ERROR
+
+#log4j.appender.CA=org.apache.log4j.ConsoleAppender
+
+#log4j.appender.CA.layout=org.apache.log4j.PatternLayout
+#log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
\ No newline at end of file
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/fixture/Main.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/fixture/Main.java
new file mode 100644
index 0000000..7cb59c2
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/fixture/Main.java
@@ -0,0 +1,23 @@
+package org.xwiki.android.test.fixture;
+
+import org.xwiki.test.integration.utils.XWikiExecutor;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: sasindap
+ * Date: 8/9/12
+ * Time: 4:40 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Main {
+ public static void main(String[] args) throws Exception {
+ System.setProperty("xwikiExecutionDirectory","C:\\Users\\admin\\Desktop\\xwiki-enterprise-jetty-10");
+ XWikiExecutor executor=new XWikiExecutor(0);
+ executor.start();
+ }
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/AttachmentOperations.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/AttachmentOperations.java
new file mode 100644
index 0000000..9809298
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/AttachmentOperations.java
@@ -0,0 +1,251 @@
+/*
+ * 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.android.test.utils.xmlrpc;
+
+import org.apache.http.util.EntityUtils;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
+import org.xwiki.android.resources.Attachments;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+
+/**
+ * XWiki Android REST Attachment related source. Can get the attachment details/list as a Attachments objects or the
+ * Stream of raw data of a attachment file.
+ */
+public class AttachmentOperations {
+
+ RestClient rpc;
+
+ /**
+ * Path provided from XWiki RESTful API
+ */
+ private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/";
+
+ /**
+ * URL of the XWiki domain
+ */
+ private String URLprefix;
+
+ /**
+ * Name of Wiki for acquiring attachment
+ */
+ private String wikiName;
+
+ /**
+ * Name of Space for acquiring attachment
+ */
+ private String spaceName;
+
+ /**
+ * Name of Page for acquiring attachment
+ */
+ private String pageName;
+
+ /**
+ * @param URLprefix XWiki URl ex:"www.xwiki.org"
+ * @param wikiName name of the wiki in UTF-8 format
+ * @param spaceName name of the space in UTF-8 format
+ * @param pageName name of the page in UTF-8 format
+ */
+ AttachmentOperations(String URLprefix, String wikiName, String spaceName, String pageName, RestClient rpc) {
+ this.URLprefix = URLprefix;
+ this.wikiName = wikiName;
+ this.spaceName = spaceName;
+ this.pageName = pageName;
+ this.rpc=rpc;
+ }
+
+ /**
+ * Gets Attachments object according to the provided field values in constructor
+ *
+ * @return Attachments object acquired according to the wiki, space & page names
+ * @throws IOException
+ * @throws RestException
+ */
+ public Attachments getAllPageAttachments() throws IOException, RestException {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/attachments";
+
+ return buildAttachments(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * Gets a stream data of the requested attachment
+ *
+ * @param attachmentName filename of the attachment in the page
+ * @return InputStream of the attachment data
+ * @throws IOException
+ * @throws RestException
+ */
+ public InputStream getPageAttachment(String attachmentName) throws IOException, RestException {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/attachments/" + attachmentName;
+
+ return rpc.getRequest(Uri).getEntity().getContent();
+ }
+
+ /**
+ * Add file to the XWiki stored in the internal/external memory
+ *
+ * @param file file representing the attachement.
+ * @param attachmentName name for the attachment
+ * @return status of the HTTP response
+ * @throws IOException
+ * @throws RestException
+ */
+ public String putPageAttachment(String attachmentName, File file) throws IOException, RestException {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/attachments/" + attachmentName;
+
+ return rpc.putRequest(Uri, file).getStatusLine().toString();
+ }
+
+ /**
+ * Gets Attachments object in the provided version of page
+ *
+ * @param version version of the page
+ * @return Attachments object acquired according to the wiki, space & page names
+ * @throws IOException
+ * @throws RestException
+ */
+ public Attachments getPageAttachmentsInHistory(String version) throws IOException, RestException {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/history/" + version + "/attachments";
+
+ return buildAttachments(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * Gets a stream data of the requested attachment in the provided page version
+ *
+ * @param version version of the page
+ * @param attachmentName file name of the attachement
+ * @return InputStream of the attachment data in provided page version
+ * @throws IOException
+ * @throws RestException
+ */
+ public InputStream getPageAttachmentsInHistory(String version, String attachmentName) throws IOException, RestException {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/history/" + version + "/attachments/" + attachmentName;
+
+ return rpc.getRequest(Uri).getEntity().getContent();
+ }
+
+ /**
+ * Gets the history of the attachment
+ *
+ * @param attachmentName filename of the attachment
+ * @return Attachments object with the version details of the attachment
+ * @throws IOException
+ * @throws RestException
+ */
+ public Attachments getPageAttachmentsInAttachmentHistory(String attachmentName) throws IOException, RestException {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/attachments/" + attachmentName + "/history";
+
+ return buildAttachments(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * Gets the attachment of a specific attachment version
+ *
+ * @param attachmentName filename of the attachment
+ * @param attachmentVersion version of the attachment
+ * @return InputStream of the provided attachment version
+ * @throws IOException
+ * @throws RestException
+ */
+ public InputStream getPageAttachmentsInAttachmentHistory(String attachmentName, String attachmentVersion) throws IOException, RestException {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/attachments/" + attachmentName + "/history/" + attachmentVersion;
+
+ return rpc.getRequest(Uri).getEntity().getContent();
+ }
+
+ /**
+ * Deletes attachment file from the XWiki server
+ *
+ * @param attachmentName filename of the attachment
+ * @return Status line of Http response
+ * @throws IOException
+ * @throws RestException
+ */
+ public String deletePageAttachment(String attachmentName) throws IOException, RestException {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/attachments/" + attachmentName;
+
+ return rpc.deleteRequest(Uri).getStatusLine().toString();
+ }
+
+ /**
+ * Parse xml into a Attachments object
+ *
+ * @param content XML content
+ * @return Attachments object deserialized from the xml content
+ */
+ private Attachments buildAttachments(String content) {
+ Attachments attachments = new Attachments();
+ Serializer serializer = new Persister();
+
+ try {
+ attachments = serializer.read(Attachments.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return attachments;
+ }
+
+ /**
+ * Generate XML content from the Attachments object
+ *
+ * @param attachments Attachments Object to be serialized into XML
+ * @return XML content of the provided Attachments object
+ */
+ private String buildXmlAttachments(Attachments attachments) {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(attachments, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/CommentOperations.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/CommentOperations.java
new file mode 100644
index 0000000..1eea20e
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/CommentOperations.java
@@ -0,0 +1,260 @@
+/*
+ * 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.android.test.utils.xmlrpc;
+
+import org.apache.http.util.EntityUtils;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
+import org.xwiki.android.resources.Comment;
+import org.xwiki.android.resources.Comments;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+/**
+ * XWiki Android REST Comments related source. Can get the comments details/list as a Comment(s) objects of Simple-xml
+ * object model
+ */
+public class CommentOperations
+{
+ /**
+ * Path provided from XWiki RESTful API
+ */
+ private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/";
+
+ /**
+ * URL of the XWiki domain
+ */
+ private String URLprefix;
+
+ /**
+ * Name of Wiki for acquiring comments
+ */
+ private String wikiName;
+
+ /**
+ * Name of space for acquiring comments
+ */
+ private String spaceName;
+
+ /**
+ * Name of page for acquiring comments
+ */
+ private String pageName;
+ private RestClient rpc;
+
+ /**
+ * @param URLprefix XWiki URl ex:"www.xwiki.org"
+ * @param wikiName name of the wiki in UTF-8 format
+ * @param spaceName name of the space in UTF-8 format
+ * @param pageName name of the page in UTF-8 format
+ * @param rpc
+ */
+ CommentOperations(String URLprefix, String wikiName, String spaceName, String pageName, RestClient rpc)
+ {
+ this.URLprefix = URLprefix;
+ this.wikiName = wikiName;
+ this.spaceName = spaceName;
+ this.pageName = pageName;
+ this.rpc=rpc;
+ }
+
+ /**
+ * @return Comments object of the page
+ * @throws IOException
+ * @throws RestException
+ */
+ public Comments getPageComments() throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/comments";
+ return buildComments(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ public boolean exists(int commentId) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/comments/" + commentId;
+ int code = rpc.headRequest(Uri);
+ if (code == 200) {
+ return true;
+ }
+ if (code == 404) {
+ return false;
+ } else {
+ throw new RestException(code);
+ }
+ }
+
+ /**
+ * @param commentId ID of the comment in the page
+ * @return comment of a page selected using comment ID
+ * @throws IOException
+ * @throws RestException
+ */
+ public Comment getPageComment(int commentId) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/comments/" + commentId;
+
+ return buildComment(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * @param version version of the page
+ * @return list of comments as a Comments object in a specific page history version
+ * @throws IOException
+ * @throws RestException
+ */
+ public Comments getPageCommentsInHistory(String version) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/history/" + version + "/comments";
+
+ return buildComments(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * @param version version of the page
+ * @param commentId ID of the comment in the page
+ * @return Comment in a specific page history version
+ * @throws IOException
+ * @throws RestException
+ */
+ public Comments getPageCommentsInHistory(String version, String commentId) throws IOException,
+ RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/history/" + version + "/comments/" + commentId;
+
+ return buildComments(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * Adds comment to the page
+ *
+ * @param comment Comment object to be added
+ * @return status of the HTTP post request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String addPageComment(Comment comment) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/comments";
+
+ return rpc.postRequest(Uri, buildXmlComment(comment)).getStatusLine().toString();
+ }
+
+ /**
+ * Parse xml into a Comments object
+ *
+ * @param content XML content
+ * @return Comments object deserialized from the xml content
+ */
+ private Comments buildComments(String content)
+ {
+ Comments comments = new Comments();
+
+ Serializer serializer = new Persister();
+
+ try {
+ comments = serializer.read(Comments.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return comments;
+ }
+
+ /**
+ * Generate XML content from the Comments object
+ *
+ * @param comments Comments object to be serialized into XML
+ * @return XML content of the provided Comments object
+ */
+ private String buildXmlComments(Comments comments)
+ {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(comments, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Parse xml into a Comment object
+ *
+ * @param content XML content
+ * @return Comment object deserialized from the xml content
+ */
+ private Comment buildComment(String content)
+ {
+ Comment comment = new Comment();
+
+ Serializer serializer = new Persister();
+
+ try {
+ comment = serializer.read(Comment.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return comment;
+ }
+
+ /**
+ * Generate XML content from the Comment object
+ *
+ * @param comment Comment object to be serialized into XML
+ * @return XML content of the provided Comment object
+ */
+ private String buildXmlComment(Comment comment)
+ {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(comment, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/ObjectOperations.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/ObjectOperations.java
new file mode 100644
index 0000000..956d4ab
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/ObjectOperations.java
@@ -0,0 +1,414 @@
+/*
+ * 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.android.test.utils.xmlrpc;
+
+import org.apache.http.util.EntityUtils;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
+import org.xwiki.android.resources.Object;
+import org.xwiki.android.resources.Objects;
+import org.xwiki.android.resources.Properties;
+import org.xwiki.android.resources.Property;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+/**
+ * XWiki Android REST Object related source. Can get the objects as a Object(s) objects of Simple-xml object model
+ */
+public class ObjectOperations
+{
+ /**
+ * Path provided from XWiki RESTful API
+ */
+ private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/";
+
+ /**
+ * URL of the XWiki domain
+ */
+ private String URLprefix;
+
+ /**
+ * Name of Wiki for acquiring objects
+ */
+ private String wikiName;
+
+ /**
+ * Name of space for acquiring objects
+ */
+ private String spaceName;
+
+ /**
+ * Name of page for acquiring objects
+ */
+ private String pageName;
+ private RestClient rpc;
+
+ /**
+ * @param URLprefix XWiki URl ex:"www.xwiki.org"
+ * @param wikiName name of the wiki in UTF-8 format
+ * @param spaceName name of the space in UTF-8 format
+ * @param pageName name of the page in UTF-8 format
+ * @param rpc
+ */
+ ObjectOperations(String URLprefix, String wikiName, String spaceName, String pageName, RestClient rpc)
+ {
+ this.URLprefix = URLprefix;
+ this.wikiName = wikiName;
+ this.spaceName = spaceName;
+ this.pageName = pageName;
+ this.rpc=rpc;
+ }
+
+ public boolean exists(String objectClassname, String objectNumber) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects" + objectClassname + "/" + objectNumber;
+
+ int code = rpc.headRequest(Uri);
+ if (code == 200) {
+ return true;
+ }
+ if (code == 404) {
+ return false;
+ } else {
+ throw new RestException(code);
+ }
+ }
+
+ /**
+ * @return list of all the Objects in a page
+ * @throws IOException
+ * @throws RestException
+ */
+ public Objects getAllObjects() throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects";
+
+ return buildObjects(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+
+ }
+
+ /**
+ * Adds object to the page
+ *
+ * @param object Object object to be added to the page
+ * @return status of th HTTP post request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String addObject(Object object) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects";
+
+ return rpc.postRequest(Uri, buildXmlObject(object)).getStatusLine().toString();
+
+ }
+
+ /**
+ * @param objectClassname name of the class
+ * @return list of objects in a specific class of a page
+ * @throws IOException
+ * @throws RestException
+ */
+ public Objects getObjectsInClassname(String objectClassname) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects/" + objectClassname;
+
+ return buildObjects(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+
+ }
+
+ /**
+ * @param objectClassname name of the class in the page
+ * @param objectNumber number of the object in the specified class
+ * @return selected Object object in the page
+ * @throws IOException
+ * @throws RestException
+ */
+ public Object getObject(String objectClassname, String objectNumber) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects/" + objectClassname + "/" + objectNumber;
+
+ return buildObject(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+
+ }
+
+ /**
+ * Update object in a page
+ *
+ * @param objectClassname name of the class of the object
+ * @param objectNumber number of the object in the class
+ * @param object Object object to be updated in the page
+ * @return status of the HTTP put request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String updateObject(String objectClassname, int objectNumber, Object object)
+ throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects/" + objectClassname + "/" + objectNumber;
+
+ return rpc.putRequest(Uri, buildXmlObject(object)).getStatusLine().toString();
+
+ }
+
+ /**
+ * Deletes the specified object in the page
+ *
+ * @param objectClassname name of the class in the page
+ * @param objectNumber number of the object in the class
+ * @return status of HTTP resonce in delete request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String deleteObject(String objectClassname, String objectNumber) throws IOException,
+ RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects/" + objectClassname + "/" + objectNumber;
+
+ return rpc.deleteRequest(Uri).getStatusLine().toString();
+
+ }
+
+ /**
+ * @param objectClassname class name of the object in a page
+ * @param objectNumber number of the object in the class
+ * @return list of properties as a Properties object in a object
+ * @throws IOException
+ * @throws RestException
+ */
+ public Properties getObjectProperties(String objectClassname, String objectNumber) throws IOException,
+ RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects/" + objectClassname + "/" + objectNumber + "/properties";
+
+ return buildProperties(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+
+ }
+
+ /**
+ * Adds a property to a object in a page
+ *
+ * @param objectClassname class name of the object
+ * @param objectNumber number of the object in the class
+ * @param property Property object to be added to the Object
+ * @return status of the HTTP put request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String addObjectProperty(String objectClassname, String objectNumber, Property property)
+ throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects/" + objectClassname + "/" + objectNumber + "/properties/" + property.getName();
+
+ return rpc.putRequest(Uri, buildXmlProperty(property)).getStatusLine().toString();
+ }
+
+ /**
+ * @param objectClassname class name of the objects
+ * @param objectNumber number of the object in the class
+ * @param propertyName name of the required property
+ * @return Specific property of a object in a page
+ * @throws IOException
+ * @throws RestException
+ */
+ public Property getObjectProperty(String objectClassname, String objectNumber, String propertyName)
+ throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/objects/" + objectClassname + "/" + objectNumber + "/properties/" + propertyName;
+
+ return buildProperty(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+
+ }
+
+ /**
+ * Parse xml into a Objects object
+ *
+ * @param content XML content
+ * @return Objects object deserialized from the xml content
+ */
+ private Objects buildObjects(String content)
+ {
+ Objects objects = new Objects();
+
+ Serializer serializer = new Persister();
+
+ try {
+ objects = serializer.read(Objects.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return objects;
+ }
+
+ /**
+ * Generate XML content from the Objects object
+ *
+ * @param objects Objects object to be serialized into XML
+ * @return XML content of the provided Objects object
+ */
+ private String buildXmlObjects(Objects objects)
+ {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(objects, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Generate XML content from the Object object
+ *
+ * @param object Object object to be serialized into XML
+ * @return XML content of the provided Object object
+ */
+ private String buildXmlObject(Object object)
+ {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(object, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Parse xml into a Object object
+ *
+ * @param content XML content
+ * @return Object object deserialized from the xml content
+ */
+ private Object buildObject(String content)
+ {
+ Object object = new Object();
+
+ Serializer serializer = new Persister();
+
+ try {
+ object = serializer.read(Object.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return object;
+ }
+
+ /**
+ * Parse xml into a Properties object
+ *
+ * @param content XML content
+ * @return Properties object deserialized from the xml content
+ */
+ private Properties buildProperties(String content)
+ {
+ Properties properties = new Properties();
+
+ Serializer serializer = new Persister();
+
+ try {
+ properties = serializer.read(Properties.class, content);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return properties;
+ }
+
+ /**
+ * Generate XML content from the Property object
+ *
+ * @param property Property object to be serialized into XML
+ * @return XML content of the provided Property object
+ */
+ private String buildXmlProperty(Property property)
+ {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(property, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Parse xml into a Property object
+ *
+ * @param content XML content
+ * @return Property object deserialized from the xml content
+ */
+ private Property buildProperty(String content)
+ {
+ Property property = new Property();
+
+ Serializer serializer = new Persister();
+
+ try {
+ property = serializer.read(Property.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return property;
+ }
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/PageOperations.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/PageOperations.java
new file mode 100644
index 0000000..8087625
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/PageOperations.java
@@ -0,0 +1,346 @@
+/*
+ * 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.android.test.utils.xmlrpc;
+
+import org.apache.http.util.EntityUtils;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
+import org.xwiki.android.resources.Page;
+import org.xwiki.android.resources.Pages;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+/**
+ * XWiki Android REST Page(s) related source. Can get the Page details/list as a Page(s) objects of Simple-xml object
+ * model
+ */
+public class PageOperations {
+ /**
+ * Path provided from XWiki RESTful API
+ */
+ private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/";
+
+ /**
+ * Path provided from XWiki RESTful API for pages
+ */
+ private final String PAGE_URL_SUFFIX = "/pages";
+
+ /**
+ * URL of the XWiki domain
+ */
+ private String URLprefix;
+
+ /**
+ * Name of Wiki for acquiring pages
+ */
+ private String wikiName;
+
+ /**
+ * Name of space for acquiring pages
+ */
+ private String spaceName;
+
+ private RestClient rpc;
+
+ /**
+ * @param URLprefix XWiki URl ex:"www.xwiki.org"
+ * @param wikiName name of the wiki in UTF-8 format
+ * @param spaceName name of the space in UTF-8 format
+ * @param rpc
+ */
+ PageOperations(String URLprefix, String wikiName, String spaceName, RestClient rpc)
+ {
+
+ this.URLprefix = URLprefix;
+ this.wikiName = wikiName;
+ this.spaceName = spaceName;
+ this.rpc=rpc;
+ }
+
+
+ /**
+ * @return all the pages as a Pages object in the specified space
+ * @throws IOException
+ * @throws RestException
+ */
+ public Pages getAllPages() throws IOException, RestException {
+ String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + PAGE_URL_SUFFIX;
+ ;
+ return buildPages(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+
+ public boolean exists(String pageName) throws IOException, RestException {
+ String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName;
+ int code = rpc.headRequest(Uri);
+
+ if (code == 200) {
+ return true;
+ }
+ if (code == 404) {
+ return false;
+ } else {
+ throw new RestException(code);
+ }
+
+ }
+
+ /**
+ * @param pageName name of the page
+ * @return requested page as a Page object
+ * @throws IOException
+ * @throws RestException
+ */
+ public Page getPage(String pageName) throws IOException, RestException {
+ String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName;
+
+ return buildPage(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * Adds or Modify the page
+ *
+ * @param page Page object to be added if not existing in the space or modified if it existing in the space
+ * @return status of the HTTP put request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String addPage(Page page) throws IOException, RestException {
+ if (page.getName() == null || page.getName().equals("")) {
+ throw new IllegalArgumentException("page.name should be initialized");
+ }
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + page.getName();
+ return (rpc.putRequest(Uri, buildXmlPage(page)).getStatusLine().toString());
+ }
+
+ /**
+ * Deletes the page by providing name of the page
+ *
+ * @param pageName name of the page
+ * @return status of the HTTP delete request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String deletePage(String pageName) throws IOException, RestException {
+ String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName;
+
+ if (rpc.isSecured()) {
+ return rpc.deleteRequest(Uri).getStatusLine().toString();
+ } else {
+ return "No authenticaiton details found";
+ }
+
+ }
+
+
+ /**
+ * @param pageName name of the page
+ * @param version history version of the page
+ * @return requested version of the page
+ * @throws IOException
+ * @throws RestException
+ */
+ public Page getPageHistoryOnVersion(String pageName, String version) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/history/" + version;
+
+ return buildPage(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * @param pageName name of the page
+ * @return children of the page as a Pages object
+ * @throws IOException
+ * @throws RestException
+ */
+ public Pages getPageChildren(String pageName) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/children";
+
+ return buildPages(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * @param pageName name of the page
+ * @param language language name of the page
+ * @return Translated page of the provided language
+ * @throws IOException
+ * @throws RestException
+ */
+ public Page getPageTranslation(String pageName, String language) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/translations/" + language;
+
+ return buildPage(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * Adds page translation to XWiki
+ *
+ * @param page Page object of the new translation
+ * @param language translated language name of the page
+ * @return status of the HTTP put request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String addPageTranslation(Page page, String language) throws IOException, RestException
+ {
+ if(page.getName()==null || page.getName().equals("")){
+ throw new IllegalArgumentException("page.name must be initialized");
+ }
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + page.getName()
+ + "/translations/" + language;
+
+ String content = buildXmlPage(page);
+
+ return rpc.putRequest(Uri, content).getStatusLine().toString();
+ }
+
+ /**
+ * Deletes specific translation page
+ *
+ * @param pageName name of the page
+ * @param language translated language name of the page
+ * @return status of the HTTP delete request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String deletePageTranslation(String pageName, String language) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/translations/" + language;
+
+ return rpc.deleteRequest(Uri).getStatusLine().toString();
+ }
+
+ /**
+ * @param pageName name of the page
+ * @param language translated language name of the page
+ * @param version version of the page
+ * @return translated page of the spcific page history version
+ * @throws IOException
+ * @throws RestException
+ */
+ public Page getPageTranslation(String pageName, String language, String version) throws IOException, RestException
+ {
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/translations/" + language + "/history/" + version;
+
+ return buildPage(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+
+
+
+ /**
+ * Parse xml into a Pages object
+ *
+ * @param content XML content
+ * @return Pages object deserialized from the xml content
+ */
+ private Pages buildPages(String content) {
+ Pages pages = new Pages();
+
+ Serializer serializer = new Persister();
+
+ try {
+ pages = serializer.read(Pages.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return pages;
+ }
+
+ /**
+ * Generate XML content from the Pages object
+ *
+ * @param pages Pages object to be serialized into XML
+ * @return XML content of the provided Pages object
+ */
+ private String buildXmlPages(Pages pages) {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(pages, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Parse xml into a Page object
+ *
+ * @param content XML content
+ * @return Page object deserialized from the xml content
+ */
+ private Page buildPage(String content) {
+ Page page = new Page();
+
+ Serializer serializer = new Persister();
+
+ try {
+ page = serializer.read(Page.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return page;
+ }
+
+ /**
+ * Generate XML content from the Page object
+ *
+ * @param page Page object to be serialized into XML
+ * @return XML content of the provided Page object
+ */
+ private String buildXmlPage(Page page) {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(page, result);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/RestClient.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/RestClient.java
new file mode 100644
index 0000000..de5cd49
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/RestClient.java
@@ -0,0 +1,436 @@
+/*
+ * 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.android.test.utils.xmlrpc;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.AuthState;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.entity.FileEntity;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility class for test setup setup. Same as org.xwiki.android.xmlrpc.HttpConnector. But not Dependant on android platform. *
+ * org.apache.http does not support preemtiveAuth, it is provided with HttpRequestInterceptor.
+ */
+
+public class RestClient {
+ Logger log = LoggerFactory.getLogger(RestClient.class);
+
+
+ private boolean secured;
+ private String serverUrl;
+
+ /**
+ * User credential details
+ */
+ private String username, password;
+
+ /**
+ * For executing http connection
+ */
+ private DefaultHttpClient client;
+
+ public RestClient(String serverUrl) {
+ this.serverUrl = serverUrl;
+ initializeHttpClient();
+ }
+
+ /**
+ * @param serverUrl = server name = host:port
+ * @param username
+ * @param password
+ */
+ public RestClient(String serverUrl, String username, String password) {
+ this.username = username;
+ this.password = password;
+ this.serverUrl = serverUrl;
+ initializeHttpClient();
+ secured = true;
+ setCredentials();
+ }
+
+ public void setAuthentication(String username, String password) {
+ this.username = username;
+ this.password = password;
+ secured = true;
+ setCredentials();
+ }
+
+ public boolean isSecured() {
+ return secured;
+ }
+
+ public int headRequest(String Uri) throws IOException {
+
+ HttpHead request = new HttpHead();
+ URI requestUri;
+ try {
+ requestUri = new URI(Uri);
+ request.setURI(requestUri);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ log.debug("Request URL :" + Uri);
+
+ try {
+ HttpResponse response = client.execute(request);
+ log.debug("Response status", response.getStatusLine().toString());
+ return response.getStatusLine().getStatusCode();
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ return -1;
+ }
+ }
+
+ /**
+ * Perform HTTP Get method execution and return the response as a String
+ *
+ * @param Uri URL of XWiki RESTful API
+ * @return Response data of the HTTP connection as a String
+ */
+ public HttpResponse getRequest(String Uri) throws IOException, RestException {
+
+
+ BufferedReader in = null;
+ HttpGet request = new HttpGet();
+ String responseText = new String();
+
+ try {
+ URI requestUri = new URI(Uri);
+ request.setURI(requestUri);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ log.debug("Request URL :" + Uri);
+ try {
+
+ HttpResponse response = client.execute(request);
+ log.debug("Response status", response.getStatusLine().toString());
+ in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+ StringBuffer sb = new StringBuffer("");
+ String line = "";
+ String NL = System.getProperty("line.separator");
+ while ((line = in.readLine()) != null) {
+ sb.append(line + NL);
+ }
+ responseText = sb.toString();
+ log.debug("Response", "response: " + responseText);
+ validate(response.getStatusLine().getStatusCode());
+ return response;
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ return null;
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+
+ /**
+ * Perform HTTP Delete method execution and return its status
+ *
+ * @param Uri URL of XWiki RESTful API
+ * @return status of the HTTP method execution
+ * @throws IOException
+ * @throws RestException
+ */
+ public HttpResponse deleteRequest(String Uri) throws IOException, RestException {
+
+ HttpDelete request = null;
+
+ try {
+ URI requestUri = new URI(Uri);
+ request = new HttpDelete();
+ request.setURI(requestUri);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ log.debug("Request URL :" + Uri);
+ try {
+ HttpResponse response = client.execute(request);
+
+ log.debug("Response status", response.getStatusLine().toString());
+ EntityUtils.consume(response.getEntity());
+ validate(response.getStatusLine().getStatusCode());
+ return response;
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+
+ /**
+ * Perform HTTP Post method execution and return its response status
+ *
+ * @param Uri URL of XWiki RESTful API
+ * @param content content to be posted to the server
+ * @return status code of the Post method execution
+ * @throws IOException
+ * @throws RestException
+ */
+ public HttpResponse postRequest(String Uri, String content) throws IOException, RestException {
+
+
+ HttpPost request = new HttpPost();
+
+ try {
+ URI requestUri = new URI(Uri);
+ request.setURI(requestUri);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+
+ log.debug("Request URL :" + Uri);
+
+ try {
+ log.debug("Post content", "content=" + content);
+ StringEntity se = new StringEntity(content, "UTF-8");
+
+ se.setContentType("application/xml");
+ // se.setContentType("text/plain");
+ request.setEntity(se);
+ request.setHeader("Content-Type", "application/xml;charset=UTF-8");
+
+ HttpResponse response = client.execute(request);
+ log.debug("Response status", response.getStatusLine().toString());
+ EntityUtils.consume(response.getEntity());
+ validate(response.getStatusLine().getStatusCode());
+ return response;
+
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Perform HTTP Put method execution and return its response status
+ *
+ * @param Uri URL of XWiki RESTful API
+ * @param content content to be posted to the server
+ * @return status code of the Put method execution
+ * @throws IOException
+ * @throws RestException
+ */
+ public HttpResponse putRequest(String Uri, String content) throws IOException, RestException {
+
+
+ HttpPut request = new HttpPut();
+
+ try {
+ log.debug("Request URL :" + Uri);
+ System.out.println(Uri);
+ URI requestUri = new URI(Uri);
+ request.setURI(requestUri);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+
+
+ try {
+ log.debug("Put content", "content=" + content);
+ StringEntity se = new StringEntity(content, "UTF-8");
+
+ se.setContentType("application/xml");
+ // se.setContentType("text/plain");
+ request.setEntity(se);
+ request.setHeader("Content-Type", "application/xml;charset=UTF-8");
+
+ HttpResponse response = client.execute(request);
+ log.debug("Response status", response.getStatusLine().toString());
+ EntityUtils.consume(response.getEntity());//close the stream to releas resources. //TODO: [ignore since test utils.]ideally this should be closed after content is read (if needed) by requester. So move it to PageOps etc.
+ validate(response.getStatusLine().getStatusCode());
+ return response;
+
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new IOException(e);
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Perform HTTP Put method with the raw data file
+ *
+ * @param Uri URL of XWiki RESTful API
+ * @param file file to upload
+ * @return status of the HTTP Put method execution
+ * @throws IOException
+ * @throws RestException
+ */
+ public HttpResponse putRequest(String Uri, File file) throws IOException, RestException {
+
+ HttpPut request = new HttpPut();
+ try {
+ URI requestUri = new URI(Uri);
+ request.setURI(requestUri);
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ log.debug("Request URL :" + Uri);
+ try {
+ FileEntity fe = new FileEntity(file, "/");
+ request.setEntity(fe);
+ // request.setHeader("Content-Type","application/xml;charset=UTF-8");
+ HttpResponse response = client.execute(request);
+ log.debug("Response status", response.getStatusLine().toString());
+ EntityUtils.consume(response.getEntity());
+ validate(response.getStatusLine().getStatusCode());
+ return response;
+ } catch (ClientProtocolException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ public SpaceOperations spaceOperations(String wikiName) {
+ return new SpaceOperations(serverUrl, wikiName, this);
+ }
+
+ public PageOperations pageOperations(String wikiName, String spaceName) {
+ return new PageOperations(serverUrl, wikiName, spaceName, this);
+ }
+
+ public ObjectOperations objectOperations(String wikiName, String spaceName, String pageName) {
+ return new ObjectOperations(serverUrl, wikiName, spaceName, pageName, this);
+ }
+
+ public CommentOperations commentOperations(String wikiName, String spaceName, String pageName) {
+ return new CommentOperations(serverUrl, wikiName, spaceName, pageName,this);
+ }
+
+ public AttachmentOperations attachmentOperations(String wikiName, String spaceName, String pageName) {
+ return new AttachmentOperations(serverUrl, wikiName, spaceName, pageName,this);
+ }
+
+ public TagOperations tagOperations(String wikiName, String spaceName, String pageName){
+ return new TagOperations(serverUrl,wikiName,spaceName,pageName,this);
+ }
+
+
+
+ public void shutDown() {
+ client.getConnectionManager().shutdown();
+ }
+
+
+ /**
+ * initializeHttpClient the general property fields
+ */
+ private void initializeHttpClient() {
+ client = new DefaultHttpClient();
+ //set http params
+ HttpParams params = new BasicHttpParams();
+ HttpConnectionParams.setConnectionTimeout(params, 10000);// try 10 seconds to get a socket connection
+ HttpConnectionParams.setSoTimeout(params, 20000);// wait 30 seconds waiting for data. then break connection.
+ client.setParams(params);
+ }
+
+ /**
+ * set user credentials with manually developed preemtive Auth
+ */
+ private void setCredentials() {
+ // Setting preemtiveAuth manually since org.apache.http does not support it
+ HttpRequestInterceptor preemptiveAuth = new HttpRequestInterceptor() {
+
+ public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
+ AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
+ CredentialsProvider credsProvider =
+ (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
+ HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
+
+ if (authState.getAuthScheme() == null) {
+ AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
+ Credentials creds = credsProvider.getCredentials(authScope);
+
+ if (creds != null) {
+ authState.setAuthScheme(new BasicScheme());
+ authState.setCredentials(creds);
+ }
+ }
+ }
+
+ };
+ client.addRequestInterceptor(preemptiveAuth, 0);
+ Credentials defaultcreds = new UsernamePasswordCredentials(username, password);
+ client.getCredentialsProvider().setCredentials(new AuthScope(null, -1, AuthScope.ANY_REALM), defaultcreds);
+
+ }
+
+ private void validate(int code) throws RestException {
+ if (400 <= code & code < 500) {
+ throw new RestException(code);
+ } else if (500 <= code & code < 600) {
+ throw new RuntimeException("server error : bad request. code:" + code);
+ }
+ }
+
+
+}
+
+
+
+
+
+
+
+
+
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/RestException.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/RestException.java
new file mode 100644
index 0000000..222cd61
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/RestException.java
@@ -0,0 +1,69 @@
+package org.xwiki.android.test.utils.xmlrpc;
+/**
+ *
+ * codes are equivelent to http response codes.
+ *
+ */
+public class RestException extends Exception
+{
+
+ int code;
+// public RestException()
+// {
+// super();
+// // TODO Auto-generated constructor stub
+// }
+//
+// public RestException(String detailMessage, Throwable throwable)
+// {
+// super(detailMessage, throwable);
+// // TODO Auto-generated constructor stub
+// }
+//
+// public RestException(String detailMessage)
+// {
+// super(detailMessage);
+// // TODO Auto-generated constructor stub
+// }
+//
+// public RestException(Throwable throwable)
+// {
+// super(throwable);
+// // TODO Auto-generated constructor stub
+// }
+
+ public RestException(int code)
+ {
+ super();
+ this.code=code;
+ }
+
+ public RestException(int code, String detailMessage, Throwable throwable)
+ {
+ super(detailMessage, throwable);
+ this.code=code;
+ }
+
+ public RestException(int code, String detailMessage)
+ {
+ super(detailMessage);
+ this.code=code;
+ }
+
+ public RestException(int code, Throwable throwable)
+ {
+ super(throwable);
+ this.code=code;
+ }
+
+
+ public int getCode()
+ {
+ return code;
+ }
+
+ @Override
+ public String getMessage() {
+ return "code: "+code; //To change body of overridden methods use File | Settings | File Templates.
+ }
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/SpaceOperations.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/SpaceOperations.java
new file mode 100644
index 0000000..dc2e699
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/SpaceOperations.java
@@ -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.android.test.utils.xmlrpc;
+
+import org.apache.http.util.EntityUtils;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
+import org.xwiki.android.resources.Spaces;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+/**
+ * XWiki Android REST Space related source. Can get the spaces details/list as a Space(s) objects of Simple-xml object
+ * model
+ */
+public class SpaceOperations
+{
+ /**
+ * Path provided from XWiki RESTful API
+ */
+ private final String SPACE_URL_PREFIX = "/xwiki/rest/wikis/";
+
+ /**
+ * Path provided from XWiki RESTful API for spaces
+ */
+ private final String SPACE_URL_SUFFIX = "/spaces";
+
+ /**
+ * URL of the XWiki domain
+ */
+ private String uRLprefix;
+
+ /**
+ * Name of Wiki for acquiring pages
+ */
+ private String wikiName;
+ private RestClient rpc;
+
+
+ /**
+ * @param URLprefix XWiki URl ex:"www.xwiki.org"
+ * @param wikiName name of the wiki in UTF-8 format
+ * @param rpc
+ */
+ public SpaceOperations(String URLprefix, String wikiName, RestClient rpc)
+ {
+ this.uRLprefix = URLprefix;
+ this.wikiName = wikiName;
+ this.rpc=rpc;
+ }
+
+ /**
+ * @return list of spaces in the specified Wiki
+ * @throws IOException
+ * @throws RestException
+ */
+ Spaces getSpaces() throws IOException, RestException
+ {
+
+ String Uri = "http://" + uRLprefix + SPACE_URL_PREFIX + wikiName + SPACE_URL_SUFFIX;
+
+ return buildSpaces(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+
+ }
+
+ /**
+ * Parse xml into a Spaces object
+ *
+ * @param content XML content
+ * @return Spaces object deserialized from the xml content
+ */
+ private Spaces buildSpaces(String content)
+ {
+ Spaces spaces = new Spaces();
+
+ Serializer serializer = new Persister();
+
+ try {
+ spaces = serializer.read(Spaces.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return spaces;
+ }
+
+ /**
+ * Generate XML content from the Spaces object
+ *
+ * @param spaces Spaces object to be serialized into XML
+ * @return XML content of the provided Spaces object
+ */
+ private String buildXmlSpaces(Spaces spaces)
+ {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(spaces, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/TagOperations.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/TagOperations.java
new file mode 100644
index 0000000..a71e538
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/TagOperations.java
@@ -0,0 +1,221 @@
+/*
+ * 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.android.test.utils.xmlrpc;
+
+import org.apache.http.util.EntityUtils;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
+import org.xwiki.android.resources.Tag;
+import org.xwiki.android.resources.Tags;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+public class TagOperations
+{
+ /**
+ * Path provided from XWiki RESTful API
+ */
+ private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/";
+
+ /**
+ * URL of the XWiki domain
+ */
+ private String URLprefix;
+
+ /**
+ * Name of Wiki for acquiring tags
+ */
+ private String wikiName;
+
+ /**
+ * Name of space for acquiring tags
+ */
+ private String spaceName;
+
+ /**
+ * Name of page for acquiring tags
+ */
+ private String pageName;
+
+ /**
+ * Type of the tag.
+ *
+ * 0= Wiki tag 1=Page tag >
+ */
+ private int tagType;
+ private RestClient rpc;
+
+ /**
+ * @param URLprefix XWiki URl ex:"www.xwiki.org"
+ * @param wikiName name of the wiki in UTF-8 format
+ */
+ TagOperations(String URLprefix, String wikiName, RestClient rpc)
+ {
+ this.URLprefix = URLprefix;
+ this.wikiName = wikiName;
+ tagType = 0;
+ this.rpc=rpc;
+ }
+
+ /**
+ * @param URLprefix XWiki URl ex:"www.xwiki.org"
+ * @param wikiName name of the wiki in UTF-8 format
+ * @param spaceName name of the space in UTF-8 format
+ * @param pageName name of the page in UTF-8 format
+ */
+ TagOperations(String URLprefix, String wikiName, String spaceName, String pageName, RestClient rpc)
+ {
+ this.rpc=rpc;
+ this.URLprefix = URLprefix;
+ this.wikiName = wikiName;
+ this.spaceName = spaceName;
+ this.pageName = pageName;
+ tagType = 1;
+ }
+
+ /**
+ * Gets all the tags either from wiki or from the page. If only the URL & Wiki name fields are provided then method
+ * will return wiki tags and if space name and page name is provided it will return page tags
+ *
+ * @return list of all tags as a Tags object
+ * @throws IOException
+ * @throws RestException
+ */
+ public Tags getTags() throws IOException, RestException
+ {
+
+ String Uri;
+
+ if (tagType == 0) {
+ Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/tags/";
+ } else if (tagType == 1) {
+ Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/tags";
+ } else {
+ Uri = "";
+ }
+
+ return buildTags(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * Adds tag to the wiki or the page depending on the fields provided in the constructor
+ *
+ * @param tag Tag object to be added
+ * @return statsu of the HTTP put request
+ * @throws IOException
+ * @throws RestException
+ */
+ public String addTag(Tag tag) throws IOException, RestException
+ {
+
+ String Uri = null;
+ if (tagType == 0) {
+
+ Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/tags";
+ String response = EntityUtils.toString(rpc.getRequest(Uri).getEntity());
+ Tags temp_tags;
+
+ temp_tags = buildTags(response);
+
+ temp_tags.getTags().add(tag);
+
+ return rpc.putRequest(Uri, buildXml(temp_tags)).getStatusLine().toString();
+
+ } else if (tagType == 1) {
+ Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/tags";
+ String response = EntityUtils.toString(rpc.getRequest(Uri).getEntity());
+ Tags temp_tags;
+
+ temp_tags = buildTags(response);
+
+ temp_tags.getTags().add(tag);
+
+ return rpc.putRequest(Uri, buildXml(temp_tags)).getStatusLine().toString();
+ }
+ throw new IllegalStateException("tagType should be =0 or 1");
+ }
+
+ public String setTags(Tags tags)throws IOException, RestException
+ {
+ String Uri = null;
+
+ if (tagType == 0) {
+
+ Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/tags";
+
+ return rpc.putRequest(Uri, buildXml(tags)).getStatusLine().toString();
+
+ } else {
+ Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/tags";
+ return rpc.putRequest(Uri, buildXml(tags)).getStatusLine().toString();
+ }
+
+ }
+
+ /**
+ * Parse xml into a Tags object
+ *
+ * @param content XML content
+ * @return Tags object deserialized from the xml content
+ */
+ private Tags buildTags(String content)
+ {
+ Tags tags = new Tags();
+
+ Serializer serializer = new Persister();
+
+ try {
+ tags = serializer.read(Tags.class, content);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return tags;
+ }
+
+ /**
+ * Generate XML content from the Tags object
+ *
+ * @param tags Tags object to be serialized into XML
+ * @return XML content of the provided Tags object
+ */
+ private String buildXml(Tags tags)
+ {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(tags, result);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/TranslationOperations.java b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/TranslationOperations.java
new file mode 100644
index 0000000..5547d68
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/TranslationOperations.java
@@ -0,0 +1,137 @@
+/*
+ * 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.android.test.utils.xmlrpc;
+
+import org.apache.http.util.EntityUtils;
+import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.core.Persister;
+import org.xwiki.android.resources.Translations;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+/**
+ * XWiki Android REST Translation related source. Can get the translation details/list as a Translations objects of
+ * Simple-xml object model. Translated pages will not requested through this class and it will provide from
+ * PageResources class
+ */
+public class TranslationOperations
+{
+ /**
+ * Path provided from XWiki RESTful API
+ */
+ private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/";
+
+ /**
+ * URL of the XWiki domain
+ */
+ private String URLprefix;
+
+ /**
+ * Name of Wiki for acquiring translations
+ */
+ private String wikiName;
+
+ /**
+ * Name of space for acquiring translations
+ */
+ private String spaceName;
+
+ /**
+ * Name of page for acquiring translations
+ */
+ private String pageName;
+ private RestClient rpc;
+
+ /**
+ * @param URLprefix XWiki URl ex:"www.xwiki.org"
+ * @param wikiName name of the Wiki in UTF-8 format
+ * @param spaceName name of the space in UTF-8 format
+ * @param pageName name of the page in UTF-8 format
+ */
+ TranslationOperations(String URLprefix, String wikiName, String spaceName, String pageName , RestClient rpc)
+ {
+ this.URLprefix = URLprefix;
+ this.wikiName = wikiName;
+ this.spaceName = spaceName;
+ this.pageName = pageName;
+ this.rpc=rpc;
+ }
+
+ /**
+ * @return list of all the translations are included in Translations object
+ * @throws IOException
+ * @throws RestException
+ */
+ public Translations getAllTranslations() throws IOException, RestException
+ {
+
+ String Uri =
+ "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName
+ + "/translations";
+
+ return buildTranslations(EntityUtils.toString(rpc.getRequest(Uri).getEntity()));
+ }
+
+ /**
+ * Parse xml into a Translations object
+ *
+ * @param content XML content
+ * @return Translations object deserialized from the xml content
+ */
+ private Translations buildTranslations(String content)
+ {
+ Translations translations = new Translations();
+
+ Serializer serializer = new Persister();
+
+ try {
+ translations = serializer.read(Translations.class, content);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return translations;
+ }
+
+ /**
+ * Generate XML content from the Translations object
+ *
+ * @param translations Translations object to be serialized into XML
+ * @return XML content of the provided Translations object
+ */
+ private String buildXmlTranslations(Translations translations)
+ {
+ Serializer serializer = new Persister();
+
+ StringWriter result = new StringWriter();
+
+ try {
+ serializer.write(translations, result);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result.toString();
+ }
+}
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/AntBuildListener.java b/xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/AntBuildListener.java
new file mode 100644
index 0000000..1e88512
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/AntBuildListener.java
@@ -0,0 +1,85 @@
+/*
+ * 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.test.integration.utils;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+
+/**
+ * Allow logging Ant messages to the console. This is used by the {@link org.xwiki.test.integration.XWikiTestSetup}
+ * class which uses Ant tasks to start/stop XWiki.
+ */
+public class AntBuildListener implements BuildListener
+{
+ private boolean isDebugModeOn;
+
+ /**
+ * @param isDebugModeOn if true then display debug messages too on the console
+ */
+ public AntBuildListener(boolean isDebugModeOn)
+ {
+ this.isDebugModeOn = isDebugModeOn;
+ }
+
+ @Override
+ public void buildStarted(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void buildFinished(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void targetStarted(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void targetFinished(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void taskStarted(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void taskFinished(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void messageLogged(BuildEvent event)
+ {
+ if ((event.getPriority() != Project.MSG_DEBUG) || isDebugModeOn) {
+ System.out.println(event.getMessage());
+ }
+ }
+}
\ No newline at end of file
diff --git a/xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/XWikiExecutor.java b/xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/XWikiExecutor.java
new file mode 100644
index 0000000..119176d
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/XWikiExecutor.java
@@ -0,0 +1,498 @@
+/*
+ * 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.test.integration.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.ExecTask;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Environment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Start and stop a xwiki instance.
+ *
+ * @version $Id$
+ * @since 2.0RC1
+ */
+public class XWikiExecutor
+{
+ protected static final Logger LOGGER = LoggerFactory.getLogger(XWikiExecutor.class);
+
+ public static final String SKIP_STARTING_XWIKI_INSTANCE = System.getProperty("xwiki.test.skipStart", "false");
+
+ public static final String BASEDIR = System.getProperty("basedir");
+
+ public static final String URL = System.getProperty("xwiki.test.baseURL", "http://localhost");
+
+ public static final String DEFAULT_PORT = System.getProperty("xwikiPort", "8080");
+
+ public static final String DEFAULT_STOPPORT = System.getProperty("xwikiStopPort", "8079");
+
+ public static final String DEFAULT_RMIPORT = System.getProperty("rmiPort", "9010");
+
+ private static final String DEFAULT_EXECUTION_DIRECTORY = System.getProperty("xwikiExecutionDirectory");
+
+ private static final String START_COMMAND = System.getProperty("xwikiExecutionStartCommand");
+
+ private static final String STOP_COMMAND = System.getProperty("xwikiExecutionStopCommand");
+
+ private static final boolean DEBUG = System.getProperty("debug", "false").equalsIgnoreCase("true");
+
+ private static final String WEBINF_PATH = "/webapps/xwiki/WEB-INF";
+
+ private static final String XWIKICFG_PATH = WEBINF_PATH + "/xwiki.cfg";
+
+ private static final String XWIKIPROPERTIES_PATH = WEBINF_PATH + "/xwiki.properties";
+
+ private static final int TIMEOUT_SECONDS = 120;
+
+ private Project project;
+
+ private int port;
+
+ private int stopPort;
+
+ private int rmiPort;
+
+ private String executionDirectory;
+
+ private List env = new ArrayList();
+
+ private String opts;
+
+ /**
+ * Was XWiki server already started. We don't try to stop it if it was already started.
+ */
+ private boolean wasStarted;
+
+ private class Response
+ {
+ public boolean timedOut;
+
+ public byte[] responseBody;
+
+ public int responseCode;
+ }
+
+ public XWikiExecutor(int index)
+ {
+ this.project = new Project();
+ this.project.init();
+ this.project.addBuildListener(new AntBuildListener(DEBUG));
+
+ // resolve ports
+ String portString = System.getProperty("xwikiPort" + index);
+ this.port = portString != null ? Integer.valueOf(portString) : (Integer.valueOf(DEFAULT_PORT) + index);
+ String stopPortString = System.getProperty("xwikiStopPort" + index);
+ this.stopPort =
+ stopPortString != null ? Integer.valueOf(stopPortString) : (Integer.valueOf(DEFAULT_STOPPORT) - index);
+ String rmiPortString = System.getProperty("rmiPort" + index);
+ this.rmiPort =
+ rmiPortString != null ? Integer.valueOf(rmiPortString) : (Integer.valueOf(DEFAULT_RMIPORT) + index);
+
+ // resolve execution directory
+ this.executionDirectory = System.getProperty("xwikiExecutionDirectory");
+ if (this.executionDirectory == null) {
+ this.executionDirectory = DEFAULT_EXECUTION_DIRECTORY;
+ if (this.executionDirectory == null) {
+ this.executionDirectory = BASEDIR + "/target/xwiki";
+ }
+ if (index > 0) {
+ this.executionDirectory += "-" + index;
+ }
+ }
+ }
+
+ public int getPort()
+ {
+ return this.port;
+ }
+
+ public int getStopPort()
+ {
+ return this.stopPort;
+ }
+
+ public int getRMIPort()
+ {
+ return this.rmiPort;
+ }
+
+ public String getExecutionDirectory()
+ {
+ if (this.executionDirectory == null) {
+ throw new RuntimeException("Invalid configuration for the execution directory. The "
+ + "[xwikiExecutionDirectory] system property must be specified.");
+ }
+ return this.executionDirectory;
+ }
+
+ public void addEnvironmentVariable(String key, String value)
+ {
+ Environment.Variable variable = new Environment.Variable();
+
+ variable.setKey(key);
+ variable.setValue(value);
+
+ this.env.add(variable);
+ }
+
+ public void setOpts(String opts)
+ {
+ this.opts = opts;
+ }
+
+ public void start() throws Exception
+ {
+ if (SKIP_STARTING_XWIKI_INSTANCE.equals("true")){
+ System.out.println(String.format("Using running instance at [%s:%s]", URL, getPort()));
+ }
+ else {
+ System.out.println(String.format("Starting XWiki server at [%s:%s]", URL, getPort()));
+ // First, verify if XWiki is started. If it is then don't start it again.
+ this.wasStarted = !isXWikiStarted(getURL(), 15).timedOut;
+ if (!this.wasStarted) {
+ startXWikiInSeparateThread();
+ waitForXWikiToLoad();
+ } else {
+ System.out.println("XWiki server is already started!");
+ }
+ }
+ }
+
+ private void startXWikiInSeparateThread()
+ {
+ Thread startThread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try {
+ startXWiki();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ startThread.start();
+ }
+
+ private void startXWiki() throws Exception
+ {
+ File dir = new File(getExecutionDirectory());
+ if (dir.exists()) {
+ ExecTask execTask = (ExecTask) this.project.createTask("exec");
+ execTask.setDir(new File(getExecutionDirectory()));
+ for (Environment.Variable variable : this.env) {
+ execTask.addEnv(variable);
+ }
+
+ if (this.opts != null) {
+ Environment.Variable optsVariable = new Environment.Variable();
+ optsVariable.setKey("XWIKI_OPTS");
+ optsVariable.setValue(this.opts);
+ execTask.addEnv(optsVariable);
+ }
+
+ String startCommand = getDefaultStartCommand(getPort(), getStopPort(), getRMIPort());
+ System.out.println("start command: "+startCommand);
+ Commandline commandLine = new Commandline(startCommand);
+ execTask.setCommand(commandLine);
+
+ execTask.execute();
+ } else {
+ throw new Exception("Invalid directory from where to start XWiki [" + this.executionDirectory + "]");
+ }
+ }
+
+ private Task createStopTask() throws Exception
+ {
+ ExecTask execTask;
+ File dir = new File(getExecutionDirectory());
+ if (dir.exists()) {
+ execTask = (ExecTask) this.project.createTask("exec");
+ execTask.setDir(new File(getExecutionDirectory()));
+
+ String stopCommand = getDefaultStopCommand(getStopPort());
+ Commandline commandLine = new Commandline(stopCommand);
+ execTask.setCommand(commandLine);
+ } else {
+ throw new Exception("Invalid directory from where to stop XWiki [" + this.executionDirectory + "]");
+ }
+
+ return execTask;
+ }
+
+ private void waitForXWikiToLoad() throws Exception
+ {
+
+ System.out.println("sleeping 3 sec allowing xwiki to start");
+ try{
+ Thread.sleep(3000);
+ }catch (InterruptedException e){
+ }
+ // Wait till the main page becomes available which means the server is started fine
+ System.out.println("Checking that XWiki is up and running...");
+
+ Response response = isXWikiStarted(getURL(), TIMEOUT_SECONDS);
+ if (response.timedOut) {
+ String message =
+ "Failed to start XWiki in [" + TIMEOUT_SECONDS + "] seconds, last error code [" + response.responseCode
+ + ", message [" + new String(response.responseBody) + "]"+" url tried was: "+ getURL();
+ System.out.println(message);
+ stop();
+ throw new RuntimeException(message);
+ } else {
+ System.out.println("Server is answering to [" + getURL() + "]... cool");
+ }
+ }
+
+ public Response isXWikiStarted(String url, int timeout) throws Exception
+ {
+ HttpClient client = new HttpClient();
+
+ boolean connected = false;
+ long startTime = System.currentTimeMillis();
+ Response response = new Response();
+ response.timedOut = false;
+ response.responseCode = -1;
+ response.responseBody = new byte[0];
+ while (!connected && !response.timedOut) {
+ GetMethod method = new GetMethod(url);
+
+ // Don't retry automatically since we're doing that in the algorithm below
+ method.getParams()
+ .setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
+ // Set a socket timeout to ensure the server has no chance of not answering to our request...
+ method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, new Integer(10000));
+
+ try {
+ // Execute the method.
+ response.responseCode = client.executeMethod(method);
+
+ // We must always read the response body.
+ response.responseBody = method.getResponseBody();
+
+ if (DEBUG) {
+ System.out.println(String.format("Result of pinging [%s] = [%s], Message = [%s]", url,
+ response.responseCode, new String(response.responseBody)));
+ }
+
+ // check the http response code is either not an error, either "unauthorized"
+ // (which is the case for products that deny view for guest, for example).
+ connected = (response.responseCode < 400 || response.responseCode == 401);
+ } catch (Exception e) {
+ // Do nothing as it simply means the server is not ready yet...
+ } finally {
+ // Release the connection.
+ method.releaseConnection();
+ }
+ Thread.sleep(500L);
+ response.timedOut = (System.currentTimeMillis() - startTime > timeout * 1000L);
+ }
+ return response;
+ }
+
+ public void stop() throws Exception
+ {
+ // Stop XWiki if it was started by start()
+ if (!this.wasStarted) {
+ createStopTask().execute();
+ }
+ System.out.println("XWiki server stopped");
+ }
+
+ public String getWebInfDirectory()
+ {
+ return getExecutionDirectory() + WEBINF_PATH;
+ }
+
+ public String getXWikiCfgPath()
+ {
+ return getExecutionDirectory() + XWIKICFG_PATH;
+ }
+
+ public String getXWikiPropertiesPath()
+ {
+ return getExecutionDirectory() + XWIKIPROPERTIES_PATH;
+ }
+
+ public Properties loadXWikiCfg() throws Exception
+ {
+ return getProperties(getXWikiCfgPath());
+ }
+
+ public Properties loadXWikiProperties() throws Exception
+ {
+ return getProperties(getXWikiPropertiesPath());
+ }
+
+ public PropertiesConfiguration loadXWikiPropertiesConfiguration() throws Exception
+ {
+ return getPropertiesConfiguration(getXWikiPropertiesPath());
+ }
+
+ /**
+ * @deprecated since 4.2M1 use {@link #getPropertiesConfiguration(String)} instead
+ */
+ @Deprecated
+ private Properties getProperties(String path) throws Exception
+ {
+ Properties properties = new Properties();
+
+ FileInputStream fis;
+ try {
+ fis = new FileInputStream(path);
+
+ try {
+ properties.load(fis);
+ } finally {
+ fis.close();
+ }
+ } catch (FileNotFoundException e) {
+ LOGGER.debug("Failed to load properties [" + path + "]", e);
+ }
+
+ return properties;
+ }
+
+ /**
+ * @since 4.2M1
+ */
+ private PropertiesConfiguration getPropertiesConfiguration(String path) throws Exception
+ {
+ PropertiesConfiguration properties = new PropertiesConfiguration();
+
+ FileInputStream fis;
+ try {
+ fis = new FileInputStream(path);
+
+ try {
+ properties.load(fis);
+ } finally {
+ fis.close();
+ }
+ } catch (FileNotFoundException e) {
+ LOGGER.debug("Failed to load properties [" + path + "]", e);
+ }
+
+ return properties;
+ }
+
+ public void saveXWikiCfg(Properties properties) throws Exception
+ {
+ saveProperties(getXWikiCfgPath(), properties);
+ }
+
+ /**
+ * @deprecated since 4.2M1 use {@link #saveXWikiProperties(PropertiesConfiguration)} instead
+ */
+ @Deprecated
+ public void saveXWikiProperties(Properties properties) throws Exception
+ {
+ saveProperties(getXWikiPropertiesPath(), properties);
+ }
+
+ /**
+ * @since 4.2M1
+ */
+ public void saveXWikiProperties(PropertiesConfiguration properties) throws Exception
+ {
+ savePropertiesConfiguration(getXWikiPropertiesPath(), properties);
+ }
+
+ private void saveProperties(String path, Properties properties) throws Exception
+ {
+ FileOutputStream fos = new FileOutputStream(path);
+ try {
+ properties.store(fos, null);
+ } finally {
+ fos.close();
+ }
+ }
+
+ private void savePropertiesConfiguration(String path, PropertiesConfiguration properties) throws Exception
+ {
+ FileOutputStream fos = new FileOutputStream(path);
+ try {
+ properties.save(fos);
+ } finally {
+ fos.close();
+ }
+ }
+
+ private String getURL()
+ {
+ // We use "xpage=plain" for 2 reasons:
+ // 1) the page loads faster since it doesn't need to display the skin
+ // 2) if the page doesn't exist it won't return a 404 HTTP Response code
+ return URL + ":" + getPort() + "/";
+ }
+
+ private String getDefaultStartCommand(int port, int stopPort, int rmiPort)
+ {
+ String startCommand = START_COMMAND;
+ if (startCommand == null) {
+ if (SystemUtils.IS_OS_WINDOWS) {
+ startCommand = String.format("cmd /c start_xwiki.bat %s %s", port, stopPort);
+ } else {
+ startCommand = String.format("sh -f start_xwiki.sh %s %s", port, stopPort);
+ }
+ } else {
+ startCommand = startCommand.replaceFirst(DEFAULT_PORT, String.valueOf(port));
+ startCommand = startCommand.replaceFirst(DEFAULT_STOPPORT, String.valueOf(stopPort));
+ startCommand = startCommand.replaceFirst(DEFAULT_RMIPORT, String.valueOf(rmiPort));
+ }
+
+ return startCommand;
+ }
+
+ private String getDefaultStopCommand(int stopPort)
+ {
+ String stopCommand = STOP_COMMAND;
+ if (stopCommand == null) {
+ if (SystemUtils.IS_OS_WINDOWS) {
+ stopCommand = String.format("cmd /c stop_xwiki.bat %s", stopPort);
+ } else {
+ stopCommand = String.format("sh -f stop_xwiki.sh %s", stopPort);
+ }
+ } else {
+ stopCommand = stopCommand.replaceFirst(DEFAULT_STOPPORT, String.valueOf(stopPort));
+ }
+
+ return stopCommand;
+ }
+}
\ No newline at end of file
diff --git a/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/AllTests.java b/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/AllTests.java
new file mode 100644
index 0000000..3da2f40
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/AllTests.java
@@ -0,0 +1,20 @@
+package org.xwiki.android.test.fixture.setup;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: admin
+ * Date: 8/11/12
+ * Time: 9:59 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ ServerStartTest.class,
+ SetupTestPageTest.class
+ })
+public class AllTests {
+
+}
diff --git a/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/ServerStartTest.java b/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/ServerStartTest.java
new file mode 100644
index 0000000..7e7b375
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/ServerStartTest.java
@@ -0,0 +1,44 @@
+package org.xwiki.android.test.fixture.setup;
+
+
+import junit.framework.AssertionFailedError;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.xwiki.android.test.fixture.setup.env.TestEnv;
+import org.xwiki.test.integration.utils.XWikiExecutor;
+
+public class ServerStartTest extends Assert {
+ XWikiExecutor exec;
+
+ boolean failed;
+ @Before
+ public void setup(){
+
+ exec=new XWikiExecutor(TestEnv.SERVER_INDEX);
+ try {
+ exec.start();
+ } catch (Exception e) {
+ throw new AssertionFailedError(e.getMessage());
+ }
+ }
+
+ @Test
+ public void setupProperly(){
+ try {
+ exec.isXWikiStarted(TestEnv.SCHEME + TestEnv.SERVER_URL, 10000);
+ } catch (Exception e) {
+ // failed=true;
+ throw new AssertionFailedError(e.getMessage());
+ }
+ }
+
+ @After
+ public void cleanup() throws Throwable{
+ if(failed){
+ exec.stop();//error if cant stop
+ }
+ }
+
+}
diff --git a/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/SetupTestPageTest.java b/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/SetupTestPageTest.java
new file mode 100644
index 0000000..9fee65c
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/SetupTestPageTest.java
@@ -0,0 +1,178 @@
+package org.xwiki.android.test.fixture.setup;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xwiki.android.resources.*;
+import org.xwiki.android.resources.Object;
+import org.xwiki.android.test.fixture.setup.env.TestEnv;
+import org.xwiki.android.test.utils.xmlrpc.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: admin
+ * Date: 8/11/12
+ * Time: 7:38 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class SetupTestPageTest extends Assert {
+ Logger logger = LoggerFactory.getLogger(SetupTestPageTest.class);
+ boolean failed;
+
+ String serverUrl, username, password, wikiName, spaceName, pageName, objecteClass, objectPropertyName, objectPropertyValue,
+ commentText, commentReplyText, tagWord, attachementName, attachmentDelName;
+ int commentReplyReplyTo;
+ RestClient rc;
+
+ @Before
+ public void setup() {
+ serverUrl = TestEnv.SERVER_URL;
+ username = TestEnv.USERNAME;
+ password = TestEnv.PASSWORD;
+
+ rc = new RestClient(serverUrl, username, password);
+
+ wikiName = TestEnv.WIKI_NAME;
+ spaceName = TestEnv.SPACE_NAME;
+ pageName = TestEnv.PAGE_NAME;
+ objecteClass = TestEnv.CLASS_NAME;
+ objectPropertyName = TestEnv.OBJECT_PROPERTY_NAME;
+ objectPropertyValue = TestEnv.OBJECT_PROPERTY_VALUE;
+ commentText = TestEnv.COMMENT_TEXT;
+ commentReplyText = TestEnv.COMMENT_REPLY_TEXT;
+ commentReplyReplyTo = TestEnv.COMMENT_REPLY_REPLY_TO;
+ tagWord = TestEnv.TAG_WORD;
+ attachementName=TestEnv.ATTACHMENT_NAME;
+ attachmentDelName=TestEnv.ATTACHMENT_DEL_NAME;
+
+ logger.debug("setting up the external fixture at server: " + serverUrl + " wiki:" + wikiName + " spaces: [ " + spaceName + " ]");
+ }
+
+ @Test
+ public void setupPage() throws RestException, IOException {
+ //delete page if exists. We delete it here because after the tests are over u can manually see the state on the server by starting it again.
+ PageOperations pageOps = rc.pageOperations(wikiName, spaceName);
+ if (pageOps.exists(pageName)) {
+ pageOps.deletePage(pageName);
+ }
+ ;
+ //add page
+
+ Page p = new Page();
+ p.setTitle(pageName);
+ p.setName(pageName);
+ p.setContent("Hi All! Happy Testing!");
+ pageOps.addPage(p);
+
+ //add obj
+ org.xwiki.android.resources.Object obj = new Object();
+ Property prop = new Property();
+ prop.setName(objectPropertyName);
+ prop.setValue(objectPropertyValue);
+ prop.attributes = new ArrayList(); //without attributes list added simplexml will throw exception.
+ obj.withClassName(objecteClass).withProperties(prop);
+
+ ObjectOperations objOps = rc.objectOperations(wikiName, spaceName, pageName);
+ objOps.addObject(obj);
+
+ //add comment
+ Comment c0 = new Comment();
+ c0.setText(commentText);
+
+ Comment c1 = new Comment();
+ c1.setReplyTo(commentReplyReplyTo);
+ c1.setText(commentReplyText);
+
+ CommentOperations cmntOps = rc.commentOperations(wikiName, spaceName, pageName);
+ cmntOps.addPageComment(c0);
+ cmntOps.addPageComment(c1);
+
+ //edit comment c0
+ //we have to use object with class XWiki.Comment
+ Object cobj=new Object();
+ cobj.withClassName("XWiki.XWikiComments");
+ Property cp=new Property();
+ cp.setName("comment");
+ cp.setValue("hi edited");
+ cp.attributes=new ArrayList();//simple xml does not check for null
+ cobj.withProperties(cp);
+ objOps.updateObject("XWiki.XWikiComments",0,cobj);
+ //add tag
+
+ Tag t = new Tag();
+ t.setName(tagWord);
+ Tags ts = new Tags();
+ ts.withTags(t);
+ TagOperations tagOps = rc.tagOperations(wikiName, spaceName, pageName);
+ tagOps.setTags(ts);
+
+ //add attachment
+ AttachmentOperations attachmentOperations = rc.attachmentOperations(wikiName, spaceName, pageName);
+ URL url = ClassLoader.getSystemResource(attachementName);
+ URL urldel = ClassLoader.getSystemResource(attachementName);
+ logger.debug("Attachment path: " + url);
+ File f = null;
+ File fdel=null;
+ try {
+ f = new File(url.toURI());
+ fdel=new File(urldel.toURI());
+ } catch (URISyntaxException e) {
+ logger.error("cannot create file for attachment:", e);
+ }
+ attachmentOperations.putPageAttachment(attachementName, f);
+ attachmentOperations.putPageAttachment(attachementName, f);//add it again
+ attachmentOperations.putPageAttachment(attachmentDelName,fdel);
+
+
+
+ //page translations.
+ Page pfr=new Page();
+ pfr.setName(pageName);
+ pfr.setTitle(pageName);
+ pfr.setContent("Bonzua!");
+ pageOps.addPageTranslation(pfr,"fr");
+ pfr.setContent("Bonzua! Happy Testing in French");
+ pageOps.addPageTranslation(pfr, "fr");
+
+
+
+ }
+
+ @After
+ public void cleanup() throws Throwable {
+ rc.shutDown();
+ }
+
+ ///
+ /*
+ public static final String COMMENT_ID = "0";
+
+ public static final String LANGUAGE = "null";
+
+ public static final String CLASS_NAME = "Blog.BlogPostClass";
+
+ public static final String OBJECT_NUMBER = "0";
+
+ public static final String OBJECT_PROPERTY_NAME = "content";
+
+ public static final String SEARCH_KEWORD = "test";
+
+ public static final String TAG_WORD = "testTag";
+
+ public static final String ATTACHMENT_NAME = "a.png";
+
+ public static final String ATTACHMENT_PATH = "./";
+
+ public static final String ATTACHMENT_VERSION = "1.0";
+ */
+
+}
diff --git a/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/env/TestEnv.java b/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/env/TestEnv.java
new file mode 100644
index 0000000..1868bf0
--- /dev/null
+++ b/xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/env/TestEnv.java
@@ -0,0 +1,72 @@
+package org.xwiki.android.test.fixture.setup.env;
+
+/**
+ * Environment variables for tests.
+ * How to setup external text setup.
+ */
+
+public class TestEnv {
+
+ public static final String DEFAULT_EXECUTION_DIRECTORY="D:\\Xwiki-server"; //machine dependant. If prop not set in pom specify here. ex: for IDE builds
+ public static final int SERVER_INDEX;
+ public static final String HOST = "localhost";
+ public static final int PORT = 8080; //actual port is port+server_index
+ public static final String SCHEME="http://";
+ public static final String SERVER_URL; //SERVER NAME set in static block.
+ public static final String USERNAME = "Admin";
+ public static final String PASSWORD = "admin";
+
+ //external test fixture.
+
+ public static final String WIKI_NAME = "xwiki";
+
+ public static final String SPACE_NAME = "Blog";
+
+ public static final String PAGE_NAME = "test2";
+
+ public static final String PAGE_VERSION = "1.1";
+
+ public static final String COMMENT_ID = "0";
+ public static final String COMMENT_TEXT = "hi";
+ public static final String COMMENT_REPLY_ID = "1";
+ public static final int COMMENT_REPLY_REPLY_TO = 0;
+ public static final String COMMENT_PAGE_HISTORY_VERSION="5.1";
+ public static final String COMMENT_REPLY_TEXT = "huy";
+
+
+ public static final String LANGUAGE = "fr";
+ public static final String TRANSLATION_VERSION="2.1";
+
+ public static final String CLASS_NAME = "Blog.BlogPostClass";
+ public static final String OBJECT_NUMBER = "0";
+ public static final String OBJECT_PROPERTY_NAME = "content";
+ public static final String OBJECT_PROPERTY_VALUE = "test blog content";
+
+ public static final String SEARCH_KEWORD = "test";
+
+ public static final String TAG_WORD = "testTag";
+
+ public static final String ATTACHMENT_NAME = "a.png";
+ public static final String ATTACHMENT_DEL_NAME = "del.png";
+ public static final String ATTACHMENT_PATH = "./";
+ public static final String ATTACHMENT_VERSION = "1.1";
+ public static final String ATTACHMENT_PAGE_HISTORY_VERSION = "9.1";
+
+ static {
+ SERVER_INDEX = new Integer(System.getProperty("xwikiExecutionIndex", "0"));
+ SERVER_URL = HOST + ":" + (PORT + SERVER_INDEX);
+ if(System.getProperty("xwikiExecutionDirectory")==null){
+ System.out.println("ERROR : xwikiExecutionDirectory not set in pom. ");
+ if(DEFAULT_EXECUTION_DIRECTORY==null){
+ throw new RuntimeException("If IDE build, set a defalut xwiki execution directory for you local machine. see TestConstants.DEFAULT_EXECUTION_DIRECTORY") ;
+ }
+ if(SERVER_INDEX>0){
+ System.setProperty("xwikiExecutionDirectory", DEFAULT_EXECUTION_DIRECTORY+"-"+SERVER_INDEX);//set it up to default val above, if not set by pom.else rewrite.
+ }else{
+ System.setProperty("xwikiExecutionDirectory", DEFAULT_EXECUTION_DIRECTORY);//set it up to default val above, if not set by pom.else rewrite.
+ }
+ }
+ System.out.println("xwiki execution dir:"+ System.getProperty("xwikiExecutionDirectory") +" index: "+SERVER_INDEX + " server Url: "+SERVER_URL);
+ }
+
+}
diff --git a/xwiki-android-test-fixture-teardown/pom.xml b/xwiki-android-test-fixture-teardown/pom.xml
new file mode 100644
index 0000000..158fb5d
--- /dev/null
+++ b/xwiki-android-test-fixture-teardown/pom.xml
@@ -0,0 +1,76 @@
+
+
+
+ xwiki-android
+ org.xwiki.android
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ xwiki-android-test-fixture-teardown
+
+
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.6.6
+
+
+
+ org.apache.ant
+ ant
+ 1.7.0
+
+
+
+ commons-httpclient
+ commons-httpclient
+ 3.1
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.1.2
+
+
+
+ org.apache.httpcomponents
+ httpcore
+ 4.1.2
+
+
+
+
+ commons-configuration
+ commons-configuration
+ 1.8
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.0
+
+
+
+ junit
+ junit
+ 4.10
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+
+
+
\ No newline at end of file
diff --git a/xwiki-android-test-fixture-teardown/resources/log4j.properties b/xwiki-android-test-fixture-teardown/resources/log4j.properties
new file mode 100644
index 0000000..762bbbb
--- /dev/null
+++ b/xwiki-android-test-fixture-teardown/resources/log4j.properties
@@ -0,0 +1,7 @@
+log4j.rootLogger=DEBUG, CA
+log4j.logger.org.apache.http=ERROR , CA
+
+log4j.appender.CA=org.apache.log4j.ConsoleAppender
+
+log4j.appender.CA.layout=org.apache.log4j.PatternLayout
+log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
diff --git a/xwiki-android-test-fixture-teardown/src/org/xwiki/test/integration/AntBuildListener.java b/xwiki-android-test-fixture-teardown/src/org/xwiki/test/integration/AntBuildListener.java
new file mode 100644
index 0000000..dd1bfa8
--- /dev/null
+++ b/xwiki-android-test-fixture-teardown/src/org/xwiki/test/integration/AntBuildListener.java
@@ -0,0 +1,85 @@
+/*
+ * 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.test.integration;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+
+/**
+ * Allow logging Ant messages to the console. This is used by the {@link org.xwiki.test.integration.XWikiTestSetup}
+ * class which uses Ant tasks to start/stop XWiki.
+ */
+public class AntBuildListener implements BuildListener
+{
+ private boolean isDebugModeOn;
+
+ /**
+ * @param isDebugModeOn if true then display debug messages too on the console
+ */
+ public AntBuildListener(boolean isDebugModeOn)
+ {
+ this.isDebugModeOn = isDebugModeOn;
+ }
+
+ @Override
+ public void buildStarted(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void buildFinished(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void targetStarted(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void targetFinished(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void taskStarted(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void taskFinished(BuildEvent event)
+ {
+ // Voluntarily do nothing
+ }
+
+ @Override
+ public void messageLogged(BuildEvent event)
+ {
+ if ((event.getPriority() != Project.MSG_DEBUG) || isDebugModeOn) {
+ System.out.println(event.getMessage());
+ }
+ }
+}
\ No newline at end of file
diff --git a/xwiki-android-test-fixture-teardown/src/org/xwiki/test/integration/XWikiExecutor.java b/xwiki-android-test-fixture-teardown/src/org/xwiki/test/integration/XWikiExecutor.java
new file mode 100644
index 0000000..cff53bd
--- /dev/null
+++ b/xwiki-android-test-fixture-teardown/src/org/xwiki/test/integration/XWikiExecutor.java
@@ -0,0 +1,491 @@
+/*
+ * 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.test.integration;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.ExecTask;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Environment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Start and stop a xwiki instance.
+ *
+ * @version $Id$
+ * @since 2.0RC1
+ */
+public class XWikiExecutor
+{
+ protected static final Logger LOGGER = LoggerFactory.getLogger(XWikiExecutor.class);
+
+ public static final String SKIP_STARTING_XWIKI_INSTANCE = System.getProperty("xwiki.test.skipStart", "false");
+
+ public static final String BASEDIR = System.getProperty("basedir");
+
+ public static final String URL = System.getProperty("xwiki.test.baseURL", "http://localhost");
+
+ public static final String DEFAULT_PORT = System.getProperty("xwikiPort", "8080");
+
+ public static final String DEFAULT_STOPPORT = System.getProperty("xwikiStopPort", "8079");
+
+ public static final String DEFAULT_RMIPORT = System.getProperty("rmiPort", "9010");
+
+ private static final String DEFAULT_EXECUTION_DIRECTORY = System.getProperty("xwikiExecutionDirectory");
+
+ private static final String START_COMMAND = System.getProperty("xwikiExecutionStartCommand");
+
+ private static final String STOP_COMMAND = System.getProperty("xwikiExecutionStopCommand");
+
+ private static final boolean DEBUG = System.getProperty("debug", "false").equalsIgnoreCase("true");
+
+ private static final String WEBINF_PATH = "/webapps/xwiki/WEB-INF";
+
+ private static final String XWIKICFG_PATH = WEBINF_PATH + "/xwiki.cfg";
+
+ private static final String XWIKIPROPERTIES_PATH = WEBINF_PATH + "/xwiki.properties";
+
+ private static final int TIMEOUT_SECONDS = 120;
+
+ private Project project;
+
+ private int port;
+
+ private int stopPort;
+
+ private int rmiPort;
+
+ private String executionDirectory;
+
+ private List env = new ArrayList();
+
+ private String opts;
+
+ /**
+ * Was XWiki server already started. We don't try to stop it if it was already started.
+ */
+ private boolean wasStarted;
+
+ private class Response
+ {
+ public boolean timedOut;
+
+ public byte[] responseBody;
+
+ public int responseCode;
+ }
+
+ public XWikiExecutor(int index)
+ {
+ this.project = new Project();
+ this.project.init();
+ this.project.addBuildListener(new AntBuildListener(DEBUG));
+
+ // resolve ports
+ String portString = System.getProperty("xwikiPort" + index);
+ this.port = portString != null ? Integer.valueOf(portString) : (Integer.valueOf(DEFAULT_PORT) + index);
+ String stopPortString = System.getProperty("xwikiStopPort" + index);
+ this.stopPort =
+ stopPortString != null ? Integer.valueOf(stopPortString) : (Integer.valueOf(DEFAULT_STOPPORT) - index);
+ String rmiPortString = System.getProperty("rmiPort" + index);
+ this.rmiPort =
+ rmiPortString != null ? Integer.valueOf(rmiPortString) : (Integer.valueOf(DEFAULT_RMIPORT) + index);
+
+ // resolve execution directory
+ this.executionDirectory = System.getProperty("xwikiExecutionDirectory" + index);
+ if (this.executionDirectory == null) {
+ this.executionDirectory = DEFAULT_EXECUTION_DIRECTORY;
+ if (this.executionDirectory == null) {
+ this.executionDirectory = BASEDIR + "/target/xwiki";
+ }
+ if (index > 0) {
+ this.executionDirectory += "-" + index;
+ }
+ }
+ }
+
+ public int getPort()
+ {
+ return this.port;
+ }
+
+ public int getStopPort()
+ {
+ return this.stopPort;
+ }
+
+ public int getRMIPort()
+ {
+ return this.rmiPort;
+ }
+
+ public String getExecutionDirectory()
+ {
+ if (this.executionDirectory == null) {
+ throw new RuntimeException("Invalid configuration for the execution directory. The "
+ + "[xwikiExecutionDirectory] system property must be specified.");
+ }
+ return this.executionDirectory;
+ }
+
+ public void addEnvironmentVariable(String key, String value)
+ {
+ Environment.Variable variable = new Environment.Variable();
+
+ variable.setKey(key);
+ variable.setValue(value);
+
+ this.env.add(variable);
+ }
+
+ public void setOpts(String opts)
+ {
+ this.opts = opts;
+ }
+
+ public void start() throws Exception
+ {
+ if (SKIP_STARTING_XWIKI_INSTANCE.equals("true")){
+ System.out.println(String.format("Using running instance at [%s:%s]", URL, getPort()));
+ }
+ else {
+ System.out.println(String.format("Starting XWiki server at [%s:%s]", URL, getPort()));
+ // First, verify if XWiki is started. If it is then don't start it again.
+ this.wasStarted = !isXWikiStarted(getURL(), 15).timedOut;
+ if (!this.wasStarted) {
+ startXWikiInSeparateThread();
+ waitForXWikiToLoad();
+ } else {
+ System.out.println("XWiki server is already started!");
+ }
+ }
+ }
+
+ private void startXWikiInSeparateThread()
+ {
+ Thread startThread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try {
+ startXWiki();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ startThread.start();
+ }
+
+ private void startXWiki() throws Exception
+ {
+ File dir = new File(getExecutionDirectory());
+ if (dir.exists()) {
+ ExecTask execTask = (ExecTask) this.project.createTask("exec");
+ execTask.setDir(new File(getExecutionDirectory()));
+ for (Environment.Variable variable : this.env) {
+ execTask.addEnv(variable);
+ }
+
+ if (this.opts != null) {
+ Environment.Variable optsVariable = new Environment.Variable();
+ optsVariable.setKey("XWIKI_OPTS");
+ optsVariable.setValue(this.opts);
+ execTask.addEnv(optsVariable);
+ }
+
+ String startCommand = getDefaultStartCommand(getPort(), getStopPort(), getRMIPort());
+ Commandline commandLine = new Commandline(startCommand);
+ execTask.setCommand(commandLine);
+
+ execTask.execute();
+ } else {
+ throw new Exception("Invalid directory from where to start XWiki [" + this.executionDirectory + "]");
+ }
+ }
+
+ private Task createStopTask() throws Exception
+ {
+ ExecTask execTask;
+ File dir = new File(getExecutionDirectory());
+ if (dir.exists()) {
+ execTask = (ExecTask) this.project.createTask("exec");
+ execTask.setDir(new File(getExecutionDirectory()));
+
+ String stopCommand = getDefaultStopCommand(getStopPort());
+ Commandline commandLine = new Commandline(stopCommand);
+ execTask.setCommand(commandLine);
+ } else {
+ throw new Exception("Invalid directory from where to stop XWiki [" + this.executionDirectory + "]");
+ }
+
+ return execTask;
+ }
+
+ private void waitForXWikiToLoad() throws Exception
+ {
+ // Wait till the main page becomes available which means the server is started fine
+ System.out.println("Checking that XWiki is up and running...");
+
+ Response response = isXWikiStarted(getURL(), TIMEOUT_SECONDS);
+ if (response.timedOut) {
+ String message =
+ "Failed to start XWiki in [" + TIMEOUT_SECONDS + "] seconds, last error code [" + response.responseCode
+ + ", message [" + new String(response.responseBody) + "]";
+ System.out.println(message);
+ stop();
+ throw new RuntimeException(message);
+ } else {
+ System.out.println("Server is answering to [" + getURL() + "]... cool");
+ }
+ }
+
+ public Response isXWikiStarted(String url, int timeout) throws Exception
+ {
+ HttpClient client = new HttpClient();
+
+ boolean connected = false;
+ long startTime = System.currentTimeMillis();
+ Response response = new Response();
+ response.timedOut = false;
+ response.responseCode = -1;
+ response.responseBody = new byte[0];
+ while (!connected && !response.timedOut) {
+ GetMethod method = new GetMethod(url);
+
+ // Don't retry automatically since we're doing that in the algorithm below
+ method.getParams()
+ .setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
+ // Set a socket timeout to ensure the server has no chance of not answering to our request...
+ method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, new Integer(10000));
+
+ try {
+ // Execute the method.
+ response.responseCode = client.executeMethod(method);
+
+ // We must always read the response body.
+ response.responseBody = method.getResponseBody();
+
+ if (DEBUG) {
+ System.out.println(String.format("Result of pinging [%s] = [%s], Message = [%s]", url,
+ response.responseCode, new String(response.responseBody)));
+ }
+
+ // check the http response code is either not an error, either "unauthorized"
+ // (which is the case for products that deny view for guest, for example).
+ connected = (response.responseCode < 400 || response.responseCode == 401);
+ } catch (Exception e) {
+ // Do nothing as it simply means the server is not ready yet...
+ } finally {
+ // Release the connection.
+ method.releaseConnection();
+ }
+ Thread.sleep(500L);
+ response.timedOut = (System.currentTimeMillis() - startTime > timeout * 1000L);
+ }
+ return response;
+ }
+
+ public void stop() throws Exception
+ {
+ // Stop XWiki if it was started by start()
+ if (!this.wasStarted) {
+ createStopTask().execute();
+ }
+ System.out.println("XWiki server stopped");
+ }
+
+ public String getWebInfDirectory()
+ {
+ return getExecutionDirectory() + WEBINF_PATH;
+ }
+
+ public String getXWikiCfgPath()
+ {
+ return getExecutionDirectory() + XWIKICFG_PATH;
+ }
+
+ public String getXWikiPropertiesPath()
+ {
+ return getExecutionDirectory() + XWIKIPROPERTIES_PATH;
+ }
+
+ public Properties loadXWikiCfg() throws Exception
+ {
+ return getProperties(getXWikiCfgPath());
+ }
+
+ public Properties loadXWikiProperties() throws Exception
+ {
+ return getProperties(getXWikiPropertiesPath());
+ }
+
+ public PropertiesConfiguration loadXWikiPropertiesConfiguration() throws Exception
+ {
+ return getPropertiesConfiguration(getXWikiPropertiesPath());
+ }
+
+ /**
+ * @deprecated since 4.2M1 use {@link #getPropertiesConfiguration(String)} instead
+ */
+ @Deprecated
+ private Properties getProperties(String path) throws Exception
+ {
+ Properties properties = new Properties();
+
+ FileInputStream fis;
+ try {
+ fis = new FileInputStream(path);
+
+ try {
+ properties.load(fis);
+ } finally {
+ fis.close();
+ }
+ } catch (FileNotFoundException e) {
+ LOGGER.debug("Failed to load properties [" + path + "]", e);
+ }
+
+ return properties;
+ }
+
+ /**
+ * @since 4.2M1
+ */
+ private PropertiesConfiguration getPropertiesConfiguration(String path) throws Exception
+ {
+ PropertiesConfiguration properties = new PropertiesConfiguration();
+
+ FileInputStream fis;
+ try {
+ fis = new FileInputStream(path);
+
+ try {
+ properties.load(fis);
+ } finally {
+ fis.close();
+ }
+ } catch (FileNotFoundException e) {
+ LOGGER.debug("Failed to load properties [" + path + "]", e);
+ }
+
+ return properties;
+ }
+
+ public void saveXWikiCfg(Properties properties) throws Exception
+ {
+ saveProperties(getXWikiCfgPath(), properties);
+ }
+
+ /**
+ * @deprecated since 4.2M1 use {@link #saveXWikiProperties(PropertiesConfiguration)} instead
+ */
+ @Deprecated
+ public void saveXWikiProperties(Properties properties) throws Exception
+ {
+ saveProperties(getXWikiPropertiesPath(), properties);
+ }
+
+ /**
+ * @since 4.2M1
+ */
+ public void saveXWikiProperties(PropertiesConfiguration properties) throws Exception
+ {
+ savePropertiesConfiguration(getXWikiPropertiesPath(), properties);
+ }
+
+ private void saveProperties(String path, Properties properties) throws Exception
+ {
+ FileOutputStream fos = new FileOutputStream(path);
+ try {
+ properties.store(fos, null);
+ } finally {
+ fos.close();
+ }
+ }
+
+ private void savePropertiesConfiguration(String path, PropertiesConfiguration properties) throws Exception
+ {
+ FileOutputStream fos = new FileOutputStream(path);
+ try {
+ properties.save(fos);
+ } finally {
+ fos.close();
+ }
+ }
+
+ private String getURL()
+ {
+ // We use "xpage=plain" for 2 reasons:
+ // 1) the page loads faster since it doesn't need to display the skin
+ // 2) if the page doesn't exist it won't return a 404 HTTP Response code
+ return URL + ":" + getPort() + "/org/xwiki/bin/view/org.xwiki.android.test.org.xwiki.test.setup.Main?xpage=plain";
+ }
+
+ private String getDefaultStartCommand(int port, int stopPort, int rmiPort)
+ {
+ String startCommand = START_COMMAND;
+ if (startCommand == null) {
+ if (SystemUtils.IS_OS_WINDOWS) {
+ startCommand = String.format("cmd /c start_xwiki.bat %s %s", port, stopPort);
+ } else {
+ startCommand = String.format("sh -f start_xwiki.sh %s %s", port, stopPort);
+ }
+ } else {
+ startCommand = startCommand.replaceFirst(DEFAULT_PORT, String.valueOf(port));
+ startCommand = startCommand.replaceFirst(DEFAULT_STOPPORT, String.valueOf(stopPort));
+ startCommand = startCommand.replaceFirst(DEFAULT_RMIPORT, String.valueOf(rmiPort));
+ }
+
+ return startCommand;
+ }
+
+ private String getDefaultStopCommand(int stopPort)
+ {
+ String stopCommand = STOP_COMMAND;
+ if (stopCommand == null) {
+ if (SystemUtils.IS_OS_WINDOWS) {
+ stopCommand = String.format("cmd /c stop_xwiki.bat %s", stopPort);
+ } else {
+ stopCommand = String.format("sh -f stop_xwiki.sh %s", stopPort);
+ }
+ } else {
+ stopCommand = stopCommand.replaceFirst(DEFAULT_STOPPORT, String.valueOf(stopPort));
+ }
+
+ return stopCommand;
+ }
+}
\ No newline at end of file
diff --git a/xwiki-android-test-fixture-teardown/test/org/xwiki/android/test/fixture/ServerShutdownTest.java b/xwiki-android-test-fixture-teardown/test/org/xwiki/android/test/fixture/ServerShutdownTest.java
new file mode 100644
index 0000000..a3e34d6
--- /dev/null
+++ b/xwiki-android-test-fixture-teardown/test/org/xwiki/android/test/fixture/ServerShutdownTest.java
@@ -0,0 +1,53 @@
+package org.xwiki.android.test.fixture;
+
+
+import junit.framework.AssertionFailedError;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.xwiki.android.test.fixture.teardown.env.TestEnv;
+import org.xwiki.test.integration.XWikiExecutor;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: sasindap
+ * Date: 8/10/12
+ * Time: 10:13 AM
+ * To change this template use File | Settings | File Templates.
+ */
+
+public class ServerShutdownTest extends Assert {
+ Logger logger= LoggerFactory.getLogger(ServerShutdownTest.class.getSimpleName());
+
+ XWikiExecutor exec;
+ boolean failed;
+
+ @Before
+ public void shutdownServer() {
+
+
+ exec = new XWikiExecutor(new Integer(System.getProperty("xwikiExecutionIndex")));
+
+ try {
+ exec.stop();
+ } catch (Exception e) {
+ throw new AssertionFailedError(e.getMessage());
+ }
+ }
+
+ @Test(expected = Exception.class)
+ public void shutdownProperly() throws Exception {
+ exec.isXWikiStarted(TestEnv.SERVER_URL, 1000);
+ }
+
+ @After
+ public void cleanup() throws Throwable {
+ logger.info("server shutdown. You can check out the pages , objects , etc created by the test cases by manually starting the server again." +
+ "\n please note that running tests on xwiki-androidt-test-fixtures-setup will clean up all above.");
+ }
+
+}
diff --git a/xwiki-android-test-fixture-teardown/test/org/xwiki/android/test/fixture/teardown/env/TestEnv.java b/xwiki-android-test-fixture-teardown/test/org/xwiki/android/test/fixture/teardown/env/TestEnv.java
new file mode 100644
index 0000000..c5b65ba
--- /dev/null
+++ b/xwiki-android-test-fixture-teardown/test/org/xwiki/android/test/fixture/teardown/env/TestEnv.java
@@ -0,0 +1,61 @@
+package org.xwiki.android.test.fixture.teardown.env;
+
+/**
+ * Environment variables for tests.
+ * How to setup external text setup.
+ */
+
+public class TestEnv {
+
+ public static final String DEFAULT_EXECUTION_DIRECTORY; //see static block to change default.
+ public static final int SERVER_INDEX;
+ public static final String HOST = "localhost";
+ public static final int PORT = 8080; //actual port is port+server_index
+ public static final String SERVER_URL; //SERVER NAME set in static block.
+ public static final String USERNAME = "Admin";
+ public static final String PASSWORD = "admin";
+
+ //external test fixture.
+
+ public static final String WIKI_NAME = "xwiki";
+
+ public static final String SPACE_NAME = "Blog";
+
+ public static final String PAGE_NAME = "test2";
+
+ public static final String PAGE_VERSION = "1.0";
+
+ public static final String COMMENT_ID = "0";
+ public static final String COMMENT_TEXT = "hi";
+ public static final String COMMENT_REPLY_ID = "1";
+ public static final int COMMENT_REPLY_REPLY_TO = 0;
+ public static final String COMMENT_REPLY_TEXT = "huy";
+
+
+ public static final String LANGUAGE = "null";
+
+ public static final String CLASS_NAME = "Blog.BlogPostClass";
+
+ public static final String OBJECT_NUMBER = "0";
+
+ public static final String OBJECT_PROPERTY_NAME = "content";
+ public static final String OBJECT_PROPERTY_VALUE = "test blog content";
+
+ public static final String SEARCH_KEWORD = "test";
+
+ public static final String TAG_WORD = "testTag";
+
+ public static final String ATTACHMENT_NAME = "a.png";
+
+ public static final String ATTACHMENT_PATH = "./";
+
+ public static final String ATTACHMENT_VERSION = "1.0";
+
+ static {
+ SERVER_INDEX = new Integer(System.getProperty("xwikiExecutionIndex", "0"));
+ DEFAULT_EXECUTION_DIRECTORY = System.getProperty("xwikiExecutionDirectory", "C:\\Users\\admin\\Desktop\\xwiki-enterprise-jetty");
+ SERVER_URL = HOST + ":" + (PORT + SERVER_INDEX);
+
+ }
+
+}
diff --git a/xwiki-android-test-rest/AndroidManifest.xml b/xwiki-android-test-rest/AndroidManifest.xml
index c8b78b0..77b55f5 100644
--- a/xwiki-android-test-rest/AndroidManifest.xml
+++ b/xwiki-android-test-rest/AndroidManifest.xml
@@ -8,13 +8,6 @@
-
-
-
-
-
-
diff --git a/xwiki-android-test-rest/project.properties b/xwiki-android-test-rest/project.properties
index 323b6c5..53844ab 100644
--- a/xwiki-android-test-rest/project.properties
+++ b/xwiki-android-test-rest/project.properties
@@ -10,6 +10,7 @@
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-android.library.reference.1=../xwiki-android-rest
# Project target.
-target=Google Inc.:Google APIs:7
+target=android-7
+android.library.reference.1=../xwiki-android-rest
+
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/AttachmentTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/AttachmentTest.java
index adefc43..f82d391 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/AttachmentTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/AttachmentTest.java
@@ -20,15 +20,18 @@
package org.xwiki.android.test.rest;
+import java.io.InputStream;
+
import org.xwiki.android.resources.Attachments;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
public class AttachmentTest extends AndroidTestCase
{
- private String wikiName, spaceName, pageName, url, username, password, version, filePath, attachmentName,
- attachmentVersion;
+ private String wikiName, spaceName, pageName, url, username, password, pageVersion, filePath, attachmentName,
+ attachmentVersion,attachmentDelName;
private boolean isSecured = true;
@@ -38,18 +41,19 @@ public class AttachmentTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- spaceName = TestResources.SPACE_NAME;
- pageName = TestResources.PAGE_NAME;
- url = TestResources.URL;
- version = TestResources.PAGE_VERSION;
- attachmentName = TestResources.ATTACHMENT_NAME;
- filePath = TestResources.ATTACHMENT_PATH;
- attachmentVersion = TestResources.ATTACHMENT_VERSION;
+ wikiName = TestConstants.WIKI_NAME;
+ spaceName = TestConstants.SPACE_NAME;
+ pageName = TestConstants.PAGE_NAME;
+ url = TestConstants.SERVER_URL;
+ pageVersion = TestConstants.ATTACHMENT_PAGE_HISTORY_VERSION;
+ attachmentName = TestConstants.ATTACHMENT_NAME;
+ filePath = TestConstants.ATTACHMENT_PATH;
+ attachmentVersion = TestConstants.ATTACHMENT_VERSION;
+ attachmentDelName= TestConstants.ATTACHMENT_DEL_NAME;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
@@ -79,22 +83,22 @@ public void testAddPageAttachment() throws Throwable
public void testDeletePageAttachment() throws Throwable
{
- String s = request.deletePageAttachment(wikiName, spaceName, pageName, attachmentName);
+ String s = request.deletePageAttachment(wikiName, spaceName, pageName, attachmentDelName);
assertNotNull(s);
}
public void testRequestPageAttchmentsInHistory() throws Throwable
{
- Attachments attachments = request.requestPageAttachmentsInHistory(wikiName, spaceName, pageName, version);
+ Attachments attachments = request.requestPageAttachmentsInHistory(wikiName, spaceName, pageName, pageVersion);
assertNotNull(attachments);
}
- // public void testRequestPageAttachmentInHistory() throws Throwable
- // {
- // InputStream inputStream =
- // request.requestPageAttachmentsInHistory(wikiName, spaceName, pageName, version, attachmentName);
- // assertNotNull(inputStream);
- // }
+// public void testRequestPageAttachmentInHistory() throws Throwable
+// {
+// InputStream inputStream =
+// request.requestPageAttachmentsInHistory(wikiName, spaceName, pageName, pageVersion, attachmentName);
+// assertNotNull(inputStream);
+// } // this test is not working in xwiki 3.5.1. Server Error.
public void testRequestPageAttchmentsInAttachmentHistory() throws Throwable
{
@@ -103,12 +107,12 @@ public void testRequestPageAttchmentsInAttachmentHistory() throws Throwable
assertNotNull(attachments);
}
- // public void testRequestPageAttachmentInAttachmentHistory() throws Throwable
- // {
- // InputStream inputStream =
- // request.requestPageAttachmentsInAttachmentHistory(wikiName, spaceName, pageName, attachmentName,
- // attachmentVersion);
- // assertNotNull(inputStream);
- // }
+ public void testRequestPageAttachmentInAttachmentHistory() throws Throwable
+ {
+ InputStream inputStream =
+ request.requestPageAttachmentsInAttachmentHistory(wikiName, spaceName, pageName, attachmentName,
+ attachmentVersion);
+ assertNotNull(inputStream);
+ }
}
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/ClassTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/ClassTest.java
index 161aaf4..6f916b6 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/ClassTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/ClassTest.java
@@ -23,6 +23,7 @@
import org.xwiki.android.resources.Class;
import org.xwiki.android.resources.Classes;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -38,13 +39,13 @@ public class ClassTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- url = TestResources.URL;
- classname = TestResources.CLASS_NAME;
+ wikiName = TestConstants.WIKI_NAME;
+ url = TestConstants.SERVER_URL;
+ classname = TestConstants.CLASS_NAME;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/CommentsTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/CommentsTest.java
index a9c96d6..57b027d 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/CommentsTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/CommentsTest.java
@@ -23,6 +23,7 @@
import org.xwiki.android.resources.Comment;
import org.xwiki.android.resources.Comments;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -38,16 +39,16 @@ public class CommentsTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- spaceName = TestResources.SPACE_NAME;
- pageName = TestResources.PAGE_NAME;
- url = TestResources.URL;
- commentId = TestResources.COMMENT_ID;
- version = TestResources.PAGE_VERSION;
+ wikiName = TestConstants.WIKI_NAME;
+ spaceName = TestConstants.SPACE_NAME;
+ pageName = TestConstants.PAGE_NAME;
+ url = TestConstants.SERVER_URL;
+ commentId = TestConstants.COMMENT_ID;
+ version = TestConstants.COMMENT_PAGE_HISTORY_VERSION;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
@@ -86,7 +87,7 @@ public void testRequestCommentsInHistoryWithID() throws Throwable
public void testAddComment() throws Throwable
{
Comment comment = new Comment();
- comment.setText("This is tesing comment in android rest");
+ comment.setText("This is tesing comment in android xmlrpc");
String s = request.addPageComment(wikiName, spaceName, pageName, comment);
assertNotNull(s);
}
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/HistoryTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/HistoryTest.java
index f3fc012..da8968d 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/HistoryTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/HistoryTest.java
@@ -22,6 +22,7 @@
import org.xwiki.android.resources.History;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -37,15 +38,15 @@ public class HistoryTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- spaceName = TestResources.SPACE_NAME;
- pageName = TestResources.PAGE_NAME;
- url = TestResources.URL;
- language = TestResources.LANGUAGE;
+ wikiName = TestConstants.WIKI_NAME;
+ spaceName = TestConstants.SPACE_NAME;
+ pageName = TestConstants.PAGE_NAME;
+ url = TestConstants.SERVER_URL;
+ language = TestConstants.LANGUAGE;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/ObjectTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/ObjectTest.java
index cebfc3a..a38589e 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/ObjectTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/ObjectTest.java
@@ -26,6 +26,7 @@
import org.xwiki.android.resources.Properties;
import org.xwiki.android.resources.Property;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -41,17 +42,17 @@ public class ObjectTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- spaceName = TestResources.SPACE_NAME;
- pageName = TestResources.PAGE_NAME;
- url = TestResources.URL;
- classname = TestResources.CLASS_NAME;
- objectNo = TestResources.OBJECT_NUMBER;
- propertyName = TestResources.OBJECT_PROPERTY_NAME;
+ wikiName = TestConstants.WIKI_NAME;
+ spaceName = TestConstants.SPACE_NAME;
+ pageName = TestConstants.PAGE_NAME;
+ url = TestConstants.SERVER_URL;
+ classname = TestConstants.CLASS_NAME;
+ objectNo = TestConstants.OBJECT_NUMBER;
+ propertyName = TestConstants.OBJECT_PROPERTY_NAME;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/PageTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/PageTest.java
index f604ff9..7e28965 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/PageTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/PageTest.java
@@ -23,12 +23,13 @@
import org.xwiki.android.resources.Page;
import org.xwiki.android.resources.Pages;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
public class PageTest extends AndroidTestCase
{
- private String wikiName, spaceName, pageName, url, username, password, language, version;
+ private String wikiName, spaceName, pageName, url, username, password, language, pageVersion,translationVersion;
private boolean isSecured = true;
@@ -38,16 +39,17 @@ public class PageTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- spaceName = TestResources.SPACE_NAME;
- pageName = TestResources.PAGE_NAME;
- url = TestResources.URL;
- language = TestResources.LANGUAGE;
- version = TestResources.PAGE_VERSION;
+ wikiName = TestConstants.WIKI_NAME;
+ spaceName = TestConstants.SPACE_NAME;
+ pageName = TestConstants.PAGE_NAME;
+ url = TestConstants.SERVER_URL;
+ language = TestConstants.LANGUAGE;
+ pageVersion = TestConstants.PAGE_VERSION;
+ translationVersion= TestConstants.TRANSLATION_VERSION;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
@@ -86,7 +88,7 @@ public void testRequestPageChildren() throws Throwable
public void testRequestPageInVersionHistory() throws Throwable
{
- Page page = request.requestPageInVersionHistory(wikiName, spaceName, pageName, version);
+ Page page = request.requestPageInVersionHistory(wikiName, spaceName, pageName, pageVersion);
assertNotNull(page);
}
@@ -98,7 +100,7 @@ public void testRequestPageTranslation() throws Throwable
public void testRequestPageTranslationInHistory() throws Throwable
{
- Page page = request.requestPageTranslationInHistory(wikiName, spaceName, pageName, language, version);
+ Page page = request.requestPageTranslationInHistory(wikiName, spaceName, pageName, language, translationVersion);
assertNotNull(page);
}
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/SearchTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/SearchTest.java
index ff8435f..62e7a3e 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/SearchTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/SearchTest.java
@@ -22,6 +22,7 @@
import org.xwiki.android.resources.SearchResults;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -37,14 +38,14 @@ public class SearchTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- spaceName = TestResources.SPACE_NAME;
- url = TestResources.URL;
- keyword = TestResources.SEARCH_KEWORD;
+ wikiName = TestConstants.WIKI_NAME;
+ spaceName = TestConstants.SPACE_NAME;
+ url = TestConstants.SERVER_URL;
+ keyword = TestConstants.SEARCH_KEWORD;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/SpaceTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/SpaceTest.java
index d71b2fb..df37d36 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/SpaceTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/SpaceTest.java
@@ -22,6 +22,7 @@
import org.xwiki.android.resources.Spaces;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -37,12 +38,12 @@ public class SpaceTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- url = TestResources.URL;
+ wikiName = TestConstants.WIKI_NAME;
+ url = TestConstants.SERVER_URL;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TagTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TagTest.java
index 66f6a33..fee8ac5 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TagTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TagTest.java
@@ -23,6 +23,7 @@
import org.xwiki.android.resources.Tag;
import org.xwiki.android.resources.Tags;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -38,15 +39,15 @@ public class TagTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- spaceName = TestResources.SPACE_NAME;
- pageName = TestResources.PAGE_NAME;
- url = TestResources.URL;
- tagText = TestResources.TAG_WORD;
+ wikiName = TestConstants.WIKI_NAME;
+ spaceName = TestConstants.SPACE_NAME;
+ pageName = TestConstants.PAGE_NAME;
+ url = TestConstants.SERVER_URL;
+ tagText = TestConstants.TAG_WORD;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TestResources.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TestResources.java
deleted file mode 100644
index 5533d6c..0000000
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TestResources.java
+++ /dev/null
@@ -1,58 +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 org.xwiki.android.test.rest;
-
-public class TestResources
-{
- public static final String WIKI_NAME = "xwiki";
-
- public static final String SPACE_NAME = "Blog";
-
- public static final String PAGE_NAME = "test2";
-
- public static final String URL = "10.0.2.2:8080";
-
- public static final String USERNAME = "superadmin";
-
- public static final String PASSWORD = "admin";
-
- public static final String PAGE_VERSION = "1.0";
-
- public static final String COMMENT_ID = "0";
-
- public static final String LANGUAGE = "null";
-
- public static final String CLASS_NAME = "Blog.BlogPostClass";
-
- public static final String OBJECT_NUMBER = "0";
-
- public static final String OBJECT_PROPERTY_NAME = "content";
-
- public static final String SEARCH_KEWORD = "test";
-
- public static final String TAG_WORD = "testTag";
-
- public static final String ATTACHMENT_NAME = "a.png";
-
- public static final String ATTACHMENT_PATH = "/sdcard/";
-
- public static final String ATTACHMENT_VERSION = "1.0";
-}
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TranslationTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TranslationTest.java
index 0f35151..f9ec118 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TranslationTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/TranslationTest.java
@@ -22,6 +22,7 @@
import org.xwiki.android.resources.Translations;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -37,14 +38,14 @@ public class TranslationTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- wikiName = TestResources.WIKI_NAME;
- spaceName = TestResources.SPACE_NAME;
- pageName = TestResources.PAGE_NAME;
- url = TestResources.URL;
+ wikiName = TestConstants.WIKI_NAME;
+ spaceName = TestConstants.SPACE_NAME;
+ pageName = TestConstants.PAGE_NAME;
+ url = TestConstants.SERVER_URL;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/WikiTest.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/WikiTest.java
index 96e905e..dcfb8fd 100644
--- a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/WikiTest.java
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/WikiTest.java
@@ -22,6 +22,7 @@
import org.xwiki.android.resources.Wikis;
import org.xwiki.android.rest.Requests;
+import org.xwiki.android.test.rest.env.TestConstants;
import android.test.AndroidTestCase;
@@ -37,11 +38,11 @@ public class WikiTest extends AndroidTestCase
protected void setUp() throws Exception
{
super.setUp();
- url = TestResources.URL;
+ url = TestConstants.SERVER_URL;
if (isSecured) {
- username = TestResources.USERNAME;
- password = TestResources.PASSWORD;
+ username = TestConstants.USERNAME;
+ password = TestConstants.PASSWORD;
}
request = new Requests(url);
diff --git a/xwiki-android-test-rest/src/org/xwiki/android/test/rest/env/TestConstants.java b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/env/TestConstants.java
new file mode 100644
index 0000000..4143ef9
--- /dev/null
+++ b/xwiki-android-test-rest/src/org/xwiki/android/test/rest/env/TestConstants.java
@@ -0,0 +1,62 @@
+package org.xwiki.android.test.rest.env;
+
+/**
+ * Environment variables for tests.
+ * How to setup external text setup.
+ */
+
+public class TestConstants {
+
+ public static final int SERVER_INDEX; //not used.
+ public static final String HOST = "10.0.2.2";
+ public static final int PORT = 8080; //actual port is port+server_index
+ public static final String SCHEME="http://";
+ public static final String SERVER_URL; //SERVER NAME set in static block.
+ public static final String USERNAME = "Admin";
+ public static final String PASSWORD = "admin";
+
+ //external test fixture.
+
+ public static final String WIKI_NAME = "xwiki";
+
+ public static final String SPACE_NAME = "Blog";
+
+ public static final String PAGE_NAME = "test2";
+
+ public static final String PAGE_VERSION = "1.1";
+
+ public static final String COMMENT_ID = "0";
+ public static final String COMMENT_TEXT = "hi";
+ public static final String COMMENT_REPLY_ID = "1";
+ public static final int COMMENT_REPLY_REPLY_TO = 0;
+ public static final String COMMENT_PAGE_HISTORY_VERSION="5.1";
+ public static final String COMMENT_REPLY_TEXT = "huy";
+
+
+ public static final String LANGUAGE = "fr";
+ public static final String TRANSLATION_VERSION="2.1";
+
+ public static final String CLASS_NAME = "Blog.BlogPostClass";
+ public static final String OBJECT_NUMBER = "0";
+ public static final String OBJECT_PROPERTY_NAME = "content";
+ public static final String OBJECT_PROPERTY_VALUE = "test blog content";
+
+ public static final String SEARCH_KEWORD = "test";
+
+ public static final String TAG_WORD = "testTag";
+
+ public static final String ATTACHMENT_NAME = "a.png";
+ public static final String ATTACHMENT_DEL_NAME = "del.png";
+ public static final String ATTACHMENT_PATH = "./";
+ public static final String ATTACHMENT_VERSION = "1.1";
+ public static final String ATTACHMENT_PAGE_HISTORY_VERSION = "9.1";
+
+ static {
+ SERVER_INDEX = new Integer(System.getProperty("xwikiExecutionIndex", "0"));
+ SERVER_URL = HOST + ":" + (PORT + SERVER_INDEX);
+ if(HOST.contains("localhost")){
+ System.err.println("localhost on android means devices interface card!!!");
+ }
+ }
+
+}
diff --git a/xwiki-android-tests-instrumentation/AndroidManifest.xml b/xwiki-android-tests-instrumentation/AndroidManifest.xml
index 6d3f5ab..94e3e1b 100644
--- a/xwiki-android-tests-instrumentation/AndroidManifest.xml
+++ b/xwiki-android-tests-instrumentation/AndroidManifest.xml
@@ -7,7 +7,7 @@
-
diff --git a/xwiki-android-tests-instrumentation/project.properties b/xwiki-android-tests-instrumentation/project.properties
index 192ff3d..6d257c7 100644
--- a/xwiki-android-tests-instrumentation/project.properties
+++ b/xwiki-android-tests-instrumentation/project.properties
@@ -10,8 +10,10 @@
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-android.library.reference.1=..\\xwiki-android-rest
-android.library.reference.2=..\\xwiki-android-components
# Project target.
-target=Google Inc.:Google APIs:7
+target=android-7
+android.library.reference.1=../xwiki-android-rest
+android.library.reference.2=../xwiki-android-components
android.library.reference.3=../xwiki-android-core
+
+
diff --git a/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestConstants.java b/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestConstants.java
new file mode 100644
index 0000000..0e99e07
--- /dev/null
+++ b/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestConstants.java
@@ -0,0 +1,66 @@
+package org.xwiki.android.tests;
+
+/**
+ * Environment variables for tests.
+ * How to setup external text setup.
+ */
+
+public class TestConstants {
+
+ public static final String DEFAULT_EXECUTION_DIRECTORY; //see static block to change default.
+ public static final int SERVER_INDEX;
+ public static final String HOST = "10.0.2.2"; // do not put local host as this is run on AVD. It'll call AVDs nic.
+ public static final int PORT = 8080; //actual port is port+server_index
+ public static final String SERVER_URL; //SERVER NAME set in static block.
+ public static final String USERNAME = "Admin";
+ public static final String PASSWORD = "admin";
+
+ //external test fixture.
+
+ public static final String WIKI_NAME = "xwiki";
+
+ public static final String SPACE_NAME = "Blog";
+
+ public static final String PAGE_NAME = "test2";
+
+ public static final String PAGE_VERSION = "1.1";
+
+ public static final String COMMENT_ID = "0";
+ public static final String COMMENT_TEXT = "hi";
+ public static final String COMMENT_REPLY_ID = "1";
+ public static final int COMMENT_REPLY_REPLY_TO = 0;
+ public static final String COMMENT_PAGE_HISTORY_VERSION="5.1";
+ public static final String COMMENT_REPLY_TEXT = "huy";
+
+
+ public static final String LANGUAGE = "fr";
+ public static final String TRANSLATION_VERSION="2.1";
+
+ public static final String CLASS_NAME = "Blog.BlogPostClass";
+ public static final String OBJECT_NUMBER = "0";
+ public static final String OBJECT_PROPERTY_NAME = "content";
+ public static final String OBJECT_PROPERTY_VALUE = "test blog content";
+
+ public static final String SEARCH_KEWORD = "test";
+
+ public static final String TAG_WORD = "testTag";
+
+ public static final String ATTACHMENT_NAME = "a.png";
+ public static final String ATTACHMENT_DEL_NAME = "del.png";
+ public static final String ATTACHMENT_PATH = "./";
+ public static final String ATTACHMENT_VERSION = "1.1";
+ public static final String ATTACHMENT_PAGE_HISTORY_VERSION = "9.1";
+
+ static {
+ SERVER_INDEX = new Integer(System.getProperty("xwikiExecutionIndex", "0"));
+ DEFAULT_EXECUTION_DIRECTORY = System.getProperty("xwikiExecutionDirectory", "C:\\Users\\admin\\Desktop\\xwiki-enterprise-jetty");
+ SERVER_URL = HOST + ":" + (PORT + SERVER_INDEX);
+ if(System.getProperty("xwikiExecutionDirectory"+SERVER_INDEX)==null){
+ System.out.println("xwiki execution dir:"+ DEFAULT_EXECUTION_DIRECTORY +" index: "+SERVER_INDEX + " server Url: "+SERVER_URL);
+ }else{
+ System.out.println("xwiki execution dir:"+ System.getProperty("xwikiExecutionDirectory"+SERVER_INDEX) +" index: "+SERVER_INDEX + " server Url: "+SERVER_URL);
+ }
+ System.setProperty("xwikiExecutionDirectory", DEFAULT_EXECUTION_DIRECTORY);//set it up to default val above, if not set by pom.else rewrite.
+ }
+
+}
diff --git a/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestResources.java b/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestResources.java
deleted file mode 100644
index 2801234..0000000
--- a/xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestResources.java
+++ /dev/null
@@ -1,58 +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 org.xwiki.android.tests;
-
-public class TestResources
-{
- public static final String WIKI_NAME = "xwiki";
-
- public static final String SPACE_NAME = "Blog";
-
- public static final String PAGE_NAME = "test2";
-
- public static final String URL = "10.0.2.2:8080";
-
- public static final String USERNAME = "Admin";
-
- public static final String PASSWORD = "admin";
-
- public static final String PAGE_VERSION = "1.0";
-
- public static final String COMMENT_ID = "0";
-
- public static final String LANGUAGE = "null";
-
- public static final String CLASS_NAME = "Blog.BlogPostClass";
-
- public static final String OBJECT_NUMBER = "0";
-
- public static final String OBJECT_PROPERTY_NAME = "content";
-
- public static final String SEARCH_KEWORD = "test";
-
- public static final String TAG_WORD = "testTag";
-
- public static final String ATTACHMENT_NAME = "a.png";
-
- public static final String ATTACHMENT_PATH = "/sdcard/";
-
- public static final String ATTACHMENT_VERSION = "1.0";
-}
diff --git a/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Comments.java b/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Comments.java
index a178d5d..0d3a94c 100644
--- a/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Comments.java
+++ b/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Comments.java
@@ -51,7 +51,7 @@
@Namespace(reference = "http://www.xwiki.org")
public class Comments // extends LinkCollection
{
- @ElementList(name = "comment", inline = true)
+ @ElementList(name = "comment", inline = true , required=false)
public List comments;
/**
diff --git a/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Properties.java b/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Properties.java
index 1eecaab..710b211 100644
--- a/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Properties.java
+++ b/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Properties.java
@@ -49,7 +49,7 @@
@Root
@Namespace(reference = "http://www.xwiki.org")
-public class Properties
+public class Properties extends LinkCollection
{
@ElementList(name = "property", inline = true)