public void run() {
continueOnFail(false);
sFakeCollection = new AdminCollectionFunctionalTest()
.routeCreateCollection();
// create document
FakeRequest request = new FakeRequest(POST,
getRouteAddress(sFakeCollection));
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
request = request.withJsonBody(document1, POST);
Result result = routeAndCall(request);
assertRoute(result, "testOnlyFields CREATE 1", 200, null, true);
String id1 = getUuid();
// read the doc
request = new FakeRequest(GET, "/document/" + sFakeCollection
+ "/" + id1);
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
result = routeAndCall(request);
assertRoute(result, "testOnlyFields load document 1",
Status.OK, "\"total\":2,\"city\":\"rome\"", true);
// update one fields
request = new FakeRequest("PUT", "/document/" + sFakeCollection
+ "/" + id1 + "/.city");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
request = request.withJsonBody(jsonForUpdate, "PUT");
result = routeAndCall(request);
assertRoute(result, "testOnlyFields fields 1", Status.OK,
"\"city\":\"milan\"", true);
request = new FakeRequest("PUT", "/document/" + sFakeCollection
+ "/" + id1 + "/.tags");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
request = request.withJsonBody(jsonForArrayUpdate, "PUT");
result = routeAndCall(request);
assertRoute(result, "testOnlyFields fields 2", Status.OK,
"\"tags\":[\"one\",\"two\",\"three\"]", true);
request = new FakeRequest("GET", "/document/" + sFakeCollection
+ "/" + id1 + "/.tags%5B0%5D");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
result = routeAndCall(request);
assertRoute(result, "testOnlyFields fields 3", Status.OK,
"\"result\":\"one\"", true);
request = new FakeRequest("PUT", "/document/" + sFakeCollection
+ "/" + id1 + "/.tags%5B3%5D");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
request.withJsonBody(jsonForArrayIndexUpdate, "PUT");
result = routeAndCall(request);
assertRoute(result, "testOnlyFields fields 4", Status.OK,
"\"tags\":[\"one\",\"two\",\"three\",\"four\"]", true);
request = new FakeRequest("PUT", "/document/" + sFakeCollection
+ "/" + id1 + "/.issues");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
request.withJsonBody(jsonForArrayObjectUpdate, "PUT");
result = routeAndCall(request);
assertRoute(result, "testOnlyFields fields 5", Status.OK,
"\"tags\":[\"1\",\"2\",\"3\"]", true);
request = new FakeRequest("PUT", "/document/" + sFakeCollection
+ "/" + id1 + "/.issues%5B0%5D/.status");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
request.withJsonBody(jsonForObjectStatusUpdate, "PUT");
result = routeAndCall(request);
assertRoute(result, "testOnlyFields fields 6", Status.OK,
"\"status\":\"ONGOING\"", true);
request = new FakeRequest("PUT", "/document/" + sFakeCollection
+ "/" + id1 + "/.issues%5B0%5D/.tags%5B3%5D");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
request.withJsonBody(jsonForArrayIndexUpdate, "PUT");
result = routeAndCall(request);
assertRoute(result, "testOnlyFields fields 7", Status.OK,
"\"tags\":[\"1\",\"2\",\"3\",\"four\"]", true);
// issue #243
// create a new user
String user = routeCreateNewUser("user1-");
// give him the read permission
request = new FakeRequest(PUT, "/document/" + sFakeCollection
+ "/" + id1 + "/read/user/" + user);
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
request = request.withHeader(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_FORM_URLENCODED);
result = routeAndCall(request);
assertRoute(result, "testOnlyFields.grant", Status.OK, null,
false);
// try to update a field
request = new FakeRequest("PUT", "/document/" + sFakeCollection
+ "/" + id1 + "/.city");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.encodeAuth(user, "passw1"));
request = request.withJsonBody(jsonForUpdate, "PUT");
result = routeAndCall(request);
assertRoute(result, "testOnlyFields fields 1", 403,
"You have not the right to modify the document", true);
// check if the password is shown
request = new FakeRequest(GET, getRouteAddress(sFakeCollection)
+ "?fields=expand(_allowRead)%20as%20ar");
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.encodeAuth(user, "passw1"));
result = routeAndCall(request);
String sContent = contentAsString(result);
Assert.assertTrue("testOnlyFields fields 2: " + sContent,!sContent.contains("ord\":\""));
// delete collection
request = new FakeRequest(DELETE, "/admin/collection/"
+ sFakeCollection);
request = request.withHeader(TestConfig.KEY_APPCODE,
TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH,
TestConfig.AUTH_ADMIN_ENC);
result = routeAndCall(request);
assertRoute(result, "testOnlyFields delete", Status.OK, null,
false);