From b0b5e5b78176edf3c5629d709e8a910f2c69777b Mon Sep 17 00:00:00 2001 From: Stefano Mazzocchi Date: Fri, 2 Jul 2010 09:31:10 +0000 Subject: [PATCH] more work on testing the broker git-svn-id: http://google-refine.googlecode.com/svn/trunk@1070 7d457c2a-affb-35e4-300a-418c747d4874 --- .../gridworks/broker/GridworksBroker.java | 2 +- .../gridworks/broker/GridworksBrokerImpl.java | 6 ++++- .../broker/tests/GridworksBrokerTests.java | 22 ++++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/broker/core/src/com/metaweb/gridworks/broker/GridworksBroker.java b/broker/core/src/com/metaweb/gridworks/broker/GridworksBroker.java index a15842622..45556ef00 100644 --- a/broker/core/src/com/metaweb/gridworks/broker/GridworksBroker.java +++ b/broker/core/src/com/metaweb/gridworks/broker/GridworksBroker.java @@ -239,7 +239,7 @@ public abstract class GridworksBroker extends ButterflyModuleImpl { output.write(buffer, 0, n); count += n; } - return buffer; + return output.toByteArray(); } diff --git a/broker/core/src/com/metaweb/gridworks/broker/GridworksBrokerImpl.java b/broker/core/src/com/metaweb/gridworks/broker/GridworksBrokerImpl.java index 524917128..a0a9d24f1 100644 --- a/broker/core/src/com/metaweb/gridworks/broker/GridworksBrokerImpl.java +++ b/broker/core/src/com/metaweb/gridworks/broker/GridworksBrokerImpl.java @@ -210,7 +210,9 @@ public class GridworksBrokerImpl extends GridworksBroker { } } - respond(response, lockToJSON(lock, uid)); + JSONObject o = lockToJSON(lock, uid); + o.put("status", "ok"); + respond(response, o); logger.trace("< obtain lock"); } @@ -342,6 +344,7 @@ public class GridworksBrokerImpl extends GridworksBroker { Writer w = response.getWriter(); JSONWriter writer = new JSONWriter(w); writer.object(); + writer.key("status"); writer.value("ok"); writer.key("data"); writer.value(project.data); writer.key("metadata"); writer.value(new JSONObject(project.metadata)); writer.key("transformations"); @@ -366,6 +369,7 @@ public class GridworksBrokerImpl extends GridworksBroker { JSONWriter writer = new JSONWriter(w); writer.object(); + writer.key("status"); writer.value("ok"); writer.key("transformations"); writer.array(); int size = project.transformations.size(); diff --git a/broker/core/tests/src/com/metaweb/gridworks/broker/tests/GridworksBrokerTests.java b/broker/core/tests/src/com/metaweb/gridworks/broker/tests/GridworksBrokerTests.java index e46b0688a..ed0712439 100644 --- a/broker/core/tests/src/com/metaweb/gridworks/broker/tests/GridworksBrokerTests.java +++ b/broker/core/tests/src/com/metaweb/gridworks/broker/tests/GridworksBrokerTests.java @@ -6,6 +6,7 @@ import static com.metaweb.gridworks.broker.GridworksBroker.GET_STATE; import static com.metaweb.gridworks.broker.GridworksBroker.OBTAIN_LOCK; import static com.metaweb.gridworks.broker.GridworksBroker.RELEASE_LOCK; import static com.metaweb.gridworks.broker.GridworksBroker.START; +import static com.metaweb.gridworks.broker.GridworksBroker.OPEN; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -138,26 +139,37 @@ public class GridworksBrokerTests { @Test public void testStartProject() { try { - JSONObject result = call(broker, request, response, OBTAIN_LOCK, "pid", "1", "uid", "testuser", "locktype", Integer.toString(ALL), "lockvalue", ""); + String project = "1"; + String user = "testuser"; + String data = "blah"; + String metadata = "{}"; + String rev = "0"; + + JSONObject result = call(broker, request, response, OBTAIN_LOCK, "pid", project, "uid", user, "locktype", Integer.toString(ALL), "lockvalue", ""); assertJSON(result, "uid", "testuser"); String lock = result.getString("lock"); - result = call(broker, request, response, START, "pid", "1", "uid", "testuser", "lock", lock, "data", "blah", "metadata", "{}", "rev", "0"); + result = call(broker, request, response, START, "pid", project, "uid", user, "lock", lock, "data", data, "metadata", metadata, "rev", rev); assertJSON(result, "status", "ok"); - result = call(broker, request, response, GET_STATE, "pid", "1", "uid", "testuser", "rev", "0"); + result = call(broker, request, response, GET_STATE, "pid", project, "uid", user, "rev", rev); JSONArray locks = result.getJSONArray("locks"); Assert.assertEquals(locks.length(), 1); JSONObject l = locks.getJSONObject(0); assertJSON(l, "uid", "testuser"); Assert.assertEquals(l.getInt("type"), ALL); - result = call(broker, request, response, RELEASE_LOCK, "pid", "1", "uid", "testuser", "lock", lock); + result = call(broker, request, response, RELEASE_LOCK, "pid", project, "uid", user, "lock", lock); assertJSON(result, "status", "ok"); - result = call(broker, request, response, GET_STATE, "pid", "1", "uid", "testuser", "rev", "0"); + result = call(broker, request, response, GET_STATE, "pid", project, "uid", user, "rev", rev); locks = result.getJSONArray("locks"); Assert.assertEquals(locks.length(), 0); + + result = call(broker, request, response, OPEN, "pid", project, "uid", user, "rev", rev); + assertJSON(result, "status", "ok"); + JSONArray result_data = result.getJSONArray("data"); + Assert.assertEquals(result_data.length(),data.getBytes("UTF-8").length); } catch (Exception e) { Assert.fail(); }