If you think the Android project couchbase-lite-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.couchbase.lite.support;
/*www.java2s.com*/import com.couchbase.lite.Database;
import com.couchbase.lite.LiteTestCase;
import com.couchbase.lite.util.Log;
import org.codehaus.jackson.map.ObjectMapper;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
publicclass JsonDocumentTest extends LiteTestCase {
publicvoid testJsonObject() throws Exception {
Map<String, Object> dict = new HashMap<String, Object>();
dict.put("id","01234567890");
dict.put("foo","bar");
dict.put("int",5);
dict.put("double",3.5);
dict.put("bool",true);
dict.put("date",new Date().toString());
ObjectMapper mapper = new ObjectMapper();
byte[] json = mapper.writeValueAsBytes(dict);
JsonDocument jsdoc = new JsonDocument(json);
assertEquals(dict, jsdoc.jsonObject());
}
publicvoid testJsonArray() throws Exception {
List<Object> array = new ArrayList<Object>();
array.add("01234567890");
array.add("bar");
array.add(5);
array.add(3.5);
array.add(true);
array.add(new Date().toString());
ObjectMapper mapper = new ObjectMapper();
byte[] json = mapper.writeValueAsBytes(array);
JsonDocument jsdoc = new JsonDocument(json);
assertEquals(array, jsdoc.jsonObject());
}
publicvoid testStringFragment() throws Exception {
String fragment = "01234567890";
ObjectMapper mapper = new ObjectMapper();
byte[] json = mapper.writeValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
assertEquals(fragment, jsdoc.jsonObject());
}
publicvoid testBooleanFragment() throws Exception {
Boolean fragment = true;
ObjectMapper mapper = new ObjectMapper();
byte[] json = mapper.writeValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
assertEquals(fragment, jsdoc.jsonObject());
}
publicvoid testIntegerFragment() throws Exception {
Integer fragment = 5;
ObjectMapper mapper = new ObjectMapper();
byte[] json = mapper.writeValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
assertEquals(fragment, jsdoc.jsonObject());
}
publicvoid testDoubleFragment() throws Exception {
Double fragment = 3.5;
ObjectMapper mapper = new ObjectMapper();
byte[] json = mapper.writeValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
assertEquals(fragment, jsdoc.jsonObject());
}
publicvoid testDateFragment() throws Exception {
Date fragment = new Date();
ObjectMapper mapper = new ObjectMapper();
byte[] json = mapper.writeValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
assertEquals(fragment, new Date((Long)jsdoc.jsonObject()));
}
}