Skip to content

Commit

Permalink
added Unit Tests for Ral.
Browse files Browse the repository at this point in the history
  • Loading branch information
sasinda committed Aug 19, 2012
1 parent 2889179 commit 6de53c7
Show file tree
Hide file tree
Showing 46 changed files with 1,281 additions and 3,180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.File;

import org.xwiki.android.xmodel.entity.DocumentBase;
import org.xwiki.android.xmodel.entity.XWikiPage;

public interface FileStoreManager
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.File;

import org.xwiki.android.context.XWikiApplicationContext;
import org.xwiki.android.xmodel.entity.DocumentBase;
import org.xwiki.android.xmodel.entity.XWikiPage;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.xwiki.android.entity.SyncOutEntity;
import org.xwiki.android.entity.User;
import org.xwiki.android.rest.reference.DocumentReference;
import org.xwiki.android.xmodel.entity.DocumentBase;
import org.xwiki.android.xmodel.entity.XWikiPage;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
Expand Down
33 changes: 4 additions & 29 deletions xwiki-android-core/src/org/xwiki/android/rest/ral/DocumentRao.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@

public interface DocumentRao extends Rao<Document>
{
//parts of a doc.
int PAGE = 1;
/**
* all Objects except comment and tag objects.
*/
int OBJECTS = 2;
int COMMENTS = 4;
int TAGS = 8;
int ATTACHMENTS = 16;
int COMMENT_OBJECTS=32;
int TAG_OBJECT=64;
int ALL = 2147483647;


/**
* semantics:
Expand Down Expand Up @@ -57,23 +46,9 @@ public interface DocumentRao extends Rao<Document>
*/
Document retreive(DocumentReference dref) throws RestConnectionException, RaoException;

// TODO: SPECIFY default semantics ;-)
/**
*
* @param dref ex: flags=OBJECTS+TAGS. Loads a Document object with XObjects and tags only.
* @param flags
* @return
*/
Document retreive(DocumentReference dref, int flags);
/**
*
* @param dref
* @param flags
* @param objTypeArgs
* ex: Blog.BlogPostClass:0:2 blog post objects from index 0 to 2. i.e 3 objs if available.
* @return
*/
Document retreive(DocumentReference dref, int flags, String... objTypeArgs);
Document retreive(DocumentReference dref, FetchConfig lazyConfig) throws RestConnectionException, RaoException;

Document retreive(Document doc, FetchConfig lazyConfig);

void delete(DocumentReference dRef) throws RestConnectionException, RaoException;
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
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;
import org.xwiki.android.rest.XWikiRestConnector;
import org.xwiki.android.rest.rpc.RestClient;

public interface RESTfulManager
{
{
DocumentRao newDocumentRao();

SpaceRao newSpaceRao();

WikiRao newWikiRao();

RestClient getRestClient();

RestConnection getConnection();



@Deprecated
XWikiRestConnector getRestConnector();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import org.xwiki.android.resources.Tags;
import org.xwiki.android.rest.RestConnectionException;
import org.xwiki.android.rest.RestException;
import org.xwiki.android.rest.XWikiRestConnecion;
import org.xwiki.android.rest.XWikiAPI;
import org.xwiki.android.rest.XWikiRestConnector;
import org.xwiki.android.rest.ral.algo.DocRetreiveStrategy;
import org.xwiki.android.rest.ral.algo.DocUpdateStrategy;
import org.xwiki.android.rest.ral.algo.IDocRetreiveStrategy;
import org.xwiki.android.rest.ral.algo.IDocUpdateStragegy;
import org.xwiki.android.rest.reference.DocumentReference;
import org.xwiki.android.rest.rpc.XWikiAPI;
import org.xwiki.android.rest.transformation.DocLaunchPadForXML;
import org.xwiki.android.rest.transformation.DocumentDismantler_XML;
import org.xwiki.android.xmodel.entity.Attachment;
Expand Down Expand Up @@ -57,7 +57,7 @@ class XmlDocumentRao implements DocumentRao
public XmlDocumentRao(String serverUrl, String username, String password)
{

api = new XWikiRestConnecion(serverUrl, username, password);
api = new XWikiRestConnector(serverUrl, username, password);
retStr = new DocRetreiveStrategy(username, password, serverUrl);
updStr = new DocUpdateStrategy(serverUrl, username, password);
// consider IoC to app context
Expand Down Expand Up @@ -200,11 +200,13 @@ public int compare(Object object1, Object object2)
int start = used;
int end = Math.min(avail, used + needed);
for (int j = used; j < end; j++) {
Comment cnw=newCmnts.get(j);
Comment cnw=newCmnts.get(j);
int tmpId=cnw.getId();
cnw.setId(++svrCmntId);
api.addPageComment(wikiName, spaceName, pageName, cnw);
svrCmntId++;

for(Comment c:newCmnts){
if(c.getReplyTo()==cnw.getId()){
if(c.getReplyTo()!=null && c.getReplyTo()==tmpId){
c.setReplyTo(svrCmntId);
}
}
Expand All @@ -223,10 +225,11 @@ public int compare(Object object1, Object object2)
if(used<avail){
for (int i = used; i < newCmnts.size(); i++){
Comment prnt=newCmnts.get(i);
api.addPageComment(wikiName, spaceName, pageName, prnt);
svrCmntId++;
int tmpId=prnt.getId();
prnt.setId(++svrCmntId);
api.addPageComment(wikiName, spaceName, pageName, prnt);
for(Comment child:newCmnts){
if(child.getReplyTo()==prnt.getId()){
if(child.getReplyTo()!=null &&child.getReplyTo()==tmpId){
child.setReplyTo(svrCmntId);
}
}
Expand All @@ -243,7 +246,7 @@ public int compare(Object object1, Object object2)
for (Attachment a : pad.getAttatchmentsToupload()) {
File f=a.getFile();
if(f!=null){
String filePath=f.getAbsolutePath();
String filePath=f.getParentFile().getAbsolutePath()+"/";
String attachmentName=a.getName();
api.putPageAttachment(wikiName, spaceName, pageName, filePath, attachmentName);
}else{
Expand Down Expand Up @@ -290,23 +293,24 @@ public Document retreive(Document doc) throws RestConnectionException, RaoExcept
{
return retStr.retreive(doc);
}

@Override
public Document retreive(DocumentReference dref) throws RestConnectionException, RaoException
public Document retreive(Document doc, FetchConfig lazyConfig)
{
return retStr.retreive(dref);
// TODO Auto-generated method stub
return null;
}

@Override
public Document retreive(DocumentReference dref, int flags)
public Document retreive(DocumentReference dref) throws RestConnectionException, RaoException
{
return retStr.retreive(dref, flags);
return retStr.retreive(dref);
}

@Override
public Document retreive(DocumentReference dref, int flags, String... objTypeArgs)
public Document retreive(DocumentReference dref, FetchConfig lazyConfig)
{
return retStr.retreive(dref, flags, objTypeArgs);
return retStr.retreive(dref, lazyConfig);
}

@Override
Expand Down Expand Up @@ -344,4 +348,6 @@ public void delete(Document resrc) throws RestConnectionException, RaoException
delete(resrc.getDocumentReference());
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

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;
import org.xwiki.android.rest.XWikiRestConnector;
import org.xwiki.android.rest.rpc.RestClient;

public class XmlRESTFulManager implements RESTfulManager
{
Expand Down Expand Up @@ -57,11 +53,19 @@ public WikiRao newWikiRao()
}

@Override
public RestConnection getConnection()
public RestClient getRestClient()
{
return new XWikiRestConnecion(serverUrl,username,password);
throw new UnsupportedOperationException("under construction. see rest.rpc package in rest module");
}

@Override
public XWikiRestConnector getRestConnector()
{
return new XWikiRestConnector(serverUrl, username, password);
}





}
Loading

0 comments on commit 6de53c7

Please sign in to comment.