Skip to content

Commit

Permalink
More Tests ;-)
Browse files Browse the repository at this point in the history
FileStore tests.
  • Loading branch information
sasinda committed Aug 19, 2012
1 parent b8ee6c0 commit c1b8000
Show file tree
Hide file tree
Showing 36 changed files with 1,156 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
class DocumentFaoImpSer implements DocumentFao
{

private final String TAG="Document FAO";
private static final String TAG="Document FAO";

private XWikiApplicationContext ctx;
private final File FSDIR;

private static final String tag="DocumentFao";//loggin tag


public DocumentFaoImpSer(XWikiApplicationContext ctx, FileStoreManager mngr)
{
Expand All @@ -50,15 +50,14 @@ public FSDocumentReference save(Document doc, String tag)
String wikiName = doc.getWikiName();
String spaceName = doc.getSpaceName();
String pageName = doc.getPageName();
String dirPath = FSDIR.getAbsolutePath() + wikiName + "/" + spaceName + "/" + pageName;
String dirPath = FSDIR.getAbsolutePath() +"/"+ wikiName + "/" + spaceName + "/" + pageName;
String filePath=dirPath+"/doc.ser";
f = new File(filePath);
boolean success=true;

FSDocumentReference fsref = new FSDocumentReference();
// doc ref data
DocumentReference docref = doc.getDocumentReference();
docref.setServerName(ctx.getUserSession().getRealm());
DocumentReference docref = doc.getDocumentReference();
fsref.copyfrom(docref);
// fs data
fsref.setTag(tag);
Expand All @@ -81,11 +80,14 @@ public FSDocumentReference save(Document doc, String tag)
if(!lst.isEmpty()){
fsref= lst.get(0);
Log.d(TAG,"Doc already saved "+ fsref.getPageName());
return fsref;
if(!(fsref.getTag().equals(tag))){
throw new FileStoreException.UnsupportedOperation("["+tag+"!="+fsref.tag+"] Try to save an already saved document with a different tag. We can have only one tag");
}

}else{
throw new RuntimeException("error in logic");
}
} catch (SQLException e1) {
} catch (SQLException e1) {
Log.e(TAG, "error while retreiving already saved doc's doc ref");
}
}
Expand Down Expand Up @@ -222,7 +224,21 @@ public boolean delete(FSDocumentReference ref)
dao.delete(ref);
}
em.close();
File f = ref.getFile();

File f = ref.getFile();
if(f==null){
String wikiName=ref.getWikiName();
String spaceName=ref.getSpaceName();
String pageName=ref.getPageName();

if(wikiName==null || spaceName==null || pageName==null){
throw new IllegalArgumentException("at least specify wiki,space,page coordinates. If not giving a direct file in fsref");
}
String dirPath=FSDIR.getAbsolutePath() +"/"+ wikiName + "/" + spaceName + "/" + pageName;
String filePath=dirPath+"/doc.ser";
f=new File(filePath);
}

return f.delete();
} catch (SQLException e) {
Log.e(TAG, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public void setFile(File f)
}

public File getFile()
{
if(file==null){
{
if(file==null ){
if(filePath==null)return null;
file=new File(filePath);
}
return this.file;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.xwiki.android.data.fileStore;

public class FileStoreException extends RuntimeException
{

public FileStoreException()
{
super();
}

public FileStoreException(String detailMessage, Throwable throwable)
{
super(detailMessage, throwable);
}

public FileStoreException(String detailMessage)
{
super(detailMessage);
}



public static class DuplicateKey extends FileStoreException
{

public DuplicateKey()
{
super();
}

public DuplicateKey(String detailMessage, Throwable throwable)
{
super(detailMessage, throwable);
}

public DuplicateKey(String detailMessage)
{
super(detailMessage);
}
}

public static class UnsupportedOperation extends FileStoreException{

public UnsupportedOperation()
{
super();
}

public UnsupportedOperation(String detailMessage, Throwable throwable)
{
super(detailMessage, throwable);
}

public UnsupportedOperation(String detailMessage)
{
super(detailMessage);
}


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is intended to be lightweight mimic of a document oriented Database.

Issues:
The File Store needs more specification.
Suggest
key= wikiName, spaceName, pageName, localVersin(new field)
What if user connects to 2 XWiki servers with same coordintates as above but 2 different Xwikis?
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @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.
*/
//TODO: PLEASE SEE THE SUB EXCEPTION TYPES. Make Raos throw them at specific points.
public class RaoException extends Exception
{

Expand Down Expand Up @@ -42,7 +43,7 @@ public RaoException(Throwable throwable)
super(throwable);
// TODO Auto-generated constructor stub
}

public RaoException(RestException rex)
{
super(rex);
Expand All @@ -69,7 +70,25 @@ public void setCode(int code)
{
this.code = code;
}



public class DuplicateDocument extends RaoException
{

}

public class DocumentNotFound extends RaoException
{

}

/**
* when updating a object in a document. Object not found thrown for set obj ops
*
* @author xwiki gsoc 2012
*/
public class ObjectNotFound extends RaoException
{

}

}
Loading

0 comments on commit c1b8000

Please sign in to comment.