@Test
public void findEventsByEntityIdAndEventTypeAndPageLink() {

    UUID tenantId = UUIDs.timeBased();
    UUID entityId1 = UUIDs.timeBased();
    UUID entityId2 = UUIDs.timeBased();
    long startTime = System.currentTimeMillis();
    long endTime = createEventsTwoEntitiesTwoTypes(tenantId, entityId1, entityId2, startTime, 20);
    TimePageLink pageLink1 = new TimePageLink(30, null, null, true);
    List<Event> events1 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink1);
    assertEquals(5, events1.size());
    TimePageLink pageLink2 = new TimePageLink(30, startTime, null, true);
    List<Event> events2 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink2);
    assertEquals(5, events2.size());
    TimePageLink pageLink3 = new TimePageLink(30, startTime, endTime, true);
    List<Event> events3 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink3);
    assertEquals(5, events3.size());
    TimePageLink pageLink4 = new TimePageLink(4, startTime, endTime, true);
    List<Event> events4 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink4);
    assertEquals(4, events4.size());
    UUID idOffset = events3.get(2).getId().getId();
    TimePageLink pageLink5 = new TimePageLink(10, startTime, endTime, true, idOffset);
    List<Event> events5 = eventDao.findEvents(tenantId, new DeviceId(entityId1), ALARM, pageLink5);
    assertEquals(2, events5.size());
}