use of org.thingsboard.server.common.data.page.TimePageLink in project thingsboard by thingsboard.
the class BaseAlarmServiceTest method testFindAlarm.
@Test
public void testFindAlarm() throws ExecutionException, InterruptedException {
AssetId parentId = new AssetId(UUIDs.timeBased());
AssetId childId = new AssetId(UUIDs.timeBased());
EntityRelation relation = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
Assert.assertTrue(relationService.saveRelationAsync(relation).get());
long ts = System.currentTimeMillis();
Alarm alarm = Alarm.builder().tenantId(tenantId).originator(childId).type(TEST_ALARM).propagate(false).severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK).startTs(ts).build();
Alarm created = alarmService.createOrUpdateAlarm(alarm);
// Check child relation
TimePageData<AlarmInfo> alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
Assert.assertNotNull(alarms.getData());
Assert.assertEquals(1, alarms.getData().size());
Assert.assertEquals(created, alarms.getData().get(0));
// Check parent relation
alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(parentId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
Assert.assertNotNull(alarms.getData());
Assert.assertEquals(0, alarms.getData().size());
created.setPropagate(true);
created = alarmService.createOrUpdateAlarm(created);
// Check child relation
alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
Assert.assertNotNull(alarms.getData());
Assert.assertEquals(1, alarms.getData().size());
Assert.assertEquals(created, alarms.getData().get(0));
// Check parent relation
alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(parentId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
Assert.assertNotNull(alarms.getData());
Assert.assertEquals(1, alarms.getData().size());
Assert.assertEquals(created, alarms.getData().get(0));
alarmService.ackAlarm(created.getId(), System.currentTimeMillis()).get();
created = alarmService.findAlarmByIdAsync(created.getId()).get();
alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.ACTIVE_ACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
Assert.assertNotNull(alarms.getData());
Assert.assertEquals(1, alarms.getData().size());
Assert.assertEquals(created, alarms.getData().get(0));
// Check not existing relation
alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.ACTIVE_UNACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
Assert.assertNotNull(alarms.getData());
Assert.assertEquals(0, alarms.getData().size());
alarmService.clearAlarm(created.getId(), System.currentTimeMillis()).get();
created = alarmService.findAlarmByIdAsync(created.getId()).get();
alarms = alarmService.findAlarms(AlarmQuery.builder().affectedEntityId(childId).status(AlarmStatus.CLEARED_ACK).pageLink(new TimePageLink(1, 0L, System.currentTimeMillis(), false)).build()).get();
Assert.assertNotNull(alarms.getData());
Assert.assertEquals(1, alarms.getData().size());
Assert.assertEquals(created, alarms.getData().get(0));
}
use of org.thingsboard.server.common.data.page.TimePageLink 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.page.TimePageLink 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.page.TimePageLink in project thingsboard by thingsboard.
the class BaseAuditLogControllerTest method testAuditLogs.
@Test
public void testAuditLogs() throws Exception {
for (int i = 0; i < 178; i++) {
Device device = new Device();
device.setName("Device" + i);
device.setType("default");
doPost("/api/device", device, Device.class);
}
List<AuditLog> loadedAuditLogs = new ArrayList<>();
TimePageLink pageLink = new TimePageLink(23);
TimePageData<AuditLog> pageData;
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
loadedAuditLogs = new ArrayList<>();
pageLink = new TimePageLink(23);
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs/customer/" + ModelConstants.NULL_UUID + "?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
loadedAuditLogs = new ArrayList<>();
pageLink = new TimePageLink(23);
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs/user/" + tenantAdmin.getId().getId().toString() + "?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
}
use of org.thingsboard.server.common.data.page.TimePageLink in project thingsboard by thingsboard.
the class BaseAuditLogControllerTest method testAuditLogs_byTenantIdAndEntityId.
@Test
public void testAuditLogs_byTenantIdAndEntityId() throws Exception {
Device device = new Device();
device.setName("Device name");
device.setType("default");
Device savedDevice = doPost("/api/device", device, Device.class);
for (int i = 0; i < 178; i++) {
savedDevice.setName("Device name" + i);
doPost("/api/device", savedDevice, Device.class);
}
List<AuditLog> loadedAuditLogs = new ArrayList<>();
TimePageLink pageLink = new TimePageLink(23);
TimePageData<AuditLog> pageData;
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs/entity/DEVICE/" + savedDevice.getId().getId() + "?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(179, loadedAuditLogs.size());
}
Aggregations