use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.
the class BaseRelationServiceTest method testSaveRelationWithEmptyType.
@Test(expected = DataValidationException.class)
public void testSaveRelationWithEmptyType() throws ExecutionException, InterruptedException {
EntityRelation relation = new EntityRelation();
relation.setFrom(new AssetId(UUIDs.timeBased()));
relation.setTo(new AssetId(UUIDs.timeBased()));
Assert.assertTrue(saveRelation(relation));
}
use of org.thingsboard.server.common.data.relation.EntityRelation 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.relation.EntityRelation in project thingsboard by thingsboard.
the class RestClient method makeRelation.
public EntityRelation makeRelation(String relationType, EntityId idFrom, EntityId idTo) {
EntityRelation relation = new EntityRelation();
relation.setFrom(idFrom);
relation.setTo(idTo);
relation.setType(relationType);
return restTemplate.postForEntity(baseURL + "/api/relation", relation, EntityRelation.class).getBody();
}
Aggregations