@Test
public void testGetEntityWithYarnACLsEnabled() throws Exception {

  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineEntities entities = new TimelineEntities();
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityId("test id 3");
    entity.setEntityType("test type 3");
    entity.setStartTime(System.currentTimeMillis());
    entity.setDomainId("domain_id_1");
    entities.addEntity(entity);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("timeline")
        .queryParam("user.name", "writer_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, entities);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
        response.getType().toString());
    TimelinePutResponse putResponse =
        response.getEntity(TimelinePutResponse.class);
    Assert.assertEquals(0, putResponse.getErrors().size());
    // verify the system data will not be exposed
    // 1. No field specification
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
        response.getType().toString());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));
    // 2. other field
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("fields", "relatedentities")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
        response.getType().toString());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));
    // 3. primaryfilters field
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("fields", "primaryfilters")
        .queryParam("user.name", "reader_user_1")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
        response.getType().toString());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNull(entity.getPrimaryFilters().get(
        TimelineStore.SystemFilter.ENTITY_OWNER.toString()));
    // get entity with other user
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 3").path("test id 3")
        .queryParam("user.name", "reader_user_2")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
        response.getType().toString());
    assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}