Search in sources :

Example 36 with DeviceId

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());
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) Event(org.thingsboard.server.common.data.Event) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 37 with DeviceId

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;
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Event(org.thingsboard.server.common.data.Event) EventId(org.thingsboard.server.common.data.id.EventId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 38 with DeviceId

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());
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) Event(org.thingsboard.server.common.data.Event) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 39 with DeviceId

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());
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) Event(org.thingsboard.server.common.data.Event) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 40 with DeviceId

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));
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Aggregations

DeviceId (org.thingsboard.server.common.data.id.DeviceId)42 Test (org.junit.Test)21 Device (org.thingsboard.server.common.data.Device)12 TenantId (org.thingsboard.server.common.data.id.TenantId)10 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)9 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)8 DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)8 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)8 ArrayList (java.util.ArrayList)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Event (org.thingsboard.server.common.data.Event)6 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 UUID (java.util.UUID)5 BooleanDataEntry (org.thingsboard.server.common.data.kv.BooleanDataEntry)5 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)5 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 DeviceAttributes (org.thingsboard.server.extensions.api.device.DeviceAttributes)5 DeviceMetaData (org.thingsboard.server.extensions.api.device.DeviceMetaData)5 Customer (org.thingsboard.server.common.data.Customer)3 DoubleDataEntry (org.thingsboard.server.common.data.kv.DoubleDataEntry)3