Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added project files

  • Loading branch information...
commit 348a81075a8e0598d35ce4a26b35a0d808d8e36f 1 parent 806f733
Kami Development AB kamidev authored
17 AndroidManifest.xml
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="se.msc.android.droidcouch"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".TestClient"
+ android:label="DroidCouch test client">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+ <uses-sdk android:minSdkVersion="3" />
+ <uses-permission android:name="android.permission.INTERNET"></uses-permission>
+</manifest>
13 default.properties
View
@@ -0,0 +1,13 @@
+# 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 use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Indicates whether an apk should be generated for each density.
+split.density=false
+# Project target.
+target=android-3
BIN  res/drawable/icon.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 res/layout/main.xml
View
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+<TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/hello"
+ />
+</LinearLayout>
5 res/values/strings.xml
View
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Running tests...\n\n</string>
+ <string name="app_name">DroidCouch Test client</string>
+</resources>
494 src/se/msc/android/droidcouch/DroidCouch.java
View
@@ -0,0 +1,494 @@
+package se.msc.android.droidcouch;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Random;
+import java.util.zip.GZIPInputStream;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.json.JSONException;
+import org.json.JSONObject;
+import android.util.Log;
+
+public class DroidCouch {
+ private static final String TAG = "DroidCouchLibrary";
+
+ public static String convertStreamToString(InputStream is) {
+ /*
+ * To convert the InputStream to String we use the
+ * BufferedReader.readLine() method. We iterate until the BufferedReader
+ * return null which means there's no more data to read. Each line will
+ * appended to a StringBuilder and returned as String.
+ *
+ * (c) public domain:
+ * http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/
+ * 11/a-simple-restful-client-at-android/
+ */
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ StringBuilder sb = new StringBuilder();
+
+ String line = null;
+ try {
+ while ((line = reader.readLine()) != null) {
+ sb.append(line + "\n");
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return sb.toString();
+ }
+
+ public static boolean createDatabase(String hostUrl, String databaseName) {
+ try {
+ HttpPut httpPutRequest = new HttpPut(hostUrl + databaseName);
+ JSONObject jsonResult = sendCouchRequest(httpPutRequest);
+ return jsonResult.getBoolean("ok");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
+ * @return the revision id of the created document
+ */
+ public static String createDocument(String hostUrl, String databaseName,
+ String docId, JSONObject jsonDoc) {
+ try {
+ HttpPut httpPutRequest = new HttpPut(hostUrl + databaseName + "/"
+ + docId);
+ StringEntity body = new StringEntity(jsonDoc.toString());
+ httpPutRequest.setEntity(body);
+ httpPutRequest.setHeader("Accept", "application/json");
+ httpPutRequest.setHeader("Content-type", "application/json");
+ JSONObject jsonResult = sendCouchRequest(httpPutRequest);
+ if (!jsonResult.getBoolean("ok")) {
+ return null; // Not ok!
+ }
+ return jsonResult.getString("rev");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static boolean deleteDatabase(String hostUrl, String databaseName) {
+ try {
+ HttpDelete httpDeleteRequest = new HttpDelete(hostUrl
+ + databaseName);
+ JSONObject jsonResult = sendCouchRequest(httpDeleteRequest);
+ return jsonResult.getBoolean("ok");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
+ * @return true if document successfully deleted
+ */
+ public static boolean deleteDocument(String hostUrl, String databaseName,
+ String docId) {
+ try {
+ JSONObject jsonDoc = getDocument(hostUrl, databaseName, docId);
+ return deleteDocument(hostUrl, databaseName, docId, jsonDoc
+ .getString("_rev"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
+ * @return true if document successfully deleted
+ */
+ public static boolean deleteDocument(String hostUrl, String databaseName,
+ String docId, String rev) {
+ try {
+ String url = hostUrl + databaseName + "/" + docId + "?rev=" + rev;
+ HttpDelete httpDeleteRequest = new HttpDelete(url);
+ JSONObject jsonResult = sendCouchRequest(httpDeleteRequest);
+ if (jsonResult != null) {
+ return jsonResult.getBoolean("ok");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ public static JSONObject get(String url) {
+ DefaultHttpClient httpclient = new DefaultHttpClient();
+ // Prepare a request object
+ HttpGet httpget = new HttpGet(url);
+ // Execute the request
+ HttpResponse response;
+ JSONObject json = null;
+ try {
+ response = httpclient.execute(httpget);
+ // Examine the response status
+ Log.i(TAG, response.getStatusLine().toString());
+
+ // Get hold of the response entity
+ HttpEntity entity = response.getEntity();
+ // If the response does not enclose an entity, there is no need
+ // to worry about connection release
+
+ if (entity != null) {
+ // A Simple JSON Response Read
+ InputStream instream = entity.getContent();
+ String result = convertStreamToString(instream);
+ // Log.i(TAG, result);
+
+ // A Simple JSONObject Creation
+ json = new JSONObject(result);
+ Log.i(TAG, json.toString(2));
+ // Closing the input stream will trigger connection release
+ instream.close();
+ }
+ } catch (Exception e) {
+ // String timestamp =
+ // TimestampFormatter.getInstance().getTimestamp();
+ Log.e(TAG, getStacktrace(e));
+ return null;
+ }
+ return json;
+ }
+
+ /**
+ * @return the Json document
+ */
+ public static JSONObject getDocument(String hostUrl, String databaseName,
+ String docId) {
+ try {
+ HttpGet httpGetRequest = new HttpGet(hostUrl + databaseName + "/"
+ + docId);
+ JSONObject jsonResult = sendCouchRequest(httpGetRequest);
+ if (jsonResult != null) {
+ return jsonResult;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static String getStacktrace(Throwable e) {
+ final Writer trace = new StringWriter();
+ e.printStackTrace(new PrintWriter(trace));
+ return trace.toString();
+ }
+
+ /**
+ * @return a Json object, null on error
+ */
+ private static JSONObject sendCouchRequest(HttpUriRequest request) {
+ try {
+ HttpResponse httpResponse = (HttpResponse) new DefaultHttpClient()
+ .execute(request);
+ HttpEntity entity = httpResponse.getEntity();
+ if (entity != null) {
+ // Read the content stream
+ InputStream instream = entity.getContent();
+ // Convert content stream to a String
+ String resultString = convertStreamToString(instream);
+ instream.close();
+ // Transform the String into a JSONObject
+ JSONObject jsonResult = new JSONObject(resultString);
+ return jsonResult;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * @return the revision id of the updated document
+ */
+ public static String updateDocument(String hostUrl, String databaseName,
+ JSONObject jsonDoc) {
+ try {
+ String docId = jsonDoc.getString("_id");
+ HttpPut httpPutRequest = new HttpPut(hostUrl + databaseName + "/"
+ + docId);
+ StringEntity body = new StringEntity(jsonDoc.toString());
+ httpPutRequest.setEntity(body);
+ httpPutRequest.setHeader("Accept", "application/json");
+ httpPutRequest.setHeader("Content-type", "application/json");
+ JSONObject jsonResult = sendCouchRequest(httpPutRequest);
+ if (!jsonResult.getBoolean("ok")) {
+ return null; // Not ok!
+ }
+ return jsonResult.getString("rev");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * @return a Json document with all documents in the database
+ */
+ public static JSONObject getAllDocuments(String hostUrl, String databaseName) {
+ try {
+ String url = hostUrl + databaseName
+ + "/_all_docs?include_docs=true";
+ HttpGet httpGetRequest = new HttpGet(url);
+ JSONObject jsonReceive = sendCouchRequest(httpGetRequest);
+ if (jsonReceive != null) {
+ return jsonReceive;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ // public static JSONObject SendHttpPut(String url, JSONObject jsonObjSend)
+ // {
+ // JSONObject jsonObjRecv = new JSONObject();
+ // DefaultHttpClient httpclient = new DefaultHttpClient();
+ // try {
+ // String current_id = jsonObjSend.getString("_id");
+ // HttpPut httpPutRequest = new HttpPut(url + "/" + current_id);
+ // StringEntity se;
+ // se = new StringEntity(jsonObjSend.toString());
+ // httpPutRequest.setEntity(se);
+ // httpPutRequest.setHeader("Accept", "application/json");
+ // httpPutRequest.setHeader("Content-type", "application/json");
+ // long t = System.currentTimeMillis();
+ // HttpResponse response = (HttpResponse) httpclient
+ // .execute(httpPutRequest);
+ // Log.i(TAG, "HTTPResponse received in ["
+ // + (System.currentTimeMillis() - t) + "ms]");
+ // // Get hold of the response entity (-> the data):
+ // HttpEntity entity = response.getEntity();
+ // if (entity != null) {
+ // // Read the content stream
+ // InputStream instream = entity.getContent();
+ // Header contentEncoding = response
+ // .getFirstHeader("Content-Encoding");
+ // if (contentEncoding != null
+ // && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
+ // instream = new GZIPInputStream(instream);
+ // }
+ // // convert content stream to a String
+ // String resultString = convertStreamToString(instream);
+ // instream.close();
+ // // Transform the String into a JSONObject
+ // jsonObjRecv = new JSONObject(resultString);
+ // // Raw DEBUG output of our received JSON object:
+ // Log.i(TAG, jsonObjRecv.toString(2));
+ // }
+ // } catch (Exception e) {
+ // // More about HTTP exception handling in another tutorial.
+ // // For now we just print the stack trace.
+ // e.printStackTrace();
+ // }
+ // return jsonObjRecv;
+ // }
+ //
+ // public static JSONObject SendHttpPutAttachment(String url,
+ // JSONObject sender, String attachment, String data, String mimetype) {
+ // JSONObject jsonObjRecv = new JSONObject();
+ // DefaultHttpClient httpclient = new DefaultHttpClient();
+ // try {
+ // String id = sender.getString("_id");
+ // String rev = sender.getString("_rev");
+ // HttpPut httpPutRequest = new HttpPut(url + "/" + id + "/"
+ // + attachment + "?rev=" + rev);
+ // StringEntity se;
+ // se = new StringEntity(data);
+ // httpPutRequest.setEntity(se);
+ // // httpPutRequest.setHeader("Content-length",
+ // // Integer.toString(attachment.length()));
+ // httpPutRequest.setHeader("Content-type", mimetype);
+ // long t = System.currentTimeMillis();
+ // HttpResponse response = (HttpResponse) httpclient
+ // .execute(httpPutRequest);
+ // Log.i(TAG, "HTTPResponse received in ["
+ // + (System.currentTimeMillis() - t) + "ms]");
+ // // Get hold of the response entity (-> the data):
+ // HttpEntity entity = response.getEntity();
+ // if (entity != null) {
+ // // Read the content stream
+ // InputStream instream = entity.getContent();
+ // Header contentEncoding = response
+ // .getFirstHeader("Content-Encoding");
+ // if (contentEncoding != null
+ // && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
+ // instream = new GZIPInputStream(instream);
+ // }
+ // // convert content stream to a String
+ // String resultString = convertStreamToString(instream);
+ // instream.close();
+ // // Transform the String into a JSONObject
+ // jsonObjRecv = new JSONObject(resultString);
+ // // Raw DEBUG output of our received JSON object:
+ // Log.i(TAG, jsonObjRecv.toString(2));
+ // }
+ // } catch (Exception e) {
+ // // More about HTTP exception handling in another tutorial.
+ // // For now we just print the stack trace.
+ // e.printStackTrace();
+ // }
+ // return jsonObjRecv;
+ // }
+
+ // public static JSONObject SendHttpPost(String url, JSONObject jsonObjSend)
+ // {
+ // JSONObject jsonObjRecv = new JSONObject();
+ // DefaultHttpClient httpclient = new DefaultHttpClient();
+ // try {
+ //
+ // HttpPost httpPostRequest = new HttpPost(url);
+ // StringEntity se;
+ // se = new StringEntity(jsonObjSend.toString());
+ // // Set HTTP parameters
+ // httpPostRequest.setEntity(se);
+ // httpPostRequest.setHeader("Accept", "application/json");
+ // httpPostRequest.setHeader("Content-type", "application/json");
+ // long t = System.currentTimeMillis();
+ // HttpResponse response = (HttpResponse) httpclient
+ // .execute(httpPostRequest);
+ // Log.i(TAG, "HTTPResponse received in ["
+ // + (System.currentTimeMillis() - t) + "ms]");
+ // // Get hold of the response entity (-> the data):
+ // HttpEntity entity = response.getEntity();
+ // if (entity != null) {
+ // // Read the content stream
+ // InputStream instream = entity.getContent();
+ // Header contentEncoding = response
+ // .getFirstHeader("Content-Encoding");
+ // if (contentEncoding != null
+ // && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
+ // instream = new GZIPInputStream(instream);
+ // }
+ // // convert content stream to a String
+ // String resultString = convertStreamToString(instream);
+ // instream.close();
+ // // Transform the String into a JSONObject
+ // jsonObjRecv = new JSONObject(resultString);
+ // // Raw DEBUG output of our received JSON object:
+ // Log.i(TAG, jsonObjRecv.toString(2));
+ // }
+ // } catch (Exception e) {
+ // // More about HTTP exception handling in another tutorial.
+ // // For now we just print the stack trace.
+ // e.printStackTrace();
+ // }
+ // return jsonObjRecv;
+ // }
+ //
+ // public static JSONObject DeleteHttpDelete(String url) {
+ // DefaultHttpClient httpclient = new DefaultHttpClient();
+ // // Prepare a request object
+ // HttpDelete httpDelete = new HttpDelete(url);
+ // // Execute the request
+ // HttpResponse response;
+ // JSONObject json = null;
+ // try {
+ // response = httpclient.execute(httpDelete);
+ // // Examine the response status
+ // Log.i(TAG, response.getStatusLine().toString());
+ //
+ // // Get hold of the response entity
+ // HttpEntity entity = response.getEntity();
+ // // If the response does not enclose an entity, there is no need
+ // // to worry about connection release
+ //
+ // if (entity != null) {
+ // // A Simple JSON Response Read
+ // InputStream instream = entity.getContent();
+ // String result = convertStreamToString(instream);
+ // Log.i(TAG, result);
+ //
+ // // A Simple JSONObject Creation
+ // json = new JSONObject(result);
+ // Log.i(TAG, json.toString(2));
+ //
+ // // Closing the input stream will trigger connection release
+ // instream.close();
+ // }
+ // } catch (ClientProtocolException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // } catch (IOException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // } catch (JSONException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // return json;
+ // }
+
+ // public static JSONObject getSampleData(String url, String status) {
+ // // JSON object to hold the information, which is sent to the server
+ // JSONObject jsonObjSend = new JSONObject();
+ //
+ // try {
+ // // Add key/value pairs
+ // Random generator = new Random();
+ // int newKey = generator.nextInt(Integer.MAX_VALUE);
+ // jsonObjSend.put("_id", Integer.toString(newKey));
+ // jsonObjSend.put("status", status);
+ // jsonObjSend.put("customer", "Imerica");
+ //
+ // // Add nested JSONObject (e.g. for header information)
+ // JSONObject header = new JSONObject();
+ // header.put("deviceType", "Android"); // Device type
+ // header.put("deviceVersion", "1.5"); // Device OS version
+ // header.put("language", "sv-se"); // Language of the Android client
+ // jsonObjSend.put("header", header);
+ //
+ // // Add hardcoded inline attachment
+ // JSONObject attachment = new JSONObject();
+ // JSONObject doc = new JSONObject();
+ // // doc.put("content_type", "text/plain");
+ // doc.put("content_type", "image/jpeg");
+ // // Base64 encoded image of red spot
+ // String imageData =
+ // "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP"
+ // + "C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA"
+ // + "AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J"
+ // + "REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq"
+ // + "ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0"
+ // + "vr4MkhoXe0rZigAAAABJRU5ErkJggg==";
+ // // Base64 encoded text
+ // // String textData = "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=";
+ // doc.put("data", imageData);
+ // attachment.put("sig.jpeg", doc);
+ // jsonObjSend.put("_attachments", attachment);
+ //
+ // // Output the JSON object we're sending to logcat:
+ // Log.i(TAG, jsonObjSend.toString(2));
+ //
+ // } catch (JSONException e) {
+ // e.printStackTrace();
+ // }
+ // return jsonObjSend;
+ // }
+
+}
118 src/se/msc/android/droidcouch/TestClient.java
View
@@ -0,0 +1,118 @@
+package se.msc.android.droidcouch;
+
+import org.json.JSONObject;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+
+public class TestClient extends Activity {
+
+ //String HOST = "ADD_YOUR_OWN_COUCHDB_SERVER_HERE";
+ String HOST = "http://wm.gjallar.se:5984/";
+
+ String DBNAME = "hackathon_2";
+ String TEST_DOC_ID = "test_document_1";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ TextView view = new TextView(this);
+ view.append("Running tests...\n\n");
+ setContentView(view);
+
+ try {
+ testDatabaseDoesNotExist();
+ testCreateDatabase();
+ testGetDatabaseInfo();
+ testCreateDocument();
+ testGetDocument();
+ testGetAllDocuments();
+ testUpdateDocument();
+ testDeleteDocument();
+ testDeleteDatabase();
+ view.append("All tests passed!");
+ } catch (Exception e) {
+ String trace = DroidCouch.getStacktrace(e);
+ view.append(trace);
+ }
+ }
+
+ public void testCreateDatabase() throws Exception {
+ boolean result = DroidCouch.createDatabase(HOST, DBNAME);
+ shouldBeTrue(result, "Database could not be created!");
+ }
+
+ public void testDatabaseDoesNotExist() throws Exception {
+ String couchUrl = HOST + DBNAME;
+ JSONObject responseObject = DroidCouch.get(couchUrl);
+ String error = responseObject.getString("error");
+ String reason = responseObject.getString("reason");
+ shouldBeTrue(error.equals("not_found"), "Incorrect message recieved");
+ shouldBeTrue(reason.equals("no_db_file"), "Incorrect message recieved");
+ }
+
+ public void testDeleteDatabase() throws Exception {
+ boolean result = DroidCouch.deleteDatabase(HOST, DBNAME);
+ shouldBeTrue(result, "Database could not be deleted!");
+ }
+
+ public void testGetDatabaseInfo() throws Exception {
+ String couchUrl = HOST + DBNAME;
+ JSONObject responseObject = DroidCouch.get(couchUrl);
+ String actualDbName = responseObject.getString("db_name");
+ shouldBeTrue(DBNAME.equals(actualDbName), "Incorrect message recieved");
+ }
+
+ public void testCreateDocument() throws Exception {
+ JSONObject json = new JSONObject().put("test_key_1", "test_value_1")
+ .put("test_key_2", "test_value_2");
+ String revision = DroidCouch.createDocument(HOST, DBNAME, TEST_DOC_ID,
+ json);
+ shouldBeTrue(null != revision, "Document has no revision number");
+ }
+
+ public void testGetDocument() throws Exception {
+ JSONObject doc = DroidCouch.getDocument(HOST, DBNAME, TEST_DOC_ID);
+ shouldBeTrue(null != doc, "Document is null");
+ shouldBeTrue(doc.getString("test_key_2").equals("test_value_2"),
+ "Wrong value");
+ }
+
+ public void testDeleteDocument() throws Exception {
+ boolean result = DroidCouch.deleteDocument(HOST, DBNAME, TEST_DOC_ID);
+ shouldBeTrue(result, "Document could not be deleted!");
+ }
+
+ public void testUpdateDocument() throws Exception {
+ JSONObject doc = DroidCouch.getDocument(HOST, DBNAME, TEST_DOC_ID);
+ String oldRevision = doc.getString("_rev");
+ doc.put("test_key_1", "updated_test_value_1");
+ String newRevision = DroidCouch.updateDocument(HOST, DBNAME, doc);
+ shouldBeTrue(null != newRevision, "Revision is null");
+ shouldBeTrue(!oldRevision.equals(newRevision),
+ "Revision has not changed!");
+ JSONObject newDoc = DroidCouch.getDocument(HOST, DBNAME, TEST_DOC_ID);
+ shouldBeTrue(newDoc.getString("test_key_1").equals(
+ "updated_test_value_1"), "Wrong value");
+ }
+
+ public void testGetAllDocuments() throws Exception {
+ JSONObject responseObject = DroidCouch.getAllDocuments(HOST, DBNAME);
+ shouldBeTrue(responseObject.has("total_rows"),
+ "Incorrect message recieved");
+ }
+
+
+ public void testPutAttachment() throws Exception {
+ }
+
+ public void testGetAttachment() throws Exception {
+ }
+
+ private void shouldBeTrue(boolean mustBeTrue, String message)
+ throws Exception {
+ if (!mustBeTrue)
+ throw new Exception("Assert failed: " + message);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.