@Test
public void testGetEntitiesByRelations() throws Exception {

  // Get entities based on relatesTo.
  TimelineFilterList relatesTo = new TimelineFilterList(Operator.OR);
  Set<Object> relatesToIds =
      new HashSet<Object>(Arrays.asList((Object)"flow1"));
  relatesTo.addFilter(new TimelineKeyValuesFilter(
      TimelineCompareOp.EQUAL, "flow", relatesToIds));
  Set<TimelineEntity> result = reader.getEntities(
      new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1",
      "app", null),
      new TimelineEntityFilters.Builder().relatesTo(relatesTo).build(),
      new TimelineDataToRetrieve());
  Assert.assertEquals(1, result.size());
  // Only one entity with ID id_1 should be returned.
  for (TimelineEntity entity : result) {
    if (!entity.getId().equals("id_1")) {
      Assert.fail("Incorrect filtering based on relatesTo");
    }
  }
  // Get entities based on isRelatedTo.
  TimelineFilterList isRelatedTo = new TimelineFilterList(Operator.OR);
  Set<Object> isRelatedToIds =
      new HashSet<Object>(Arrays.asList((Object)"tid1_2"));
  isRelatedTo.addFilter(new TimelineKeyValuesFilter(
      TimelineCompareOp.EQUAL, "type1", isRelatedToIds));
  result = reader.getEntities(
      new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1",
      "app", null),
      new TimelineEntityFilters.Builder().isRelatedTo(isRelatedTo).build(),
      new TimelineDataToRetrieve());
  Assert.assertEquals(2, result.size());
  // Two entities with IDs' id_1 and id_3 should be returned.
  for (TimelineEntity entity : result) {
    if (!entity.getId().equals("id_1") && !entity.getId().equals("id_3")) {
      Assert.fail("Incorrect filtering based on isRelatedTo");
    }
  }
}