more work on testing the broker

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1070 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-07-02 09:31:10 +00:00
parent 07532fad61
commit b0b5e5b781
3 changed files with 23 additions and 7 deletions

View File

@ -239,7 +239,7 @@ public abstract class GridworksBroker extends ButterflyModuleImpl {
output.write(buffer, 0, n);
count += n;
}
return buffer;
return output.toByteArray();
}

View File

@ -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();

View File

@ -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();
}