use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class JpaBaseEventDaoTest method findEventsByEntityIdAndEventTypeAndPageLink.
@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());
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class JpaBaseEventDaoTest method getEvent.
private Event getEvent(UUID eventId, UUID tenantId, UUID entityId) {
Event event = new Event();
event.setId(new EventId(eventId));
event.setTenantId(new TenantId(tenantId));
EntityId deviceId = new DeviceId(entityId);
event.setEntityId(deviceId);
event.setUid(event.getId().getId().toString());
event.setType(STATS);
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode jsonNode = mapper.readTree("{\"key\":\"value\"}");
event.setBody(jsonNode);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return event;
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class JpaBaseEventDaoTest method findEvent.
@Test
@DatabaseSetup("classpath:dbunit/event.xml")
public void findEvent() {
UUID tenantId = UUID.fromString("be41c7a0-31f5-11e7-9cfd-2786e6aa2046");
UUID entityId = UUID.fromString("be41c7a1-31f5-11e7-9cfd-2786e6aa2046");
String eventType = STATS;
String eventUid = "be41c7a3-31f5-11e7-9cfd-2786e6aa2046";
Event event = eventDao.findEvent(tenantId, new DeviceId(entityId), eventType, eventUid);
eventDao.find().stream().forEach(System.out::println);
assertNotNull("Event expected to be not null", event);
assertEquals("be41c7a2-31f5-11e7-9cfd-2786e6aa2046", event.getId().getId().toString());
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class JpaBaseEventDaoTest method findEventsByEntityIdAndPageLink.
@Test
public void findEventsByEntityIdAndPageLink() {
UUID tenantId = UUIDs.timeBased();
UUID entityId1 = UUIDs.timeBased();
UUID entityId2 = UUIDs.timeBased();
long startTime = System.currentTimeMillis();
long endTime = createEventsTwoEntities(tenantId, entityId1, entityId2, startTime, 20);
TimePageLink pageLink1 = new TimePageLink(30, null, null, true);
List<Event> events1 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink1);
assertEquals(10, events1.size());
TimePageLink pageLink2 = new TimePageLink(30, startTime, null, true);
List<Event> events2 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink2);
assertEquals(10, events2.size());
TimePageLink pageLink3 = new TimePageLink(30, startTime, endTime, true);
List<Event> events3 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink3);
assertEquals(10, events3.size());
TimePageLink pageLink4 = new TimePageLink(5, startTime, endTime, true);
List<Event> events4 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink4);
assertEquals(5, events4.size());
UUID idOffset = events4.get(4).getId().getId();
TimePageLink pageLink5 = new TimePageLink(10, startTime, endTime, true, idOffset);
List<Event> events5 = eventDao.findEvents(tenantId, new DeviceId(entityId1), pageLink5);
assertEquals(5, events5.size());
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class BaseTimeseriesServiceTest method testFindLatest.
@Test
public void testFindLatest() throws Exception {
DeviceId deviceId = new DeviceId(UUIDs.timeBased());
saveEntries(deviceId, TS - 2);
saveEntries(deviceId, TS - 1);
saveEntries(deviceId, TS);
List<TsKvEntry> entries = tsService.findLatest(deviceId, Collections.singleton(STRING_KEY)).get();
Assert.assertEquals(1, entries.size());
Assert.assertEquals(toTsEntry(TS, stringKvEntry), entries.get(0));
}
Aggregations