@Test
public void testPermissions() throws IOException {

  Note note1 = ZeppelinServer.notebook.createNote(null);
  // Set only readers
  String jsonRequest = "{\"readers\":[\"admin-team\"],\"owners\":[]," +
          "\"writers\":[]}";
  PutMethod put = httpPut("/notebook/" + note1.getId() + "/permissions/", jsonRequest);
  LOG.info("testPermissions response\n" + put.getResponseBodyAsString());
  assertThat("test update method:", put, isAllowed());
  put.releaseConnection();
  GetMethod get = httpGet("/notebook/" + note1.getId() + "/permissions/");
  assertThat(get, isAllowed());
  Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
  }.getType());
  Map<String, Set<String>> authInfo = (Map<String, Set<String>>) resp.get("body");
  // Check that both owners and writers is set to the princpal if empty
  assertEquals(authInfo.get("readers"), Lists.newArrayList("admin-team"));
  assertEquals(authInfo.get("owners"), Lists.newArrayList("anonymous"));
  assertEquals(authInfo.get("writers"), Lists.newArrayList("anonymous"));
  get.releaseConnection();
  Note note2 = ZeppelinServer.notebook.createNote(null);
  // Set only writers
  jsonRequest = "{\"readers\":[],\"owners\":[]," +
          "\"writers\":[\"admin-team\"]}";
  put = httpPut("/notebook/" + note2.getId() + "/permissions/", jsonRequest);
  assertThat("test update method:", put, isAllowed());
  put.releaseConnection();
  get = httpGet("/notebook/" + note2.getId() + "/permissions/");
  assertThat(get, isAllowed());
  resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
  }.getType());
  authInfo = (Map<String, Set<String>>) resp.get("body");
  // Check that owners is set to the princpal if empty
  assertEquals(authInfo.get("owners"), Lists.newArrayList("anonymous"));
  assertEquals(authInfo.get("writers"), Lists.newArrayList("admin-team"));
  get.releaseConnection();
  // Test clear permissions
  jsonRequest = "{\"readers\":[],\"owners\":[],\"writers\":[]}";
  put = httpPut("/notebook/" + note2.getId() + "/permissions/", jsonRequest);
  put.releaseConnection();
  get = httpGet("/notebook/" + note2.getId() + "/permissions/");
  assertThat(get, isAllowed());
  resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
  }.getType());
  authInfo = (Map<String, Set<String>>) resp.get("body");
  assertEquals(authInfo.get("readers"), Lists.newArrayList());
  assertEquals(authInfo.get("writers"), Lists.newArrayList());
  assertEquals(authInfo.get("owners"), Lists.newArrayList());
  get.releaseConnection();
  //cleanup
  ZeppelinServer.notebook.removeNote(note1.getId(), null);
  ZeppelinServer.notebook.removeNote(note2.getId(), null);
}