Skip to content

Commit

Permalink
add Document and test
Browse files Browse the repository at this point in the history
  • Loading branch information
linong.cao committed Mar 1, 2012
1 parent 122c038 commit 60cc58b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ctalk/src/com/db/letdb/Document.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.db.letdb;

import com.alibaba.fastjson.JSON;

/**
* @created: Mar 1, 2012
* @author : jias chao<[email protected]>
*/
public class Document {

private String id;

protected String getJsonStr(){
String jstr = JSON.toJSONString(this);
return jstr;
}

protected Document getInstance(String jstr){
Document doc = JSON.parseObject(jstr, Document.class);
return doc;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}
2 changes: 2 additions & 0 deletions ctalk/src/com/db/letdb/LetdbFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ public int sync() throws IOException{
return out.toByteArray().length;
}



}
34 changes: 34 additions & 0 deletions ctalk/test/com/db/letdb/DocumentTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.db.letdb;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Test;

/**
* @created: Mar 1, 2012
* @author : jias chao<[email protected]>
*/
public class DocumentTest {


@Test
public void testDoc2json(){
Document doc = new Document();
assertEquals("{}",doc.getJsonStr());


doc.setId("abc-12");
assertEquals("{\"id\":\"abc-12\"}",doc.getJsonStr());
}


@Test
public void testJson2Doc(){

String str = "{\"id\":\"abc-12\"}";
Document doc = new Document().getInstance(str);
assertEquals("abc-12",doc.getId());
}

}

0 comments on commit 60cc58b

Please sign in to comment.