From b27bcff5334870f208a01b6ac44cbbb29a42455c Mon Sep 17 00:00:00 2001 From: sasinda Date: Tue, 14 Aug 2012 22:23:33 +0530 Subject: [PATCH] added J2SE module to start up server, setup external fixture another module to shutdown server and teardown ext fixture. bug fixes and feature additions to ral. --- .gitignore | 5 +- pom.xml | 249 ++++++--- xwiki-android-client/AndroidManifest.xml | 2 +- xwiki-android-client/project.properties | 7 +- xwiki-android-components/project.properties | 2 + .../res/values/strings.xml | 2 +- xwiki-android-core/pom.xml | 1 + xwiki-android-core/project.properties | 1 + .../context/XWikiApplicationContext.java | 3 +- .../xwiki/android/rest/ral/DocumentRao.java | 8 + .../android/rest/ral/RESTfulManager.java | 9 + .../src/org/xwiki/android/rest/ral/Rao.java | 2 + .../xwiki/android/rest/ral/RaoException.java | 41 ++ .../org/xwiki/android/rest/ral/Verifier.java | 33 ++ .../android/rest/ral/XmlDocumentRao.java | 55 +- .../android/rest/ral/XmlRESTFulManager.java | 29 + .../rest/ral/algo/DocRetreiveStrategy.java | 8 +- .../rest/ral/algo/DocUpdateStrategy.java | 18 +- .../rest/reference/DocumentReference.java | 2 +- .../transformation/DocLaunchPadForXML.java | 10 +- .../transformation/DocumentBuilder_XML.java | 16 +- .../DocumentDismantler_XML.java | 12 +- .../transformation/XModelTranslator_XML.java | 88 ++-- .../rest/transformation/XObjectFactory.java | 2 +- .../android/xmodel/entity/Attachment.java | 14 + .../xwiki/android/xmodel/entity/Comment.java | 292 ++++++---- .../xwiki/android/xmodel/entity/Document.java | 162 +++++- .../android/xmodel/entity/DocumentBase.java | 19 +- .../android/xmodel/xobjects/XComment.java | 1 + .../xmodel/xobjects/XPropertyBase.java | 6 +- .../xmodel/xobjects/XSimpleObject.java | 8 +- xwiki-android-rest/res/values/strings.xml | 2 +- .../xwiki/android/rest/CommentResources.java | 41 +- .../org/xwiki/android/rest/HttpConnector.java | 18 +- .../xwiki/android/rest/ObjectResources.java | 68 ++- .../src/org/xwiki/android/rest/Requests.java | 90 ++-- .../xwiki/android/rest/RestConnection.java | 8 + .../Upgrade Http Connector, RestConnection | 100 ++++ .../{XWikiRestfulAPI.java => XWikiAPI.java} | 48 +- ...Connector.java => XWikiRestConnecion.java} | 174 +++--- xwiki-android-test-core/AndroidManifest.xml | 26 + xwiki-android-test-core/pom.xml | 70 +++ xwiki-android-test-core/proguard-project.txt | 20 + xwiki-android-test-core/project.properties | 16 + .../res/drawable-hdpi/ic_launcher.png | Bin 0 -> 9397 bytes .../res/drawable-ldpi/ic_launcher.png | Bin 0 -> 2729 bytes .../res/drawable-mdpi/ic_launcher.png | Bin 0 -> 5237 bytes .../res/drawable-xhdpi/ic_launcher.png | Bin 0 -> 14383 bytes .../res/values/strings.xml | 6 + .../org/xwiki/android/core/test/AllTests.java | 36 ++ .../xwiki/android/core/test/TestTemplate.java | 86 +++ .../android/core/test/properties/Env.java | 40 ++ .../rest/ral/test/TestDocumentRaoCreate.java | 270 ++++++++++ .../rest/ral/test/TestDocumentRaoDelete.java | 78 +++ .../ral/test/TestDocumentRaoRetreive.java | 102 ++++ .../rest/ral/test/TestDocumentRaoUpdate.java | 99 ++++ xwiki-android-test-fixture-setup/pom.xml | 127 +++++ .../resources/a.png | Bin 0 -> 261 bytes .../resources/del.png | Bin 0 -> 16900 bytes .../resources/log4j.properties | 7 + .../org/xwiki/android/test/fixture/Main.java | 23 + .../utils/xmlrpc/AttachmentOperations.java | 251 +++++++++ .../test/utils/xmlrpc/CommentOperations.java | 260 +++++++++ .../test/utils/xmlrpc/ObjectOperations.java | 414 +++++++++++++++ .../test/utils/xmlrpc/PageOperations.java | 346 ++++++++++++ .../android/test/utils/xmlrpc/RestClient.java | 436 +++++++++++++++ .../test/utils/xmlrpc/RestException.java | 69 +++ .../test/utils/xmlrpc/SpaceOperations.java | 129 +++++ .../test/utils/xmlrpc/TagOperations.java | 221 ++++++++ .../utils/xmlrpc/TranslationOperations.java | 137 +++++ .../integration/utils/AntBuildListener.java | 85 +++ .../test/integration/utils/XWikiExecutor.java | 498 ++++++++++++++++++ .../android/test/fixture/setup/AllTests.java | 20 + .../test/fixture/setup/ServerStartTest.java | 44 ++ .../test/fixture/setup/SetupTestPageTest.java | 178 +++++++ .../test/fixture/setup/env/TestEnv.java | 72 +++ xwiki-android-test-fixture-teardown/pom.xml | 76 +++ .../resources/log4j.properties | 7 + .../test/integration/AntBuildListener.java | 85 +++ .../xwiki/test/integration/XWikiExecutor.java | 491 +++++++++++++++++ .../test/fixture/ServerShutdownTest.java | 53 ++ .../test/fixture/teardown/env/TestEnv.java | 61 +++ xwiki-android-test-rest/AndroidManifest.xml | 7 - xwiki-android-test-rest/project.properties | 5 +- .../android/test/rest/AttachmentTest.java | 58 +- .../xwiki/android/test/rest/ClassTest.java | 11 +- .../xwiki/android/test/rest/CommentsTest.java | 19 +- .../xwiki/android/test/rest/HistoryTest.java | 15 +- .../xwiki/android/test/rest/ObjectTest.java | 19 +- .../org/xwiki/android/test/rest/PageTest.java | 24 +- .../xwiki/android/test/rest/SearchTest.java | 13 +- .../xwiki/android/test/rest/SpaceTest.java | 9 +- .../org/xwiki/android/test/rest/TagTest.java | 15 +- .../android/test/rest/TestResources.java | 58 -- .../android/test/rest/TranslationTest.java | 13 +- .../org/xwiki/android/test/rest/WikiTest.java | 7 +- .../android/test/rest/env/TestConstants.java | 62 +++ .../AndroidManifest.xml | 2 +- .../project.properties | 8 +- .../xwiki/android/tests/TestConstants.java | 66 +++ .../xwiki/android/tests/TestResources.java | 58 -- .../org/xwiki/android/resources/Comments.java | 2 +- .../xwiki/android/resources/Properties.java | 2 +- 103 files changed, 6368 insertions(+), 700 deletions(-) create mode 100644 xwiki-android-core/src/org/xwiki/android/rest/ral/Verifier.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/RestConnection.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/Upgrade Http Connector, RestConnection rename xwiki-android-rest/src/org/xwiki/android/rest/{XWikiRestfulAPI.java => XWikiAPI.java} (92%) rename xwiki-android-rest/src/org/xwiki/android/rest/{XWikiRestConnector.java => XWikiRestConnecion.java} (80%) create mode 100644 xwiki-android-test-core/AndroidManifest.xml create mode 100644 xwiki-android-test-core/pom.xml create mode 100644 xwiki-android-test-core/proguard-project.txt create mode 100644 xwiki-android-test-core/project.properties create mode 100644 xwiki-android-test-core/res/drawable-hdpi/ic_launcher.png create mode 100644 xwiki-android-test-core/res/drawable-ldpi/ic_launcher.png create mode 100644 xwiki-android-test-core/res/drawable-mdpi/ic_launcher.png create mode 100644 xwiki-android-test-core/res/drawable-xhdpi/ic_launcher.png create mode 100644 xwiki-android-test-core/res/values/strings.xml create mode 100644 xwiki-android-test-core/src/org/xwiki/android/core/test/AllTests.java create mode 100644 xwiki-android-test-core/src/org/xwiki/android/core/test/TestTemplate.java create mode 100644 xwiki-android-test-core/src/org/xwiki/android/core/test/properties/Env.java create mode 100644 xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoCreate.java create mode 100644 xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoDelete.java create mode 100644 xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoRetreive.java create mode 100644 xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoUpdate.java create mode 100644 xwiki-android-test-fixture-setup/pom.xml create mode 100644 xwiki-android-test-fixture-setup/resources/a.png create mode 100644 xwiki-android-test-fixture-setup/resources/del.png create mode 100644 xwiki-android-test-fixture-setup/resources/log4j.properties create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/fixture/Main.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/AttachmentOperations.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/CommentOperations.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/ObjectOperations.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/PageOperations.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/RestClient.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/RestException.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/SpaceOperations.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/TagOperations.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/android/test/utils/xmlrpc/TranslationOperations.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/AntBuildListener.java create mode 100644 xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/XWikiExecutor.java create mode 100644 xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/AllTests.java create mode 100644 xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/ServerStartTest.java create mode 100644 xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/SetupTestPageTest.java create mode 100644 xwiki-android-test-fixture-setup/test/org/xwiki/android/test/fixture/setup/env/TestEnv.java create mode 100644 xwiki-android-test-fixture-teardown/pom.xml create mode 100644 xwiki-android-test-fixture-teardown/resources/log4j.properties create mode 100644 xwiki-android-test-fixture-teardown/src/org/xwiki/test/integration/AntBuildListener.java create mode 100644 xwiki-android-test-fixture-teardown/src/org/xwiki/test/integration/XWikiExecutor.java create mode 100644 xwiki-android-test-fixture-teardown/test/org/xwiki/android/test/fixture/ServerShutdownTest.java create mode 100644 xwiki-android-test-fixture-teardown/test/org/xwiki/android/test/fixture/teardown/env/TestEnv.java delete mode 100644 xwiki-android-test-rest/src/org/xwiki/android/test/rest/TestResources.java create mode 100644 xwiki-android-test-rest/src/org/xwiki/android/test/rest/env/TestConstants.java create mode 100644 xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestConstants.java delete mode 100644 xwiki-android-tests-instrumentation/src/org/xwiki/android/tests/TestResources.java diff --git a/.gitignore b/.gitignore index 58c3a45..0eae072 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ # Build -target -*/target -target-eclipse +target/ +target-eclipse/ # IDEA *.iml diff --git a/pom.xml b/pom.xml index f339655..321fadf 100644 --- a/pom.xml +++ b/pom.xml @@ -22,72 +22,187 @@ --> - 4.0.0 - - org.xwiki.commons - xwiki-commons - 4.1.2 - - org.xwiki.android - xwiki-android - 1.0-SNAPSHOT - XWiki Android - Parent POM - pom - XWiki Android - Parent POM - - true - + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Test.java + + once + + + + + + xwikiExecutionDirectory + ${xwikiExecutionDirectory} + + + xwikiExecutionIndex + ${xwikiExecutionIndex} + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unzip-application + test-compile + + unpack + + + + + org.xwiki.enterprise + xwiki-enterprise-jetty-${xwiki.db} + ${xwiki.xe.version} + zip + + + ${xwikiExecutionDirectory}/../ + + ${xwiki.test.skipUnpack} + + + + + + + + + + + + true + - true - - - - xwiki-rest-model - xwiki-android-rest - xwiki-android-core - xwiki-android-components - xwiki-android-client - - xwiki-android-tests-instrumentation - - - - - com.google.android - android - 2.1.2 - provided - - - - - src - - - - com.jayway.maven.plugins.android.generation2 - android-maven-plugin - 3.3.0 - - - ${env.ANDROID_HOME} - 2.1 - - true - true - true - - - true - - - - - maven-compiler-plugin - 2.3.2 - - - - + true + + + + 8080 + 8079 + 6666 + 4444 + + + http://localhost + + false + + false + ${project.parent.basedir}/target/test-server/xwiki-enterprise-jetty-${xwiki.db}-${xwiki.xe.version} + 0 + + + + + hsqldb + + + true + + + 4.1.3 + hsqldb + org.hsqldb + hsqldb + 2.2.8 + + + + \ No newline at end of file diff --git a/xwiki-android-client/AndroidManifest.xml b/xwiki-android-client/AndroidManifest.xml index 2e433fc..e846ac8 100644 --- a/xwiki-android-client/AndroidManifest.xml +++ b/xwiki-android-client/AndroidManifest.xml @@ -20,7 +20,7 @@ android:icon="@drawable/icon" android:label="@string/app_name" > diff --git a/xwiki-android-client/project.properties b/xwiki-android-client/project.properties index ed15f33..ef59822 100644 --- a/xwiki-android-client/project.properties +++ b/xwiki-android-client/project.properties @@ -12,7 +12,8 @@ # Project target. target=android-7 - -android.library.reference.3=../xwiki-android-core android.library.reference.1=../xwiki-android-components -android.library.reference.2=../xwiki-android-rest +android.library.reference.2=../xwiki-android-core +android.library.reference.3=../xwiki-android-rest + + diff --git a/xwiki-android-components/project.properties b/xwiki-android-components/project.properties index caec599..3993eb0 100644 --- a/xwiki-android-components/project.properties +++ b/xwiki-android-components/project.properties @@ -14,3 +14,5 @@ android.library=true # Project target. target=android-7 android.library.reference.1=../xwiki-android-core +android.library.reference.2=../xwiki-android-rest + diff --git a/xwiki-android-components/res/values/strings.xml b/xwiki-android-components/res/values/strings.xml index 80ac9d4..52af792 100644 --- a/xwiki-android-components/res/values/strings.xml +++ b/xwiki-android-components/res/values/strings.xml @@ -1,6 +1,6 @@ - Hello World, Main! + Hello World, org.xwiki.android.test.org.xwiki.test.integration.Main! Xwiki Components No items xwikiNavigatorListClick diff --git a/xwiki-android-core/pom.xml b/xwiki-android-core/pom.xml index 887a553..7f8e9dd 100644 --- a/xwiki-android-core/pom.xml +++ b/xwiki-android-core/pom.xml @@ -33,6 +33,7 @@ xwiki-android-core apklib + 1.0-SNAPSHOT XWiki android core lib diff --git a/xwiki-android-core/project.properties b/xwiki-android-core/project.properties index 8dffb0e..62f1e5f 100644 --- a/xwiki-android-core/project.properties +++ b/xwiki-android-core/project.properties @@ -14,3 +14,4 @@ target=android-7 android.library=true android.library.reference.1=../xwiki-android-rest + diff --git a/xwiki-android-core/src/org/xwiki/android/context/XWikiApplicationContext.java b/xwiki-android-core/src/org/xwiki/android/context/XWikiApplicationContext.java index deac8ff..62e396c 100644 --- a/xwiki-android-core/src/org/xwiki/android/context/XWikiApplicationContext.java +++ b/xwiki-android-core/src/org/xwiki/android/context/XWikiApplicationContext.java @@ -105,7 +105,8 @@ public void updateToAuthenticatedState(User user) public static XWikiApplicationContext getInstance() { - return currContext; + if(currContext==null) throw new RuntimeException("please set XWikiApplicationContext in android manifest * doc.set("XOMyClass/0",o1) * the create method adds the same object twice to the remote page. * @param doc + * @return created document extracted from server. */ @Override public Document create(Document doc) throws RestConnectionException ,RaoException; + /** + * check wether the doc exists on server + * @param dref + * @return + */ + public boolean exists(DocumentReference dref) throws RestConnectionException,RaoException;; + /** * default semantics * diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/RESTfulManager.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/RESTfulManager.java index 45ff583..c35372f 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/RESTfulManager.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/RESTfulManager.java @@ -1,7 +1,11 @@ package org.xwiki.android.rest.ral; +import java.util.Properties; + import org.xwiki.android.resources.Space; import org.xwiki.android.resources.Wiki; +import org.xwiki.android.rest.RestConnection; +import org.xwiki.android.rest.XWikiAPI; import org.xwiki.android.xmodel.entity.Document; public interface RESTfulManager @@ -11,4 +15,9 @@ public interface RESTfulManager SpaceRao newSpaceRao(); WikiRao newWikiRao(); + + RestConnection getConnection(); + + + } diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/Rao.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/Rao.java index 2e2a7db..1ba04a2 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/Rao.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/Rao.java @@ -16,6 +16,8 @@ interface Rao { T create(T resrc) throws RestConnectionException,RaoException; + + boolean exists(T resrc) throws RestConnectionException,RaoException; T retreive(T resrc) throws RestConnectionException,RaoException; diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/RaoException.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/RaoException.java index 4a146cb..3421141 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/RaoException.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/RaoException.java @@ -1,5 +1,7 @@ package org.xwiki.android.rest.ral; +import org.xwiki.android.rest.RestException; + /** * @author xwiki gsoc 2012 For exceptional situations where client is doing some thing wrong due to lack of knowledge of * the remote servers state.Ex: Call to create a document that already exsist in the remote server. @@ -7,6 +9,9 @@ public class RaoException extends Exception { + private RestException cause; + private int code; + public RaoException() { super(); @@ -19,6 +24,13 @@ public RaoException(String detailMessage, Throwable throwable) // TODO Auto-generated constructor stub } + public RaoException(String detailMessage, RestException rex) + { + super(detailMessage, rex); + this.cause = rex; + this.code = rex.getCode(); + } + public RaoException(String detailMessage) { super(detailMessage); @@ -30,5 +42,34 @@ public RaoException(Throwable throwable) super(throwable); // TODO Auto-generated constructor stub } + + public RaoException(RestException rex) + { + super(rex); + this.cause = rex; + this.code = rex.getCode(); + } + + public RestException getCause() + { + return cause; + } + + public void setCause(RestException cause) + { + this.cause = cause; + } + + public int getCode() + { + return code; + } + + public void setCode(int code) + { + this.code = code; + } + + } diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/Verifier.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/Verifier.java new file mode 100644 index 0000000..b50bdd0 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/Verifier.java @@ -0,0 +1,33 @@ +package org.xwiki.android.rest.ral; + +import org.xwiki.android.xmodel.entity.Document; + +import android.util.Log; + +/** + * + * Verifiere to check parameters passed to each ral method. + * + */ +class Verifier +{ + + + + private static final String TAG ="RAL Verifier"; + + /** + * + * @param doc + * @return verification result. success=true + */ + static boolean verifyDocumentForCreate(Document doc){ + boolean title=false; //verify title set + title=(doc.getTitle()!=null & !doc.getTitle().equals("")); + if(!title){ + Log.w(TAG, "doc must have a title. For XWiki version 3.x and below."); + } + return title; + + } +} diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlDocumentRao.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlDocumentRao.java index ccc7159..4fecbc1 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlDocumentRao.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlDocumentRao.java @@ -11,12 +11,13 @@ import org.xwiki.android.context.UserSession; import org.xwiki.android.context.XWikiApplicationContext; +import org.xwiki.android.resources.Comment; import org.xwiki.android.resources.Object; import org.xwiki.android.resources.Page; import org.xwiki.android.rest.RestConnectionException; import org.xwiki.android.rest.RestException; -import org.xwiki.android.rest.XWikiRestConnector; -import org.xwiki.android.rest.XWikiRestfulAPI; +import org.xwiki.android.rest.XWikiRestConnecion; +import org.xwiki.android.rest.XWikiAPI; import org.xwiki.android.rest.ral.algo.DocRetreiveStrategy; import org.xwiki.android.rest.ral.algo.DocUpdateStrategy; import org.xwiki.android.rest.ral.algo.IDocRetreiveStrategy; @@ -44,14 +45,14 @@ class XmlDocumentRao implements DocumentRao private static int PAGE = DocumentDismantler_XML.PAGE; private static int OBJECTS = DocumentDismantler_XML.OBJECTS; private static int ALL = DocumentDismantler_XML.ALL; - private XWikiRestfulAPI api; + private XWikiAPI api; private IDocRetreiveStrategy retStr; private IDocUpdateStragegy updStr; public XmlDocumentRao(String serverUrl, String username, String password) { - api = new XWikiRestConnector(serverUrl, username, password); + api = new XWikiRestConnecion(serverUrl, username, password); retStr = new DocRetreiveStrategy(username, password, serverUrl); updStr = new DocUpdateStrategy(serverUrl, username, password); // consider IoC to app context @@ -63,6 +64,9 @@ public XmlDocumentRao(String serverUrl, String username, String password) @Override public Document create(Document doc) throws RestConnectionException, RaoException { + Verifier.verifyDocumentForCreate(doc);//just logs warn msgs if verification failed. Runtime exceptions will be thrown + //when server responds with errors. + // TODO: make advanced algo.Put it in ral.algo package. Here we use simple non parellal way to create doc. DocumentDismantler_XML con = new DocumentDismantler_XML(ALL); DocLaunchPadForXML pad = con.convertDocument(doc); @@ -92,7 +96,7 @@ public Index(int first, int last) } Map indexes=new HashMap(10);//for < 10 classes of objs. - Map edObjs = pad.getEditedObjects(); + Map edObjs = pad.getEditedObjects(); //objects added using set method. explicitly palced at smplObject.number A:for(String k: edObjs.keySet()){ String ss[]=k.split("/"); @@ -101,7 +105,7 @@ public Index(int first, int last) Index i= indexes.get(clsName); if(i==null){//new class obList.add(o); - int first=obList.size(); + int first=obList.size()-1; int last=first; indexes.put(clsName, new Index(first,last)); }else{ @@ -114,7 +118,7 @@ public Index(int first, int last) continue A; } } - obList.add(last+1,edObjs.get(k)); + obList.add(last+1,o); i.last++; } } @@ -126,7 +130,7 @@ public Index(int first, int last) Index i=indexes.get(clsName); if(i==null){//this is new object obList.add(o); - int first=obList.size(); + int first=obList.size()-1; int last=first; indexes.put(clsName, new Index(first, last)); }else{ @@ -154,7 +158,14 @@ public Index(int first, int last) //upload objects. for (Object object : obList) { api.addObject(wikiName, spaceName, pageName, object); - } + } + + List newCmnts=pad.getNewComments(); + List edCmnts=pad.getEditedComments(); + + + + return null; // TODO RET CREATED DOC. NEED TO ADD CUSTOMIZATION CODE WETHER TO RET OR NOT. } } catch (RestException e) { @@ -164,6 +175,28 @@ public Index(int first, int last) } } + + @Override + public boolean exists(Document doc) throws RestConnectionException, RaoException + { + String wikiName = doc.getWikiName(); + String spaceName = doc.getSpaceName(); + String pageName = doc.getPageName(); + boolean exists; + try { + exists=api.existsPage(wikiName, spaceName, pageName); + return exists; + } catch (RestException e) { + throw new RaoException(e); + } + } + + @Override + public boolean exists(DocumentReference dref) throws RestConnectionException, RaoException + { + // TODO Auto-generated method stub + return false; + } @Override public Document retreive(Document doc) throws RestConnectionException, RaoException @@ -224,4 +257,8 @@ public void delete(Document resrc) throws RestConnectionException, RaoException delete(resrc.getDocumentReference()); } + + + + } diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlRESTFulManager.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlRESTFulManager.java index b9e785d..f3d73cf 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlRESTFulManager.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/XmlRESTFulManager.java @@ -1,7 +1,12 @@ package org.xwiki.android.rest.ral; +import java.util.Properties; + import org.xwiki.android.resources.Space; import org.xwiki.android.resources.Wiki; +import org.xwiki.android.rest.RestConnection; +import org.xwiki.android.rest.XWikiAPI; +import org.xwiki.android.rest.XWikiRestConnecion; import org.xwiki.android.xmodel.entity.Document; public class XmlRESTFulManager implements RESTfulManager @@ -15,6 +20,22 @@ public XmlRESTFulManager(String serverUrl, String username, String password) this.username = username; this.password = password; } + + /** + * + * @param username + * @param password + * @param props additional properties. Like props to support OAuth when XWiki Servers support them and etc. + * + */ + + public XmlRESTFulManager(String serverUrl, String username, String password, Properties props) + { + this.serverUrl = serverUrl; + this.username = username; + this.password = password; + throw new UnsupportedOperationException("impl in future, when need arise for additional props for connection. Like OAuth etc..."); + } public DocumentRao newDocumentRao() { @@ -35,4 +56,12 @@ public WikiRao newWikiRao() } + @Override + public RestConnection getConnection() + { + return new XWikiRestConnecion(serverUrl,username,password); + } + + + } diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocRetreiveStrategy.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocRetreiveStrategy.java index d9b2479..845f4a5 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocRetreiveStrategy.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocRetreiveStrategy.java @@ -13,8 +13,8 @@ import org.xwiki.android.resources.Tags; import org.xwiki.android.rest.RestConnectionException; import org.xwiki.android.rest.RestException; -import org.xwiki.android.rest.XWikiRestConnector; -import org.xwiki.android.rest.XWikiRestfulAPI; +import org.xwiki.android.rest.XWikiRestConnecion; +import org.xwiki.android.rest.XWikiAPI; import org.xwiki.android.rest.ral.RaoException; import org.xwiki.android.rest.reference.DocumentReference; import org.xwiki.android.rest.transformation.DocumentBuilder; @@ -27,14 +27,14 @@ public class DocRetreiveStrategy implements IDocRetreiveStrategy String username; String password; String url; - XWikiRestfulAPI api; + XWikiAPI api; public DocRetreiveStrategy(String username, String password, String serverUrl) { this.username = username; this.password = password; this.url = serverUrl; - api=new XWikiRestConnector(url, username, password); + api=new XWikiRestConnecion(url, username, password); } @Override diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocUpdateStrategy.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocUpdateStrategy.java index 3712421..1a2df91 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocUpdateStrategy.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/DocUpdateStrategy.java @@ -8,8 +8,8 @@ import org.xwiki.android.resources.Tags; import org.xwiki.android.rest.RestConnectionException; import org.xwiki.android.rest.RestException; -import org.xwiki.android.rest.XWikiRestConnector; -import org.xwiki.android.rest.XWikiRestfulAPI; +import org.xwiki.android.rest.XWikiRestConnecion; +import org.xwiki.android.rest.XWikiAPI; import org.xwiki.android.rest.ral.RaoException; import org.xwiki.android.rest.transformation.DocLaunchPadForXML; import org.xwiki.android.rest.transformation.DocumentDismantler_XML; @@ -22,12 +22,12 @@ public class DocUpdateStrategy implements IDocUpdateStragegy { private static final String TAG = "DocUpdate"; - XWikiRestfulAPI api; + XWikiAPI api; DocumentDismantler_XML dismantler; public DocUpdateStrategy(String serverUrl, String username, String password) { - api = new XWikiRestConnector(serverUrl, username, password); + api = new XWikiRestConnecion(serverUrl, username, password); dismantler = new DocumentDismantler_XML(); } @@ -51,7 +51,7 @@ public Document update(Document d) throws RestConnectionException, RaoException String ss[] = key.split("/"); Object ores = e.getValue(); String objectClassname = ss[0]; - String objectNumber = ss[1]; + int objectNumber = new Integer(ss[1]); try { api.updateObject(wikiName, spaceName, pageName, objectClassname, objectNumber, ores); numEdObj++; // after the api op. If exception happens no ++ happens. @@ -89,11 +89,11 @@ public Document update(Document d) throws RestConnectionException, RaoException // edited comments // need to conver to objs. Direct editing is not currently supported in // xwiki restful api. - for (Object comment : pad.getEditedComments()) { - String objectClassname = comment.getClassName(); - String objectNumber = comment.getNumber() + ""; + for (Object cmntObj : pad.getEditedComments()) { + String objectClassname = cmntObj.getClassName(); + int objectNumber = cmntObj.getNumber(); try { - api.updateObject(wikiName, spaceName, pageName, objectClassname, objectNumber, comment); + api.updateObject(wikiName, spaceName, pageName, objectClassname, objectNumber, cmntObj); numEdCmnt++; } catch (RestException e1) { // TODO Auto-generated catch block diff --git a/xwiki-android-core/src/org/xwiki/android/rest/reference/DocumentReference.java b/xwiki-android-core/src/org/xwiki/android/rest/reference/DocumentReference.java index cb0ea5e..01cd647 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/reference/DocumentReference.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/reference/DocumentReference.java @@ -80,7 +80,7 @@ public void setPageName(String pageName) @Override public String getURL() { - return getAuthority() + "/xwiki/rest/wikis/" + wikiName + "/spaces" + spaceName + "/pages" + pageName; + return getAuthority() + "/xwiki/xmlrpc/wikis/" + wikiName + "/spaces" + spaceName + "/pages" + pageName; } } diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocLaunchPadForXML.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocLaunchPadForXML.java index 4a7068c..2d46924 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocLaunchPadForXML.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocLaunchPadForXML.java @@ -1,9 +1,11 @@ package org.xwiki.android.rest.transformation; import java.util.ArrayList; +import java.util.HashSet; import java.util.Hashtable; import java.util.List; import java.util.Map; +import java.util.Set; import org.xwiki.android.resources.Attachment; import org.xwiki.android.resources.Comment; @@ -30,8 +32,8 @@ public class DocLaunchPadForXML Tags tags; - List attatchmentsToupload;//new and update both. Same rest method. - List deletedAttachments; + List attatchmentsToupload;//new and update both. Same xmlrpc method. + Set deletedAttachments; public DocLaunchPadForXML() { @@ -43,7 +45,7 @@ public DocLaunchPadForXML() deletedComments=new ArrayList(); attatchmentsToupload=new ArrayList(); - deletedAttachments=new ArrayList(); + deletedAttachments=new HashSet(); } @@ -135,7 +137,7 @@ public List getAttatchmentsToupload( return attatchmentsToupload; } - public List getDeletedAttachments() + public Set getDeletedAttachments() { return deletedAttachments; } diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentBuilder_XML.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentBuilder_XML.java index 6dcb2c9..b41d37b 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentBuilder_XML.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentBuilder_XML.java @@ -106,7 +106,7 @@ private DocumentBuilder initWithPage(Page p) } /* (non-Javadoc) - * @see org.xwiki.android.rest.transformation.DocumentBuilder#withObject(org.xwiki.android.resources.Object) + * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#withObject(org.xwiki.android.resources.Object) */ @Override public DocumentBuilder withObject(Object res) @@ -146,7 +146,7 @@ public DocumentBuilder withObject(Object res) } /* (non-Javadoc) - * @see org.xwiki.android.rest.transformation.DocumentBuilder#withObjectSummary(org.xwiki.android.resources.ObjectSummary) + * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#withObjectSummary(org.xwiki.android.resources.ObjectSummary) */ @Override public DocumentBuilder withObjectSummary(ObjectSummary res) @@ -171,7 +171,7 @@ public DocumentBuilder withObjectSummary(ObjectSummary res) } /* (non-Javadoc) - * @see org.xwiki.android.rest.transformation.DocumentBuilder#withComments(org.xwiki.android.resources.Comments) + * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#withComments(org.xwiki.android.resources.Comments) */ @Override public DocumentBuilder withComments(Comments cmnts) @@ -183,7 +183,7 @@ public DocumentBuilder withComments(Comments cmnts) } /* (non-Javadoc) - * @see org.xwiki.android.rest.transformation.DocumentBuilder#withComment(org.xwiki.android.resources.Comment) + * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#withComment(org.xwiki.android.resources.Comment) */ @Override public DocumentBuilder withComment(Comment cmntRes) @@ -201,7 +201,7 @@ public DocumentBuilder withComment(Comment cmntRes) } /* (non-Javadoc) - * @see org.xwiki.android.rest.transformation.DocumentBuilder#withTags(org.xwiki.android.resources.Tags) + * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#withTags(org.xwiki.android.resources.Tags) */ @Override public DocumentBuilder withTags(Tags tags) @@ -214,7 +214,7 @@ public DocumentBuilder withTags(Tags tags) } /* (non-Javadoc) - * @see org.xwiki.android.rest.transformation.DocumentBuilder#withAttachments(org.xwiki.android.resources.Attachments) + * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#withAttachments(org.xwiki.android.resources.Attachments) */ @Override public DocumentBuilder withAttachments(Attachments attachments) @@ -226,7 +226,7 @@ public DocumentBuilder withAttachments(Attachments attachments) } /* (non-Javadoc) - * @see org.xwiki.android.rest.transformation.DocumentBuilder#withAttachment(org.xwiki.android.resources.Attachment) + * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#withAttachment(org.xwiki.android.resources.Attachment) */ @Override public DocumentBuilder withAttachment(Attachment attachment) @@ -367,7 +367,7 @@ public DocumentBuilder withAttachment(Attachment attachment) // } // /* (non-Javadoc) - * @see org.xwiki.android.rest.transformation.DocumentBuilder#build() + * @see org.xwiki.android.xmlrpc.transformation.DocumentBuilder#build() */ @Override public Document build() diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentDismantler_XML.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentDismantler_XML.java index 35d3195..d71f572 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentDismantler_XML.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/DocumentDismantler_XML.java @@ -77,7 +77,7 @@ public DocLaunchPadForXML convertDocument(Document doc) pad.editedObjects.put(en.getKey(),ores ); } // mark deleted objects. - List delObjs = doc.getAllDeletedObjects(); + Set delObjs = doc.getDeletedObjects(); for (String objKey : delObjs) { pad.deletedObjects.add(objKey); } @@ -97,13 +97,11 @@ public DocLaunchPadForXML convertDocument(Document doc) // updates List editedComments = doc.getAllEditedComments(); for (Comment ec : editedComments) { - Object ores = new Object(); - ores.setClassName("XWiki.XWikiComments"); - ores.setNumber(ec.getId()); + Object ores=translator.toObject(ec); pad.editedComments.add(ores); } // deletes - List deletedComments = doc.getAllDeletedComments(); + Set deletedComments = doc.getDeletedCommentSet(); for (int id : deletedComments) { String key = "XWiki.XWikiComments"; key += "/" + id; @@ -112,7 +110,7 @@ public DocLaunchPadForXML convertDocument(Document doc) } if ((parts & TAGS) == TAGS) { - // new,update,del all in one rest method. + // new,update,del all in one xmlrpc method. Tags tgsres = null; if (doc.getAllNewTags() != null && !doc.getAllNewTags().isEmpty()) { tgsres = translator.toTags(doc.getTags()); @@ -126,7 +124,7 @@ public DocLaunchPadForXML convertDocument(Document doc) edlist.addAll(newlist); pad.attatchmentsToupload = edlist; // deleted ones - pad.deletedAttachments = doc.getAllDeletedAttachments(); + pad.deletedAttachments = doc.getDeletedAttachments(); } // "ALL", its automatically done as 31=1+2+... return pad; diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/XModelTranslator_XML.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/XModelTranslator_XML.java index 7990668..c4d0dd8 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/transformation/XModelTranslator_XML.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/XModelTranslator_XML.java @@ -97,33 +97,55 @@ public Object toObject(XSimpleObject xso) XProperty xp = entry.getValue(); String pName = entry.getKey(); // transfer fields to resource.Property - Property p = new Property(); - p.setName(pName); - p.setType(xp.getType()); - p.setValue(xp.toString()); - - Map attrs = xp.getAllAttributes(); - Set> atrEntrySet = attrs.entrySet(); - - List attrList = new ArrayList(); - for (Entry atrEn : atrEntrySet) { - Attribute atr = new Attribute(); - atr.setName(atrEn.getKey()); - atr.setValue(atrEn.getValue().toString()); - attrList.add(atr); - } - plist.add(p.withAttributes(attrList)); + if(xp!=null){ + Property p = new Property(); + p.setName(pName); + p.setType(xp.getType()); + p.setValue(xp.toString()); + + Map attrs = xp.getAllAttributes(); + Set> atrEntrySet = attrs.entrySet(); + List attrList = new ArrayList(); + for (Entry atrEn : atrEntrySet) { + Attribute atr = new Attribute(); + atr.setName(atrEn.getKey()); + atr.setValue(atrEn.getValue().toString()); + attrList.add(atr); + } + plist.add(p.withAttributes(attrList)); + } } return obj.withProperties(plist); } + + public Object toObject(org.xwiki.android.xmodel.entity.Comment c){ + XComment xc=new XComment(); + xc.setNumber((c.getId())); + xc.setAuthor(c.getAuthor()); + xc.setDate(c.getDate()); + xc.setComment(c.getText()); + xc.setReplyto(c.getReplyTo()); + return toObject(xc); + } + + public Object toObject(Comment c){ + XComment xc=new XComment(); + xc.setAuthor(c.getAuthor()); + xc.setComment(c.getText()); + //xc.setDate(c.getDate()); + //TODO + return toObject(xc); + } public Comment toComment(org.xwiki.android.xmodel.entity.Comment c) { Comment cres = new Comment(); cres.id = c.getId(); cres.author = c.getAuthor(); - cres.date = c.getDate().toGMTString(); + if(c.getDate()!=null){ + cres.date = c.getDate().toGMTString(); + } cres.highlight = c.getHighlight(); cres.text = c.getText(); cres.replyTo = c.getReplyTo(); @@ -131,22 +153,9 @@ public Comment toComment(org.xwiki.android.xmodel.entity.Comment c) } - public Object toCommentObject(org.xwiki.android.xmodel.entity.Comment c){ - XComment xc=new XComment(); - xc.setAuthor(c.getAuthor()); - xc.setComment(c.getText()); - //TODO - return toObject(xc); - } + - public Object convertToCommentObject(Comment c){ - XComment xc=new XComment(); - xc.setAuthor(c.getAuthor()); - xc.setComment(c.getText()); - //xc.setDate(c.getDate()); - //TODO - return toObject(xc); - } + public Tags toTags(List tags) @@ -180,10 +189,19 @@ public Attachment toAttachment(org.xwiki.android.xmodel.entity.Attachment a) atres.setPageVersion(a.getVersion()); atres.setMimeType(a.getMimeType()); atres.setAuthor(a.getAuthor()); - atres.setDate(a.getDate().toGMTString()); - atres.setXwikiAbsoluteUrl(a.getXwikiAbsoluteUrl().toString()); - atres.setXwikiRelativeUrl(a.getXwikiAbsoluteUrl().toString()); + if(atres.getDate()!=null){ + atres.setDate(a.getDate().toGMTString()); + } + if(a.getXwikiAbsoluteUrl()!=null){ + atres.setXwikiAbsoluteUrl(a.getXwikiAbsoluteUrl().toString()); + } + if(a.getXwikiRelativeUrl()!=null){ + atres.setXwikiRelativeUrl(a.getXwikiAbsoluteUrl().toString()); + } return null; } } + +//TODO overload above methods with ex: toComment(Comment c, boolean minimal) where minimal true means +// only essential data to create a comment in the server are put to resources.Comment DTO. diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/XObjectFactory.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/XObjectFactory.java index 5c4e821..2ac9d75 100644 --- a/xwiki-android-core/src/org/xwiki/android/rest/transformation/XObjectFactory.java +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/XObjectFactory.java @@ -16,7 +16,7 @@ public class XObjectFactory private static Hashtable> xobjMap; static { xobjMap = new Hashtable>(20); - // Include code here to map XSimple Objects to the rest model objects by className. (keep alphabetic ordering + // Include code here to map XSimple Objects to the xmlrpc model objects by className. (keep alphabetic ordering // for clarity) // xobj in app within minutes diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Attachment.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Attachment.java index 8659b07..bffcf78 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Attachment.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Attachment.java @@ -21,6 +21,20 @@ public class Attachment extends Resource private URL xwikiAbsoluteUrl; // local private File file; + + public Attachment() + { + + } + + + public Attachment(String name, File file) + { + super(); + this.name = name; + this.file = file; + } + public String getId() { diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Comment.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Comment.java index 1d16cb8..b82ae9c 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Comment.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Comment.java @@ -1,5 +1,6 @@ package org.xwiki.android.xmodel.entity; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -8,112 +9,187 @@ public class Comment extends Resource { - List links; - int id; - String author; - Date date; - String text; - int replyTo; - String highlight; - //object associated to this comment. - XComment xobj; - public List getLinks() - { - return links; - } - public void addLink(Link link) - { - links.add(link); - } - public void removeLink(int index){ - links.remove(index); - } - public void clearLinks(){ - links.clear(); - } - - - public int getId() - { - return id; - } - public void setId(int id) - { - this.id = id; - } - public String getAuthor() - { - return author; - } - public void setAuthor(String author) - { - this.author = author; - } - public Date getDate() - { - return date; - } - public void setDate(Date date) - { - this.date = date; - } - public String getText() - { - return text; - } - public void setText(String text) - { - this.text = text; - } - public int getReplyTo() - { - return replyTo; - } - public void setReplyTo(int replyTo) - { - this.replyTo = replyTo; - } - - - - public String getHighlight() - { - return highlight; - } - public void setHighlight(String highlight) - { - this.highlight = highlight; - } - private XComment getXObject() - { - if(xobj==null){ - xobj=new XComment(); - - //! xobj.setId(""+id);// dont set.Not the same. - xobj.setNumber(id); - xobj.setAuthor(author); - xobj.setDate(date); - xobj.setComment(text); - xobj.setReplyto(replyTo); - - } - return xobj; - } - private void setXObject(XComment xobj) - { - this.xobj = xobj; - } - - @Override - public boolean equals(Object o) - { - if(!(o instanceof XComment)){ - return false; - }else{ - Comment c=(Comment) o; - return c.getId()==this.id; - } - - } - + List links; + int id =-1; //-1 to mean null + String author; + Date date; + String text; + int replyTo=-1; //-1 to mean null + String highlight; + + Document ownerDoc; + List replies; + // object associated to this comment. + XComment xobj; + + public Comment() + { + replies=new ArrayList(); + } + + public Comment(String text){ + this(); + this.text=text; + } + + /** + * + * This method also adds the reply comment to the parent comment's owning document if it is owned by a document. + * @return true if added. false if already contained the comment. + */ + public boolean addReplyComment(Comment rply){ + if(!replies.contains(rply)){ + replies.add(rply); + if(ownerDoc!=null){ + rply.replyTo=this.id;//setting id is done by document. If this cmnt is owned by a doc then it is + ownerDoc.addComment(rply); + } + return true; + }else{ + return false; + } + } + + public List getReplies() + { + return replies; + } + + public void setReplies(List replies) + { + this.replies = replies; + } + + public List getLinks() + { + return links; + } + + public void addLink(Link link) + { + links.add(link); + } + + public void removeLink(int index) + { + links.remove(index); + } + + public void clearLinks() + { + links.clear(); + } + + public int getId() + { + return id; + } + + public void setId(int id) + { + if(ownerDoc!=null){ + throw new IllegalStateException("You cannot alter the id of a comment after it is owned by a document"); + } + this.id = id; + } + + public String getAuthor() + { + return author; + } + + public void setAuthor(String author) + { + this.author = author; + } + + public Date getDate() + { + return date; + } + + public void setDate(Date date) + { + this.date = date; + } + + public String getText() + { + return text; + } + + public void setText(String text) + { + this.text = text; + } + + public int getReplyTo() + { + return replyTo; + } + + public void setReplyTo(int replyTo) + { + this.replyTo = replyTo; + } + + public String getHighlight() + { + return highlight; + } + + public void setHighlight(String highlight) + { + this.highlight = highlight; + } + + //package + + Document getDocument(){ + return ownerDoc; + } + void setOwner(Document ownerDoc){ + this.ownerDoc=ownerDoc; + } + + + + + //private + + private XComment getXObject() + { + if (xobj == null) { + xobj = new XComment(); + + // ! xobj.setId(""+id);// dont set.Not the same. + xobj.setNumber(id); + xobj.setAuthor(author); + xobj.setDate(date); + xobj.setComment(text); + xobj.setReplyto(replyTo); + + } + return xobj; + } + + + + private void setXObject(XComment xobj) + { + this.xobj = xobj; + } + + @Override + public boolean equals(Object o) + { + if (!(o instanceof XComment)) { + return false; + } else { + Comment c = (Comment) o; + return c.getId() == this.id && c.text==this.text; + } + + } + } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Document.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Document.java index ee87e77..388e58a 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Document.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/Document.java @@ -1,9 +1,12 @@ package org.xwiki.android.xmodel.entity; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; import java.util.List; import java.util.Map; +import java.util.Set; import org.xwiki.android.resources.Attachments; import org.xwiki.android.rest.reference.DocumentReference; @@ -27,7 +30,7 @@ public class Document extends DocumentBase private Map objects; // key= ClassName/number - private List comments; // key = int index in the list + private Map comments; // key = int index in the list private Map attatchments;// key = resource id. ex: xwiki:Blog.BlogPost1@mypic -->key is: mypic @@ -63,7 +66,7 @@ public Document(String wikiName, String spaceName, String pageName) editedObjects = new Hashtable(); deletedObjects = new ArrayList(); - comments = new ArrayList(); + comments = new HashMap(); newComments=new ArrayList(); editedComments=new ArrayList(); deletedCommetns=new ArrayList(); @@ -97,6 +100,17 @@ public XSimpleObject getObject(String key) } return obj; } + + public XSimpleObject getObject(String className, int number) + { + String key=className+"/"+number; + XSimpleObject obj = objects.get(key); + if(obj!=null){ + obj.setEdited(true); + } + return obj; + } + /** * Update a existing object in the doc. The update is done if the Object.isAltered returns true. This property is @@ -105,6 +119,7 @@ public XSimpleObject getObject(String key) * @param key * @param object */ + @Deprecated public void setObject(String key, XSimpleObject object) { String keyprefix=object.getClassName(); @@ -127,6 +142,29 @@ public void setObject(String key, XSimpleObject object) editedObjects.put(key, object); } objects.put(key, object); + } + /** + * + * @param object + * @return key to refer this obj. + */ + public String setObject(XSimpleObject object) + { + if(object.getNumber()==-1){ + throw new IllegalArgumentException("object's number must be set"); + } + if(object.getClassName().equals("")){ + throw new IllegalArgumentException("object's class name must not be empty"); + } + //end validation + + String key=object.getClassName()+"/"+object.getNumber(); + + if (object.isEdited()) {//may remove this line. Since set is done because XObj is edited. + editedObjects.put(key, object); + } + objects.put(key, object); + return key; } private int _addNum = 0; @@ -169,29 +207,91 @@ public Comment getComment(int id){ * @return id of the new comment. */ public int addComment(Comment cmnt){ - comments.add(cmnt); - cmnt.setId(comments.size()-1); - newComments.add(cmnt); - return comments.size()-1; + if(!newComments.contains(cmnt)&&!comments.containsKey(cmnt.getId())){ + newComments.add(cmnt); + int id=-newComments.size()-10; + comments.put(id,cmnt); + cmnt.setId(id); + cmnt.setOwner(this); + return id; + }else{ + return cmnt.getId(); + } } + + /** + * + * @param cmnt + * @param cascade if true adds all the reply comments as well to the document. + * @return int[0]=parent comments id, int[1] number of comments added + */ + public int[] addComment(Comment prntCmnt, boolean cascade){ + int pid=addComment(prntCmnt); + int[] rslts=new int[2]; + rslts[0]=pid; + rslts[1]=1; + if(cascade){ + for(Comment rply:prntCmnt.getReplies()){ + int[] recRslt=addComment(rply,true); + rslts[1]+=recRslt[1]; + } + } + return rslts; + } + + @Deprecated //TODO remove soon public void setComment(int id, Comment cmnt){ - comments.set(id, cmnt); + if(id<0){ + throw new IllegalArgumentException("comment id should be gt or eq to 0, \n If you are seting a comment that was added with add method no need to set again"); + } + comments.put(id, cmnt); if(!editedComments.contains(cmnt)){ editedComments.add(cmnt); - } + } + if(cmnt.getDocument()!=null){ + if(this!=cmnt.getDocument())throw new IllegalStateException("comment is already owned by another doc"); + }else{ + cmnt.setId(id); + cmnt.setOwner(this); + } + } + + public void setComment(Comment cmnt){ + int id=cmnt.getId(); + if(id<0){ + throw new IllegalArgumentException("comment id should be gt or eq to 0, \n If you are seting a comment that was added with add method no need to set again"); + } + comments.put(id, cmnt); + if(!editedComments.contains(cmnt)){ + editedComments.add(cmnt); + } + if(cmnt.getDocument()!=null){ + if(this!=cmnt.getDocument())throw new IllegalStateException("comment is already owned by another doc"); + }else{ + cmnt.setId(id); + cmnt.setOwner(this); + } + + } + + public void deleteComment(int id){ comments.remove(id); Comment cmnt=new Comment(); cmnt.setId(id); - int i=newComments.indexOf(cmnt); - int j=editedComments.indexOf(cmnt); - if(i>0){ - newComments.remove(i); - } - if(j>0){ - editedComments.remove(j); - } + if(id<0){ + int i=newComments.indexOf(cmnt); + if(i>=0){ + newComments.remove(i); + } + }else{ + int j=editedComments.indexOf(cmnt); + if(j>=0){ + editedComments.remove(j); + } + } + deletedCommetns.add(id); } @@ -280,7 +380,7 @@ public List getChildrenDocuments() return children; } - public List getAllComments() + public Map getAllComments() { return comments; } @@ -335,22 +435,40 @@ public List getAllEditedAttachments() - public List getAllDeletedObjects() + public List listObjectDeletions() { return deletedObjects; } - public List getAllDeletedComments() + public Set getDeletedObjects(){ + Set s=new HashSet(); + s.addAll(deletedObjects); + return s; + } + + public List listCommentDeletions() { return deletedCommetns; } + public Set getDeletedCommentSet(){ + Set s=new HashSet(); + s.addAll(deletedCommetns); + return s; + } + - public List getAllDeletedAttachments(){ + public List listAttachmentDeletions(){ return deletedAttachments; - } + } + + public Set getDeletedAttachments(){ + Set s=new HashSet(); + s.addAll(deletedObjects); + return s; + } - public List getAllDeletedTags(){ + public List listTagDeletions(){ return deletedTags; } diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/DocumentBase.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/DocumentBase.java index 72172fd..2c0bcee 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/DocumentBase.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/DocumentBase.java @@ -66,7 +66,7 @@ public abstract class DocumentBase extends Resource // other fields protected DocumentReference docRef; - protected boolean offlineMode; + public DocumentBase(String wikiName, String spaceName, String pageName) { @@ -92,22 +92,7 @@ public void setDocumentReference(DocumentReference docRef) this.docRef = docRef; } - /** - * if in offline mode the create(), update ... methods will use the save method to save a local copy. The delete - * method will mark the document for deletion. The sync service will take the responsibilities after internet - * connection is available. * - * - * @param val - */ - public void setOfflineMode(boolean val) - { - this.offlineMode = val; - } - - public boolean isOfflineMode() - { - return offlineMode; - } + // /** // * valid for only Documents retreived from server. diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XComment.java b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XComment.java index bcf1adf..4a822c7 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XComment.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XComment.java @@ -106,6 +106,7 @@ public void setpAuthor(XStringProperty author) { fields.put("author", author); } + public XTextAreaProperty getpComment() { return (XTextAreaProperty) fields.get("comment"); diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XPropertyBase.java b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XPropertyBase.java index b754aba..7802337 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XPropertyBase.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XPropertyBase.java @@ -148,7 +148,11 @@ public String getValidationRegExp() @Override public void setAttribute(String name, Object val) throws IllegalArgumentException { - if(name.equals("number")){ + if(val==null){ + throw new IllegalArgumentException("cannot set null attribute"); + } + + if(name.equals("number")){ if(!(val instanceof Integer)){ //now it should be string. Other wise class cast exception. try{ diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XSimpleObject.java b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XSimpleObject.java index e85b737..4c0d228 100644 --- a/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XSimpleObject.java +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/xobjects/XSimpleObject.java @@ -40,13 +40,7 @@ public XSimpleObject(String className) } - /** - * same as get className when called from a extended type. Ex: XBlogPost.getType() eq new XblogPost().getClassName(); - */ - public static String getType() - { - return "XSimpleObject"; - } + //get set pairs. diff --git a/xwiki-android-rest/res/values/strings.xml b/xwiki-android-rest/res/values/strings.xml index 4545ba3..7697541 100644 --- a/xwiki-android-rest/res/values/strings.xml +++ b/xwiki-android-rest/res/values/strings.xml @@ -1,6 +1,6 @@ - Hello World, Main! + Hello World, org.xwiki.android.test.org.xwiki.test.integration.Main! AndroidRest searchButtonClick diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/CommentResources.java b/xwiki-android-rest/src/org/xwiki/android/rest/CommentResources.java index 8d77c40..faa1cbe 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/CommentResources.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/CommentResources.java @@ -74,8 +74,8 @@ public CommentResources(String URLprefix, String wikiName, String spaceName, Str /** * @return Comments object of the page - * @throws RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ public Comments getPageComments() throws RestConnectionException, RestException { @@ -86,13 +86,29 @@ public Comments getPageComments() throws RestConnectionException, RestException return buildComments(super.getResponse(Uri)); } + public boolean exists(int commentId) throws RestConnectionException, RestException + { + String Uri = + "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName + + "/comments/" + commentId; + int code = 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 RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ - public Comment getPageComment(String commentId) throws RestConnectionException, RestException + public Comment getPageComment(int commentId) throws RestConnectionException, RestException { String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName @@ -104,8 +120,8 @@ public Comment getPageComment(String commentId) throws RestConnectionException, /** * @param version version of the page * @return list of comments as a Comments object in a specific page history version - * @throws RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ public Comments getPageCommentsInHistory(String version) throws RestConnectionException, RestException { @@ -120,10 +136,11 @@ public Comments getPageCommentsInHistory(String version) throws RestConnectionEx * @param version version of the page * @param commentId ID of the comment in the page * @return Comment in a specific page history version - * @throws RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ - public Comments getPageCommentsInHistory(String version, String commentId) throws RestConnectionException, RestException + public Comments getPageCommentsInHistory(String version, String commentId) throws RestConnectionException, + RestException { String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName @@ -137,8 +154,8 @@ public Comments getPageCommentsInHistory(String version, String commentId) throw * * @param comment Comment object to be added * @return status of the HTTP post request - * @throws RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ public String addPageComment(Comment comment) throws RestConnectionException, RestException { diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java b/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java index 672167e..f83e477 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/HttpConnector.java @@ -139,7 +139,7 @@ public int headRequest(String Uri) throws RestConnectionException{ setCredentials(); request.setURI(requestUri); - Log.d("Request URL", Uri); + Log.d("HEAD Request URL", Uri); try { response = client.execute(request); @@ -180,7 +180,7 @@ public String getResponse(String Uri) throws RestConnectionException, RestExcept setCredentials(); request.setURI(requestUri); - Log.d("Request URL", Uri); + Log.d("GET Request URL", Uri); try { response = client.execute(request); @@ -234,7 +234,7 @@ public String deleteRequest(String Uri) throws RestConnectionException, RestExce setCredentials(); request.setURI(requestUri); - Log.d("Request URL", Uri); + Log.d("DELETE Request URL", Uri); try { @@ -278,7 +278,7 @@ public int checkLogin(String username, String password, String Url) throws RestC String Uri; int responseCode = 0; - Uri = "http://" + Url + "/xwiki/rest/"; + Uri = "http://" + Url + "/xwiki/xmlrpc/"; try { requestUri = new URI(Uri); @@ -292,7 +292,7 @@ public int checkLogin(String username, String password, String Url) throws RestC setCredentials(); request.setURI(requestUri); - Log.d("Request URL", Uri); + Log.d("GET Login Request URL", Uri); try { response = client.execute(request); @@ -340,7 +340,7 @@ public String postRequest(String Uri, String content) throws RestConnectionExcep setCredentials(); request.setURI(requestUri); - Log.d("Request URL", Uri); + Log.d("POST Request URL", Uri); try { Log.d("Post content", "content=" + content); @@ -392,7 +392,7 @@ public String putRequest(String Uri, String content) throws RestConnectionExcept setCredentials(); request.setURI(requestUri); - Log.d("Request URL", Uri); + Log.d("PUT Request URL", Uri); try { Log.d("Put content", "content=" + content); @@ -443,7 +443,7 @@ public InputStream getResponseAttachment(String Uri) throws RestConnectionExcept setCredentials(); request.setURI(requestUri); - Log.d("Request URL", Uri); + Log.d("GET Request URL", Uri); try { response = client.execute(request); @@ -488,7 +488,7 @@ public String putRaw(String Uri, String filePath) throws RestConnectionException setCredentials(); request.setURI(requestUri); - Log.d("Request URL", Uri); + Log.d("PUT Request URL", Uri); try { diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/ObjectResources.java b/xwiki-android-rest/src/org/xwiki/android/rest/ObjectResources.java index 803b9a7..ac306f8 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/ObjectResources.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/ObjectResources.java @@ -73,10 +73,27 @@ public ObjectResources(String URLprefix, String wikiName, String spaceName, Stri this.pageName = pageName; } + public boolean exists(String objectClassname, String objectNumber) throws RestConnectionException, RestException + { + String Uri = + "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName + + "/objects/" +objectClassname + "/" + objectNumber; + + int code = 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 RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ public Objects getAllObjects() throws RestConnectionException, RestException { @@ -93,8 +110,8 @@ public Objects getAllObjects() throws RestConnectionException, RestException * * @param object Object object to be added to the page * @return status of th HTTP post request - * @throws RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ public String addObject(Object object) throws RestConnectionException, RestException { @@ -109,8 +126,8 @@ public String addObject(Object object) throws RestConnectionException, RestExcep /** * @param objectClassname name of the class * @return list of objects in a specific class of a page - * @throws RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ public Objects getObjectsInClassname(String objectClassname) throws RestConnectionException, RestException { @@ -126,8 +143,8 @@ public Objects getObjectsInClassname(String objectClassname) throws RestConnecti * @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 RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ public Object getObject(String objectClassname, String objectNumber) throws RestConnectionException, RestException { @@ -146,10 +163,11 @@ public Object getObject(String objectClassname, String objectNumber) throws Rest * @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 RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ - public String updateObject(String objectClassname, String objectNumber, Object object) throws RestConnectionException, RestException + public String updateObject(String objectClassname, String objectNumber, Object object) + throws RestConnectionException, RestException { String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName @@ -165,10 +183,11 @@ public String updateObject(String objectClassname, String objectNumber, Object o * @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 RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ - public String deleteObject(String objectClassname, String objectNumber) throws RestConnectionException, RestException + public String deleteObject(String objectClassname, String objectNumber) throws RestConnectionException, + RestException { String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName @@ -182,10 +201,11 @@ public String deleteObject(String objectClassname, String objectNumber) throws R * @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 RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ - public Properties getObjectProperties(String objectClassname, String objectNumber) throws RestConnectionException, RestException + public Properties getObjectProperties(String objectClassname, String objectNumber) throws RestConnectionException, + RestException { String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName @@ -202,10 +222,11 @@ public Properties getObjectProperties(String objectClassname, String objectNumbe * @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 RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ - public String addObjectProperty(String objectClassname, String objectNumber, Property property) throws RestConnectionException, RestException + public String addObjectProperty(String objectClassname, String objectNumber, Property property) + throws RestConnectionException, RestException { String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName @@ -219,10 +240,11 @@ public String addObjectProperty(String objectClassname, String objectNumber, Pro * @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 RestConnectionException - * @throws RestException + * @throws RestConnectionException + * @throws RestException */ - public Property getObjectProperty(String objectClassname, String objectNumber, String propertyName) throws RestConnectionException, RestException + public Property getObjectProperty(String objectClassname, String objectNumber, String propertyName) + throws RestConnectionException, RestException { String Uri = "http://" + URLprefix + PAGE_URL_PREFIX + wikiName + "/spaces/" + spaceName + "/pages/" + pageName diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/Requests.java b/xwiki-android-rest/src/org/xwiki/android/rest/Requests.java index eafa63a..5a036a7 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/Requests.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/Requests.java @@ -47,7 +47,7 @@ /** * All the XWiki Android RESTful requests for getting, putting and posting are included here. Method names starting from - * "request" will return objects XWiki Android REST model. Currently using xwiki-rest-model-simplexml. Method names + * "request" will return objects XWiki Android REST model. Currently using xwiki-xmlrpc-model-simplexml. Method names * starting from "add" will add XWiki Android REST model objects to the XWiki Server. */ @Deprecated @@ -98,7 +98,7 @@ public Requests(String URLprefix, String username, String password) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#setAuthentication(java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#setAuthentication(java.lang.String, java.lang.String) */ public void setAuthentication(String username, String password) { @@ -130,7 +130,7 @@ private String convertToUTF(String keyword) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestSearch(java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestSearch(java.lang.String, java.lang.String) */ public SearchResults requestSearch(String wikiName, String keyword) { @@ -157,7 +157,7 @@ public SearchResults requestSearch(String wikiName, String keyword) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestSearch(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestSearch(java.lang.String, java.lang.String, java.lang.String) */ public SearchResults requestSearch(String wikiName, String spaceName, String keyword) @@ -184,7 +184,7 @@ public SearchResults requestSearch(String wikiName, String spaceName, String key } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestWikis() + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestWikis() */ public Wikis requestWikis() @@ -208,7 +208,7 @@ public Wikis requestWikis() } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestSpaces(java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestSpaces(java.lang.String) */ public Spaces requestSpaces(String wikiName) @@ -231,7 +231,7 @@ public Spaces requestSpaces(String wikiName) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestAllPages(java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestAllPages(java.lang.String, java.lang.String) */ public Pages requestAllPages(String wikiName, String spaceName) @@ -255,7 +255,7 @@ public Pages requestAllPages(String wikiName, String spaceName) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPage(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPage(java.lang.String, java.lang.String, java.lang.String) */ public Page requestPage(String wikiName, String spaceName, String pageName) @@ -281,7 +281,7 @@ public Page requestPage(String wikiName, String spaceName, String pageName) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addPage(java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Page) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPage(java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Page) */ public String addPage(String wikiName, String spaceName, String pageName, Page page) @@ -307,7 +307,7 @@ public String addPage(String wikiName, String spaceName, String pageName, Page p } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String) */ public String deletePage(String wikiName, String spaceName, String pageName) @@ -333,7 +333,7 @@ public String deletePage(String wikiName, String spaceName, String pageName) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ public String deletePage(String wikiName, String spaceName, String pageName, String language) @@ -360,7 +360,7 @@ public String deletePage(String wikiName, String spaceName, String pageName, Str } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageHistory(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageHistory(java.lang.String, java.lang.String, java.lang.String) */ @@ -387,7 +387,7 @@ public History requestPageHistory(String wikiName, String spaceName, String page } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageInVersionHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageInVersionHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -414,7 +414,7 @@ public Page requestPageInVersionHistory(String wikiName, String spaceName, Strin } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageChildren(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageChildren(java.lang.String, java.lang.String, java.lang.String) */ @@ -442,7 +442,7 @@ public Pages requestPageChildren(String wikiName, String spaceName, String pageN } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageTags(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageTags(java.lang.String, java.lang.String, java.lang.String) */ @@ -469,7 +469,7 @@ public Tags requestPageTags(String wikiName, String spaceName, String pageName) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addPageTag(java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Tag) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageTag(java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Tag) */ @@ -497,7 +497,7 @@ public String addPageTag(String wikiName, String spaceName, String pageName, Tag } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestWikiTags(java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestWikiTags(java.lang.String) */ @@ -522,7 +522,7 @@ public Tags requestWikiTags(String wikiName) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageComments(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageComments(java.lang.String, java.lang.String, java.lang.String) */ @@ -549,7 +549,7 @@ public Comments requestPageComments(String wikiName, String spaceName, String pa } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addPageComment(java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Comment) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageComment(java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Comment) */ @@ -578,7 +578,7 @@ public String addPageComment(String wikiName, String spaceName, String pageName, } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageComments(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageComments(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -593,7 +593,7 @@ public Comment requestPageComments(String wikiName, String spaceName, String pag commentresources.setAuthenticaion(username, password); } try { - return commentresources.getPageComment(commentId); + return commentresources.getPageComment(new Integer(commentId)); } catch (RestConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -605,7 +605,7 @@ public Comment requestPageComments(String wikiName, String spaceName, String pag } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageCommentsInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageCommentsInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -632,7 +632,7 @@ public Comments requestPageCommentsInHistory(String wikiName, String spaceName, } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageCommentsInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageCommentsInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -660,7 +660,7 @@ public Comments requestPageCommentsInHistory(String wikiName, String spaceName, } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestAllPageAttachments(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestAllPageAttachments(java.lang.String, java.lang.String, java.lang.String) */ @@ -688,7 +688,7 @@ public Attachments requestAllPageAttachments(String wikiName, String spaceName, } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageAttachment(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageAttachment(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -716,7 +716,7 @@ public InputStream requestPageAttachment(String wikiName, String spaceName, Stri } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addPageAttachment(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageAttachment(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -745,7 +745,7 @@ public String addPageAttachment(String wikiName, String spaceName, String pageNa } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#deletePageAttachment(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePageAttachment(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -773,7 +773,7 @@ public String deletePageAttachment(String wikiName, String spaceName, String pag } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageAttachmentsInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageAttachmentsInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -801,7 +801,7 @@ public Attachments requestPageAttachmentsInHistory(String wikiName, String space } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageAttachmentsInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageAttachmentsInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -830,7 +830,7 @@ public InputStream requestPageAttachmentsInHistory(String wikiName, String space } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageAttachmentsInAttachmentHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageAttachmentsInAttachmentHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -859,7 +859,7 @@ public Attachments requestPageAttachmentsInAttachmentHistory(String wikiName, St } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageAttachmentsInAttachmentHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageAttachmentsInAttachmentHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -888,7 +888,7 @@ public InputStream requestPageAttachmentsInAttachmentHistory(String wikiName, St } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestWikiClasses(java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestWikiClasses(java.lang.String) */ @@ -913,7 +913,7 @@ public Classes requestWikiClasses(String wikiName) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestWikiClasses(java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestWikiClasses(java.lang.String, java.lang.String) */ @@ -939,7 +939,7 @@ public Class requestWikiClasses(String wikiName, String classname) } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestAllPageTranslations(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestAllPageTranslations(java.lang.String, java.lang.String, java.lang.String) */ @@ -966,7 +966,7 @@ public Translations requestAllPageTranslations(String wikiName, String spaceName } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageTranslation(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageTranslation(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -993,7 +993,7 @@ public Page requestPageTranslation(String wikiName, String spaceName, String pag } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageHistoryInLanguage(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageHistoryInLanguage(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -1020,7 +1020,7 @@ public History requestPageHistoryInLanguage(String wikiName, String spaceName, S } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestPageTranslationInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestPageTranslationInHistory(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -1048,7 +1048,7 @@ public Page requestPageTranslationInHistory(String wikiName, String spaceName, S } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addObject(java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Object) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addObject(java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Object) */ @@ -1075,7 +1075,7 @@ public String addObject(String wikiName, String spaceName, String pageName, Obje } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestAllObjects(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestAllObjects(java.lang.String, java.lang.String, java.lang.String) */ @@ -1102,7 +1102,7 @@ public Objects requestAllObjects(String wikiName, String spaceName, String pageN } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestObjectsInClass(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestObjectsInClass(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -1130,7 +1130,7 @@ public Objects requestObjectsInClass(String wikiName, String spaceName, String p } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestObject(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestObject(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -1160,7 +1160,7 @@ public Object requestObject(String wikiName, String spaceName, String pageName, } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#deleteObject(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deleteObject(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -1190,7 +1190,7 @@ public String deleteObject(String wikiName, String spaceName, String pageName, S } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestObjectAllProperties(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestObjectAllProperties(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -1220,7 +1220,7 @@ public Properties requestObjectAllProperties(String wikiName, String spaceName, } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#requestObjectProperty(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#requestObjectProperty(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -1251,7 +1251,7 @@ public Property requestObjectProperty(String wikiName, String spaceName, String } /* (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addProperty(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Property) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addProperty(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.xwiki.android.resources.Property) */ diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/RestConnection.java b/xwiki-android-rest/src/org/xwiki/android/rest/RestConnection.java new file mode 100644 index 0000000..cc4b133 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/RestConnection.java @@ -0,0 +1,8 @@ +package org.xwiki.android.rest; + +public interface RestConnection +{ + XWikiAPI getBaseAPI(); + boolean isClosed(); + void close(); +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/Upgrade Http Connector, RestConnection b/xwiki-android-rest/src/org/xwiki/android/rest/Upgrade Http Connector, RestConnection new file mode 100644 index 0000000..9850c5e --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/Upgrade Http Connector, RestConnection @@ -0,0 +1,100 @@ +PoC. +We can achieve parellel http connections in this layer. +Use implementations of RestConnection to adjust params. +RestConnection.close() should shutdown the http connection manager of the http client. + +sample code// + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.scheme.PlainSocketFactory; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; + +/** + * Created with IntelliJ IDEA. + * User: admin + * Date: 8/11/12 + * Time: 1:53 PM + * To change this template use File | Settings | File Templates. + */ +public class org.xwiki.android.test.org.xwiki.test.integration.Main { + + static DefaultHttpClient client; + public static void main(String[] args) throws IOException, InterruptedException { + + SchemeRegistry schemeRegistry = new SchemeRegistry(); + schemeRegistry.register( + new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); + + ClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); + HttpClient httpClient = new DefaultHttpClient(cm); + +// URIs to perform GETs on + String[] urisToGet = { + "http://www.domain1.com/", + "http://www.domain2.com/", + "http://www.domain3.com/", + "http://www.domain4.com/" + }; + +// create a thread for each URI + GetThread[] threads = new GetThread[urisToGet.length]; + for (int i = 0; i < threads.length; i++) { + HttpGet httpget = new HttpGet(urisToGet[i]); + threads[i] = new GetThread(httpClient, httpget); + } + +// start the threads + for (int j = 0; j < threads.length; j++) { + threads[j].start(); + } + +// join the threads + for (int j = 0; j < threads.length; j++) { + threads[j].join(); + } + + } + + static class GetThread extends Thread { + + private final HttpClient httpClient; + private final HttpContext context; + private final HttpGet httpget; + + public GetThread(HttpClient httpClient, HttpGet httpget) { + this.httpClient = httpClient; + this.context = new BasicHttpContext(); + this.httpget = httpget; + } + + @Override + public void run() { + try { + HttpResponse response = this.httpClient.execute(this.httpget, this.context); + HttpEntity entity = response.getEntity(); + if (entity != null) { + // do something useful with the entity + } + // ensure the connection gets released to the manager + EntityUtils.consume(entity); + } catch (Exception ex) { + this.httpget.abort(); + } + } + + } + +} \ No newline at end of file diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestfulAPI.java b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiAPI.java similarity index 92% rename from xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestfulAPI.java rename to xwiki-android-rest/src/org/xwiki/android/rest/XWikiAPI.java index 95c3b2d..38dc5a7 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestfulAPI.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiAPI.java @@ -26,7 +26,7 @@ * @author xwiki gsoc 2012 * */ -public interface XWikiRestfulAPI +public interface XWikiAPI { /** @@ -242,6 +242,7 @@ String addPageTag(String wikiName, String spaceName, String pageName, Tag tag) t public String setTags(String wikiName, String spaceName, String pageName,Tags tags) throws RestConnectionException, RestException; /** + * get all comments in page * @param wikiName * name of the Wiki * @param spaceName @@ -253,6 +254,27 @@ String addPageTag(String wikiName, String spaceName, String pageName, Tag tag) t Comments getPageComments(String wikiName, String spaceName, String pageName) throws RestConnectionException, RestException; + /** + * check whether a comment exists for the given page. + * @param wikiName + * @param spaceName + * @param pageName + * @param commentId + * @return + * @throws RestConnectionException + * @throws RestException + */ + public boolean existsPageComment(String wikiName, String spaceName, String pageName,int commentId) throws RestConnectionException, RestException; + + /** + * get a comment. + * @param commentId ID of the comment in the page + * @return comment of a page selected using comment ID + * @throws RestConnectionException + * @throws RestException + */ + public Comment getPageComment(String wikiName, String spaceName, String pageName, int commentId) throws RestConnectionException, RestException; + /** * Add comment to the page * @@ -265,24 +287,12 @@ Comments getPageComments(String wikiName, String spaceName, String pageName) thr * @param comment * Comment object to be added * @return status of the HTTP response - */ + */ + String addPageComment(String wikiName, String spaceName, String pageName, Comment comment) throws RestConnectionException, RestException; - /** - * @param wikiName - * name of the Wiki - * @param spaceName - * name of the space - * @param pageName - * name of the page - * @param commentId - * ID of the comment - * @return page comment according to the comment ID - */ - Comment getPageComments(String wikiName, String spaceName, String pageName, String commentId) - throws RestConnectionException, RestException; - + /** * @param wikiName * name of the Wiki @@ -495,6 +505,9 @@ History getPageHistoryInLanguage(String wikiName, String spaceName, String pageN Page getPageTranslationInHistory(String wikiName, String spaceName, String pageName, String language, String version) throws RestConnectionException, RestException; + + boolean existsObject(String wikiName, String spaceName, String pageName, String objectClassname, + int objectNumber)throws RestConnectionException,RestException; /** * Adds provided object to the given page * @@ -525,7 +538,7 @@ String addObject(String wikiName, String spaceName, String pageName, Object obje * @throws RestException */ public String updateObject(String wikiName, String spaceName, String pageName, String objectClassname, - String objectNumber, Object object) throws RestConnectionException, RestException; + int objectNumber, Object object) throws RestConnectionException, RestException; /** * @param wikiName @@ -622,6 +635,7 @@ Properties getObjectAllProperties(String wikiName, String spaceName, String page */ Property getObjectProperty(String wikiName, String spaceName, String pageName, String objectClassname, String objectNumber, String propertyName) throws RestConnectionException, RestException; + //TODO: refactor number to int /** * Adds the property to the object of a page diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnecion.java similarity index 80% rename from xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java rename to xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnecion.java index 54a8870..ffea118 100644 --- a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java +++ b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnecion.java @@ -25,9 +25,11 @@ import android.util.Log; -public class XWikiRestConnector implements XWikiRestfulAPI +public class XWikiRestConnecion implements RestConnection, XWikiAPI { + private static final String TAG ="XWikiRestConnecion"; + /** * URL of the XWiki domain */ @@ -51,7 +53,7 @@ public class XWikiRestConnector implements XWikiRestfulAPI /** * @param URLprefix URL of the XWiki domain */ - public XWikiRestConnector(String URLprefix) + public XWikiRestConnecion(String URLprefix) { this.URLprefix = URLprefix; isAuthenticated = false; @@ -64,7 +66,7 @@ public XWikiRestConnector(String URLprefix) * @param username username of the user account * @param password password of the user account */ - public XWikiRestConnector(String URLprefix, String username, String password) + public XWikiRestConnecion(String URLprefix, String username, String password) { this.URLprefix = URLprefix; this.username = username; @@ -74,7 +76,7 @@ public XWikiRestConnector(String URLprefix, String username, String password) /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#setAuthentication(java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#setAuthentication(java.lang.String, java.lang.String) */ @Override public void setAuthentication(String username, String password) @@ -109,7 +111,7 @@ private String urlEncode(String word) /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getSearch(java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getSearch(java.lang.String, java.lang.String) */ @Override public SearchResults searchInWiki(String wikiName, String keyword) throws RestConnectionException, RestException, RestException @@ -129,7 +131,7 @@ public SearchResults searchInWiki(String wikiName, String keyword) throws RestCo /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getSearch(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getSearch(java.lang.String, java.lang.String, java.lang.String) */ @Override public SearchResults searchInSpace(String wikiName, String spaceName, String keyword) throws RestConnectionException, RestException @@ -148,7 +150,7 @@ public SearchResults searchInSpace(String wikiName, String spaceName, String key /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getWikis() + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getWikis() */ @Override public Wikis getWikis() throws RestConnectionException, RestException @@ -164,7 +166,7 @@ public Wikis getWikis() throws RestConnectionException, RestException /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getSpaces(java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getSpaces(java.lang.String) */ @Override public Spaces getSpaces(String wikiName) throws RestConnectionException, RestException @@ -179,7 +181,7 @@ public Spaces getSpaces(String wikiName) throws RestConnectionException, RestExc /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getAllPages(java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getAllPages(java.lang.String, java.lang.String) */ @Override public Pages getAllPages(String wikiName, String spaceName) throws RestConnectionException, RestException @@ -225,7 +227,7 @@ public Page getPage(String wikiName, String spaceName, String pageName) throws R /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addPage(java.lang.String, java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPage(java.lang.String, java.lang.String, java.lang.String, * org.xwiki.android.resources.Page) */ @Override @@ -244,7 +246,7 @@ public String addPage(String wikiName, String spaceName, String pageName, Page p /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String) */ @Override public String deletePage(String wikiName, String spaceName, String pageName) throws RestConnectionException, RestException @@ -262,7 +264,7 @@ public String deletePage(String wikiName, String spaceName, String pageName) thr /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String, * java.lang.String) */ @Override @@ -283,7 +285,7 @@ public String deletePage(String wikiName, String spaceName, String pageName, Str /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageHistory(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageHistory(java.lang.String, java.lang.String, java.lang.String) */ @Override @@ -302,7 +304,7 @@ public History getPageHistory(String wikiName, String spaceName, String pageName /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageInVersionHistory(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageInVersionHistory(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -323,7 +325,7 @@ public Page getPageInVersionHistory(String wikiName, String spaceName, String pa /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageChildren(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageChildren(java.lang.String, java.lang.String, java.lang.String) */ @Override @@ -343,7 +345,7 @@ public Pages getPageChildren(String wikiName, String spaceName, String pageName) /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageTags(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageTags(java.lang.String, java.lang.String, java.lang.String) */ @Override @@ -362,7 +364,7 @@ public Tags getPageTags(String wikiName, String spaceName, String pageName) thro /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addPageTag(java.lang.String, java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageTag(java.lang.String, java.lang.String, java.lang.String, * org.xwiki.android.resources.Tag) */ @@ -395,7 +397,7 @@ public String setTags(String wikiName, String spaceName, String pageName,Tags ta /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getWikiTags(java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getWikiTags(java.lang.String) */ @Override @@ -412,7 +414,7 @@ public Tags getWikiTags(String wikiName) throws RestConnectionException, RestExc /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageComments(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageComments(java.lang.String, java.lang.String, java.lang.String) */ @Override @@ -428,16 +430,24 @@ public Comments getPageComments(String wikiName, String spaceName, String pageNa } return commentresources.getPageComments(); } + + @Override + public boolean existsPageComment(String wikiName, String spaceName, String pageName, int commentId) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); - /* - * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addPageComment(java.lang.String, java.lang.String, java.lang.String, - * org.xwiki.android.resources.Comment) - */ + CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + commentresources.setAuthenticaion(username, password); + } + return commentresources.exists(commentId); + } @Override - public String addPageComment(String wikiName, String spaceName, String pageName, Comment comment) - throws RestConnectionException, RestException + public Comment getPageComment(String wikiName, String spaceName, String pageName, int commentId) throws RestConnectionException, RestException { wikiName = urlEncode(wikiName); spaceName = urlEncode(spaceName); @@ -446,20 +456,18 @@ public String addPageComment(String wikiName, String spaceName, String pageName, CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); if (isAuthenticated) { commentresources.setAuthenticaion(username, password); - return commentresources.addPageComment(comment); - } else { - return "Autherization details are not provided"; } + return commentresources.getPageComment(commentId); } /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageComments(java.lang.String, java.lang.String, java.lang.String, - * java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageComment(java.lang.String, java.lang.String, java.lang.String, + * org.xwiki.android.resources.Comment) */ @Override - public Comment getPageComments(String wikiName, String spaceName, String pageName, String commentId) + public String addPageComment(String wikiName, String spaceName, String pageName, Comment comment) throws RestConnectionException, RestException { wikiName = urlEncode(wikiName); @@ -469,13 +477,17 @@ public Comment getPageComments(String wikiName, String spaceName, String pageNam CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); if (isAuthenticated) { commentresources.setAuthenticaion(username, password); + return commentresources.addPageComment(comment); + } else { + return "Autherization details are not provided"; } - return commentresources.getPageComment(commentId); } + + /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageCommentsInHistory(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageCommentsInHistory(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -496,7 +508,7 @@ public Comments getPageCommentsInHistory(String wikiName, String spaceName, Stri /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageCommentsInHistory(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageCommentsInHistory(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String) */ @@ -517,7 +529,7 @@ public Comments getPageCommentsInHistory(String wikiName, String spaceName, Stri /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getAllPageAttachments(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getAllPageAttachments(java.lang.String, java.lang.String, * java.lang.String) */ @@ -539,7 +551,7 @@ public Attachments getAllPageAttachments(String wikiName, String spaceName, Stri /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageAttachment(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachment(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -561,7 +573,7 @@ public InputStream getPageAttachment(String wikiName, String spaceName, String p /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addPageAttachment(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageAttachment(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String) */ @@ -583,7 +595,7 @@ public String putPageAttachment(String wikiName, String spaceName, String pageNa /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#deletePageAttachment(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePageAttachment(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -605,7 +617,7 @@ public String deletePageAttachment(String wikiName, String spaceName, String pag /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageAttachmentsInHistory(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachmentsInHistory(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -626,7 +638,7 @@ public Attachments getPageAttachmentsInHistory(String wikiName, String spaceName /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageAttachmentsInHistory(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachmentsInHistory(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String) */ @@ -648,7 +660,7 @@ public InputStream getPageAttachmentsInHistory(String wikiName, String spaceName /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageAttachmentsInAttachmentHistory(java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachmentsInAttachmentHistory(java.lang.String, * java.lang.String, java.lang.String, java.lang.String) */ @@ -670,7 +682,7 @@ public Attachments getPageAttachmentsInAttachmentHistory(String wikiName, String /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageAttachmentsInAttachmentHistory(java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachmentsInAttachmentHistory(java.lang.String, * java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -692,7 +704,7 @@ public InputStream getPageAttachmentsInAttachmentHistory(String wikiName, String /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getWikiClasses(java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getWikiClasses(java.lang.String) */ @Override @@ -709,7 +721,7 @@ public Classes getWikiClasses(String wikiName) throws RestConnectionException, R /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getWikiClasses(java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getWikiClasses(java.lang.String, java.lang.String) */ @Override @@ -727,7 +739,7 @@ public Class getWikiClasses(String wikiName, String classname) throws RestConnec /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getAllPageTranslations(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getAllPageTranslations(java.lang.String, java.lang.String, * java.lang.String) */ @@ -748,7 +760,7 @@ public Translations getAllPageTranslations(String wikiName, String spaceName, St /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageTranslation(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageTranslation(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -769,7 +781,7 @@ public Page getPageTranslation(String wikiName, String spaceName, String pageNam /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageHistoryInLanguage(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageHistoryInLanguage(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -790,7 +802,7 @@ public History getPageHistoryInLanguage(String wikiName, String spaceName, Strin /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getPageTranslationInHistory(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageTranslationInHistory(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String) */ @@ -808,10 +820,29 @@ public Page getPageTranslationInHistory(String wikiName, String spaceName, Strin } return pageresources.getPageTranslation(pageName, language, version); } + + @Override + public boolean existsObject(String wikiName, String spaceName, String pageName, String objectClassname, + int objectNumber) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + objectClassname = urlEncode(objectClassname); + String objNumber=urlEncode(objectNumber+""); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + boolean val= objectresources.exists(objectClassname,objNumber); + return val; + + } /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addObject(java.lang.String, java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addObject(java.lang.String, java.lang.String, java.lang.String, * org.xwiki.android.resources.Object) */ @@ -841,7 +872,7 @@ public String addObject(String wikiName, String spaceName, String pageName, Obje * @throws RestException */ @Override - public String updateObject(String wikiName, String spaceName, String pageName,String objectClassname, String objectNumber, Object object) throws RestConnectionException, RestException + public String updateObject(String wikiName, String spaceName, String pageName,String objectClassname, int objectNumber, Object object) throws RestConnectionException, RestException { wikiName = urlEncode(wikiName); spaceName = urlEncode(spaceName); @@ -851,13 +882,13 @@ public String updateObject(String wikiName, String spaceName, String pageName,St if (isAuthenticated) { objectresources.setAuthenticaion(username, password); } - return objectresources.updateObject(objectClassname, objectNumber, object); + return objectresources.updateObject(objectClassname, ""+objectNumber, object); } /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getAllObjects(java.lang.String, java.lang.String, java.lang.String) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getAllObjects(java.lang.String, java.lang.String, java.lang.String) */ @Override @@ -876,7 +907,7 @@ public Objects getAllObjects(String wikiName, String spaceName, String pageName) /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getObjectsInClass(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getObjectsInClass(java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -898,7 +929,7 @@ public Objects getObjectsInClass(String wikiName, String spaceName, String pageN /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getObject(java.lang.String, java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getObject(java.lang.String, java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -921,7 +952,7 @@ public Object getObject(String wikiName, String spaceName, String pageName, Stri /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#deleteObject(java.lang.String, java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deleteObject(java.lang.String, java.lang.String, java.lang.String, * java.lang.String, java.lang.String) */ @@ -944,7 +975,7 @@ public String deleteObject(String wikiName, String spaceName, String pageName, S /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getObjectAllProperties(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getObjectAllProperties(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String) */ @@ -967,7 +998,7 @@ public Properties getObjectAllProperties(String wikiName, String spaceName, Stri /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#getObjectProperty(java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getObjectProperty(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -991,7 +1022,7 @@ public Property getObjectProperty(String wikiName, String spaceName, String page /* * (non-Javadoc) - * @see org.xwiki.android.rest.XWikiRestfulAPI#addProperty(java.lang.String, java.lang.String, java.lang.String, + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addProperty(java.lang.String, java.lang.String, java.lang.String, * java.lang.String, java.lang.String, org.xwiki.android.resources.Property) */ @@ -1012,5 +1043,30 @@ public String addObjectProperty(String wikiName, String spaceName, String pageNa return objectresources.addObjectProperty(objectClassname, objectNumber, property); } + //connection methods + + + @Override + public XWikiAPI getBaseAPI() + { + return this; + } + + @Override + public boolean isClosed() + { + return false; + } + + @Override + public void close() + { + Log.e(TAG, "not implemented: should release any resources: Also see that HttpConnector does not release resources"); + //httpclient.getConnectionManager().shutdown(); + //refer: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html + //throw new UnsupportedOperationException("should be releasing resources."); + } + + } diff --git a/xwiki-android-test-core/AndroidManifest.xml b/xwiki-android-test-core/AndroidManifest.xml new file mode 100644 index 0000000..ed58db2 --- /dev/null +++ b/xwiki-android-test-core/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xwiki-android-test-core/pom.xml b/xwiki-android-test-core/pom.xml new file mode 100644 index 0000000..cd4c949 --- /dev/null +++ b/xwiki-android-test-core/pom.xml @@ -0,0 +1,70 @@ + + + + + + 4.0.0 + + org.xwiki.android + xwiki-android + 1.0-SNAPSHOT + + + xwiki-android-test-core + apk + XWiki Android Core tests + Tests the platform core of the XWiki Android Platform libs. + + + + org.xwiki.android + xwiki-android-rest + apklib + ${project.version} + + + + org.xwiki.android + xwiki-android-core + apklib + ${project.version} + + + + com.google.android + android-test + 2.1.2 + provided + + + + junit + junit + 3.8.2 + provided + + + + + diff --git a/xwiki-android-test-core/proguard-project.txt b/xwiki-android-test-core/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/xwiki-android-test-core/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/xwiki-android-test-core/project.properties b/xwiki-android-test-core/project.properties new file mode 100644 index 0000000..0d7f4ae --- /dev/null +++ b/xwiki-android-test-core/project.properties @@ -0,0 +1,16 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# 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 + +# Project target. +target=android-7 +android.library.reference.1=..\\xwiki-android-rest +android.library.reference.2=../xwiki-android-core diff --git a/xwiki-android-test-core/res/drawable-hdpi/ic_launcher.png b/xwiki-android-test-core/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..96a442e5b8e9394ccf50bab9988cb2316026245d GIT binary patch literal 9397 zcmV;mBud+fP)L`9r|n3#ts(U@pVoQ)(ZPc(6i z8k}N`MvWQ78F(rhG(?6FnFXYo>28{yZ}%O}TvdDT_5P?j=iW=V`8=UNc_}`JbG!ST zs@lK(TWkH+P**sB$A`cEY%Y53cQ}1&6`x-M$Cz&{o9bLU^M-%^mY?+vedlvt$RT-^ zu|w7}IaWaljBq#|I%Mpo!Wc2bbZF3KF9|D%wZe{YFM=hJAv$>j>nhx`=Wis#KG!cJA5x!4)f) zezMz1?Vn$GnZNjbFXH(pK83nn!^3=+^*kTTs5rV9Dq^XS(IKO!mKt5!dSmb3IVCxZ z8TTk5IE)F1V29$G7v#j9d-hy&_pdg8?kT4)zqr>?`}I%W>(?GO%*C&}?Fp|bI*~2&KZ$%^B6R&1~2kA{`CWy+>F-x=z-f{_&vyu_3yp{jtw(*syi% zu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#Z@0&k3QOG}i+j)HBi%%Z=`tcW^UCejx+4hFXpTF~> z6_NH`)m1V01y2Phns1H@BEv%=rBZ<`6)ly05y^ASTBkN~;?g=vr9P;=m7CX$|G)Zgm+aiXZ~uaNy+(I$oqD4|rBaJZ zrIPx7!4u>8HcdFJC#TdexmzBje$|6hQ{z`W;j zcxEL`omomE>(d+x8Qd8VhX=5+`P#GV58evMdoP*&lTI}9fl8%JsjEQ2FXPkIUzaTk zaNk#c^;wYqAW|>-DX%0C?1}#Zoic`Di%g1kcS7qn!=Ut&(rcy6c zEP5*Vl6GWL2O9olCKpP^6ib5fJT(SUCo~-tix$s^a?N*TuSl&?#P^M4X@Pb!L1}-x z&WA*#CC1=+BE_;txmKWDDTfD-_Gz_Ib&Z~KTI()QX%w`p;#2A}c%F3r-vD)*@$xL` zN{seU@}^QO)(>T_xfWpdaeovRE7^CZPMr}#|!d*|R6{H=+M{MV$Mp3LNPKT_t5 z(-+S5yz=?J*A+!U{KSTh8xFttSbqQdFU>bSjT8Q$)Ky#JnbOd}k;7ZR_W37=|NQzh jFn-Lp|K;W1YU6(Zg`N}+zmb=x00000NkvXXu0mjf_|!_9 literal 0 HcmV?d00001 diff --git a/xwiki-android-test-core/res/drawable-mdpi/ic_launcher.png b/xwiki-android-test-core/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..359047dfa4ed206e41e2354f9c6b307e713efe32 GIT binary patch literal 5237 zcmV-*6pHJKP)!xJWW@nmR0Ns^Wrk)72_X;&VM@qLNZyn;-h1m-)j4PH{!#b7fObo=TF+Xw z)_t{JRqgNW{e9m)=MZ*rJl6A%IHK!gcqM)U)>TjF8ytMTRLpN39jns9J?@oOe47l4 z1dw7d06;*nuu_+V$6Qs4K>#PCRHVFExV^duw#+4>?(j) z*AHP%*L5@qEpM#j?*@5nOq@HlBR^5M@^_J9)U!&MV7N?QAAfFbdJaGWPgRws)6~+R z-NrZmx0V*7Od$!{dkY1w*wll3j_1b``)C%NH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Y84}cF$$#|Dx-Bwp4xT+U;&*D<@0j8tMo%x5%Tg?~5R?T=3cv%@lt|5rbf!U~$$KWHR3?Xk zu&I|c5%P}XIIb@4XrJ=aC`y!W*}^Y88R7A}hVa+MJ05U+?`P+M8rvjM6j3edroqA2 zxm4Kuj7oLnm$`fxbar$}K3^bGfWT*$Wd5R*hEfJ52%w-LATTp*YNZ}ksTNg7J=bnd z-Pkqa!RO=D(kYB&|Wjqg0rvF8kum{NfucTYqrP z`5U%u**G!G6{S=zQMp`3K3_yWUyzoz^2Q(tmC>3+s5Oq`4(BY=)S@2MFgiNo;u?&k zg`0}`37-~9P0%vHiA@+H2!cEy8o#>wuOImB)G_Pj7yce!TXGVt#ORn z(=jFB*q2Zp6$}lGp?}+$um^#4QjKaSEI75c$z6AAYL348>#uKEccl>fFbuUZ0R$d} zZ~}6sT!$|qC`YPurgrtQ76=RC$YS~T-}$t1r_YJ6x+vSq`|xwOl@gGLU>BhcFBv~FMie-ahi$Rz-LINpu0Hu~Za`}LYEdk2y0hQVU6k7}mB|~9e!x(}I6ii4k;VvE0 z?|KG+Oj%0Bi3m(dlp;$c5Cu`1CM@ypLV(%bX9 zr_WVSKiJ10x1!vdPr`gLXF?@f1r%~#N8UkH?XgO1p%e>?-DLnfb z=86?7j~f~sKElT8lSw^&-{|PJ_Z)D@o-cw6^yvN1aY@hS38meM!r|M7s_XW%93Aak za$IUh=gpcu=jzR`4$^18^F8_11#h4-#Jd^}{s&{CB`(>qac=+s03~!qSaf7zbY(hY za%Ew3WdJfTF)=MLIW00WR4_R@Gcr0eGA%GSIxsM(l48sN001R)MObuXVRU6WZEs|0 vW_bWIFflPLFgYzTHdHV-Ix;spGd3+SH##sdcWUue00000NkvXXu0mjfB?gph literal 0 HcmV?d00001 diff --git a/xwiki-android-test-core/res/drawable-xhdpi/ic_launcher.png b/xwiki-android-test-core/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..71c6d760f05183ef8a47c614d8d13380c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wh;L1&Bp-%AN|S+IN+dtu>8SW;MiEQQXoi>G#VR3kNlOA0hCa%=}ubL{Rw#g z8>O^z*aor(V1b*ij4|}&n%zkb0KoqRbb1&ct<2Ko0000bbVXQnWMOn=I%9HWVRU5x zGB7bQEigGPGBQ*!IXW{kIx{jYFgH3dFsPDZ%m4rYC3HntbYx+4WjbwdWNBu305UK! pF)c7TEipD!FgH3fH###mEigAaFfey&@l*f+002ovPDHLkV1iQC3p)S+ literal 0 HcmV?d00001 diff --git a/xwiki-android-test-core/res/values/strings.xml b/xwiki-android-test-core/res/values/strings.xml new file mode 100644 index 0000000..2c78198 --- /dev/null +++ b/xwiki-android-test-core/res/values/strings.xml @@ -0,0 +1,6 @@ + + + + Xwiki-android-test-coreTest + + \ No newline at end of file diff --git a/xwiki-android-test-core/src/org/xwiki/android/core/test/AllTests.java b/xwiki-android-test-core/src/org/xwiki/android/core/test/AllTests.java new file mode 100644 index 0000000..9ca4983 --- /dev/null +++ b/xwiki-android-test-core/src/org/xwiki/android/core/test/AllTests.java @@ -0,0 +1,36 @@ +/* + * 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.core.test; + +import junit.framework.Test; +import junit.framework.TestSuite; +import android.test.suitebuilder.TestSuiteBuilder; + +/** + * A test suite containing all tests for test application. + */ +public class AllTests extends TestSuite +{ + public static Test suite() + { + return new TestSuiteBuilder(AllTests.class).includePackages("org.xwiki.android.rest.ral.test").includeAllPackagesUnderHere().build(); + } +} diff --git a/xwiki-android-test-core/src/org/xwiki/android/core/test/TestTemplate.java b/xwiki-android-test-core/src/org/xwiki/android/core/test/TestTemplate.java new file mode 100644 index 0000000..2d3a066 --- /dev/null +++ b/xwiki-android-test-core/src/org/xwiki/android/core/test/TestTemplate.java @@ -0,0 +1,86 @@ +package org.xwiki.android.core.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 TestTemplate extends AndroidTestCase +{ + + private static final String TAG = TestTemplate.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 TestTemplate() + { + // 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(); + Log.d(TAG, "SET UP" + countTestCases()); + + //run before each testxxxx; + // + + 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++; + Log.d(TAG, "TEAR DOWN"); + //run after each testxxxx + // add cleanup code here + } + + 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/core/test/properties/Env.java b/xwiki-android-test-core/src/org/xwiki/android/core/test/properties/Env.java new file mode 100644 index 0000000..83f66cc --- /dev/null +++ b/xwiki-android-test-core/src/org/xwiki/android/core/test/properties/Env.java @@ -0,0 +1,40 @@ +package org.xwiki.android.core.test.properties; + +public interface Env +{ + String WIKI_NAME = "xwiki"; + + String SPACE_NAME = "Blog"; + + String PAGE_NAME = "test2"; + + String TEMP_PAGE_NAME ="tempTestPage"; //used for create method tests. because page needss to be deleted for creation + + String URL = "10.0.2.2:8080"; + + String USERNAME = "superadmin"; + + String PASSWORD = "admin"; + + // String PAGE_VERSION = "1.0"; + + String COMMENT_ID = "0"; + + // String LANGUAGE = "null"; + + String CLASS_NAME = "Blog.BlogPostClass"; + + int OBJECT_NUMBER = 0; + + String OBJECT_PROPERTY_NAME = "content"; + + // String SEARCH_KEWORD = "test"; + + String TAG_WORD = "testTag"; + + String ATTACHMENT_NAME = "note.txt"; + + + + // String ATTACHMENT_VERSION = "1.0"; +} diff --git a/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoCreate.java b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoCreate.java new file mode 100644 index 0000000..93a3b01 --- /dev/null +++ b/xwiki-android-test-core/src/org/xwiki/android/rest/ral/test/TestDocumentRaoCreate.java @@ -0,0 +1,270 @@ +package org.xwiki.android.rest.ral.test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.List; + +import junit.framework.AssertionFailedError; + +import org.xwiki.android.context.XWikiApplicationContext; +import org.xwiki.android.core.test.properties.Env; +import org.xwiki.android.resources.Comments; +import org.xwiki.android.resources.Object; +import org.xwiki.android.resources.Property; +import org.xwiki.android.rest.PageResources; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; +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.Attachment; +import org.xwiki.android.xmodel.entity.Comment; +import org.xwiki.android.xmodel.entity.Document; +import org.xwiki.android.xmodel.entity.Tag; +import org.xwiki.android.xmodel.xobjects.XSimpleObject; + +import android.app.Application; +import android.content.Context; +import android.test.AndroidTestCase; +import android.util.Log; + +/** + * Tests XMLDocumentRao.create(); + */ +public class TestDocumentRaoCreate extends AndroidTestCase +{ + private static final String TAG = TestDocumentRaoCreate.class.getSimpleName(); + // test org.xwiki.android.test.fixture.teardown.env parameters. + String serverUrl, username, password, wikiName, spaceName, pageName, attachmentName; + static int count=1; + + // tested apis + RESTfulManager rm; + DocumentRao rao; + + // api used for output verification + XWikiAPI api; + + // test inputs + Document doc; + // special inputs set in tests + XBlogPost xb1, xb2, xb3; + XSimpleObject so1, so2; // a general so. + Comment c1, c2, c3; + Tag t1, t2; + Attachment a1; + File af1; + + public TestDocumentRaoCreate() + { + username = Env.USERNAME; + password = Env.PASSWORD; + serverUrl = Env.URL; + + wikiName = Env.WIKI_NAME; + spaceName = Env.SPACE_NAME; + pageName = Env.TEMP_PAGE_NAME; + attachmentName=Env.ATTACHMENT_NAME; + } + + @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); + + // setup preconditions on serverside + if(count<6)api.deletePage(wikiName, spaceName, pageName); + if(count==1){ + Application sys=XWikiApplicationContext.getInstance(); + FileOutputStream fos = sys.openFileOutput(attachmentName, Context.MODE_WORLD_READABLE); + PrintWriter writer=new PrintWriter(fos); + writer.println("this is a text attachment."); + writer.flush(); + writer.close(); + af1=sys.getFileStreamPath(attachmentName); + } + Log.d(TAG,"setup test method:"+ count ); + + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + count++; + // rm.close(); + } + + /** + * a minimal test + */ + public void testCreate01() throws Throwable + { + boolean success = true; + + try { + rao.create(doc); + success = api.existsPage(wikiName, spaceName, pageName); + } catch (RaoException e) { + success = false; + } catch (RestException e) { + success = false; + } + assertTrue(success); + } + + /** + * test with xobjects. Use add method. + */ + public void testCreate02() throws Throwable + { + boolean success = false; + xb1 = new XBlogPost(); + xb1.setContent("test post"); + doc.addObject(xb1); + try { + rao.create(doc); + } catch (RaoException e) { + success = false; + } + try { + success = api.existsPage(wikiName, spaceName, pageName); + } catch (RestException e) { + success = false; + } + assertTrue(success); + } + + /** + * test add/set general XSimpleObject. + * + * @throws Throwable + */ + public void testCreate03() throws Throwable + { + boolean success; + so1 = new XSimpleObject("Blog.BlogClass") + { + }; + so2 = new XSimpleObject("Blog.BlogCategoryClass") + { + }; + so2.setNumber(1); + doc.addObject(so1); + doc.setObject(so2); + + try { + rao.create(doc); + } catch (RaoException e) { + success = false; + } + + // verify + try { + success = api.existsPage(wikiName, spaceName, pageName); + if (success) { + boolean crite1 = api.existsObject(wikiName, spaceName, pageName, so1.getClassName(), 0); + boolean crite2 = api.existsObject(wikiName, spaceName, pageName, so1.getClassName(), 0); + success = crite1 & crite2; + } + } catch (RestException e) { + success = false; + } + } + + /** + * checks wether the objects get added in the correct sequence + * + * @throws Throwable + */ + public void testCreate04() throws Throwable + { + boolean success = false; + xb1 = new XBlogPost(); + xb2 = new XBlogPost(); + xb3 = new XBlogPost(); + + xb1.setContent("0"); + xb2.setContent("1"); + xb3.setContent("2"); + + xb1.setNumber(0); + // dont set num on xb2 + xb3.setNumber(2); + + doc.setObject(xb1); + doc.addObject(xb2); + doc.setObject(xb3); + + rao.create(doc); + + try { + success = api.existsPage(wikiName, spaceName, pageName); + if (success) { + boolean crite1 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 0); + boolean crite2 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 1); + boolean crite3 = api.existsObject(wikiName, spaceName, pageName, xb1.getClassName(), 2); + success = crite1 & crite2 & crite3; + } + if (success) { + Property xb2PropRet = + api.getObjectProperty(wikiName, spaceName, pageName, xb2.getClassName(), "1", "content"); + success = xb2PropRet.getValue().equals("1"); + } + + } catch (RestException e) { + success = false; + } + assertTrue(success); + } + + public void testCreate05WithCmnts() throws Throwable + { + + c1 = new Comment("hi"); + c2 = new Comment("reply to hi"); + c1.addReplyComment(c2); + doc.addComment(c1, true); + + try { + rao.create(doc); + } catch (RaoException e) { + throw new AssertionFailedError("xmlrpc exception code=" + e.getCode()); + } + try { + boolean success = api.existsPage(wikiName, spaceName, pageName); + assertTrue(success); + if (success) { + Comments cmnts = api.getPageComments(wikiName, spaceName, pageName); + List 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 0000000000000000000000000000000000000000..fad651f8c89b9577f20dc1ab79865652adcb90ac GIT binary patch literal 261 zcmeAS@N?(olHy`uVBq!ia0vp^YCtT-!3HF6x9U{@DVAa<&kznEsNqQI0P^>Ex;Tb- zblwef4Q+~7dhVn$4#xTKGEXBJ6Z?3*tpL2vaaLTp| ztDWDahXhvbUVS=U@AHQv@;T>i%YPQV(>&C^?^-^?Ha#=uKW=Y#3*1fs`h&sK)z4*} HQ$iB}ImK(* literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a63fb681788b8a4ff4d4367eaee2934a8ffeb33c GIT binary patch literal 16900 zcmb4K6f0JoLh%B{o#5^icXumN+}h&qPK&#{z0dDYct7mj zue;~W*_pd{CPGa`4jqLU1pok`E6Bq%{@daITTsY#U3E`63<=;E7ga+kptR!k^>Q&P&GNmHb) zbJ1}t(C_TNp0&~mwyur_mpr{VT_-Br4|VQ&u6wOJf9{F6&9o0SeuAhp8n zKgz||i$|U3CWoqO5|OFc4x)QDrlHTgJtmh(Ah!5`g%!WKOwlPETah{myN!rvPJA2b zFf>9QbH@!T|IVF9TeO1S%Rl-QzRl02yd!+}%U#*A*vV{Fb_Kga-TTtnRu`Ge;<7uP zoMX{hBwi%74SMKZcg?8A^N)W+L0NMd+dqA#W%i!8PBY)8t8Mq{-NMHH-L=SLt=RGL zcxNEk&O3a1z5Y=v(&{m!N&-_yqfCLC?mYQ%QfE=Z{XWuV109Y(%k_R>$gCxq8shSi zk2STjAZ{?lQd1{m&T5j=ZJ_@;d;2%l$a%NC|LN{%srpL6lqy_}17;N}Nhycd*=r?{ zIH#D4oIfXCYusWnR-$$G;ps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*4$DUaEsGU?tO znXk1HA8YyUosseMW|4S%=s4RJzHL=8dtPrVtJ_m;^`^{*^TM@qiKv_B-8o;~XPf)C zYHp#4gS_WuuXXqKew^QFH9vEGxkbHv=x%*xViv~(k8_#aA1a>9 ztgg0PHn(uk{$T%8w=XF~1sCl|&CA{DVm&wf`P#->i%azu_v>BWURQ8fbboF7`F@p! zi*3IZSbxbl*Pnh~c;~%BR=azL|3{IB9T+@a{an^LB{Ts50a-(R literal 0 HcmV?d00001 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)