|
|
@ -31,7 +31,9 @@ import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.page.TimePageData; |
|
|
import org.thingsboard.server.common.data.page.TimePageData; |
|
|
import org.thingsboard.server.common.data.page.TimePageLink; |
|
|
import org.thingsboard.server.common.data.page.TimePageLink; |
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
import org.thingsboard.server.common.data.relation.EntityRelation; |
|
|
|
|
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.concurrent.ExecutionException; |
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
|
public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
|
|
public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
|
|
@ -184,4 +186,85 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
|
|
Assert.assertEquals(1, alarms.getData().size()); |
|
|
Assert.assertEquals(1, alarms.getData().size()); |
|
|
Assert.assertEquals(created, alarms.getData().get(0)); |
|
|
Assert.assertEquals(created, alarms.getData().get(0)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void testDeleteAlarm() 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(tenantId, relation).get()); |
|
|
|
|
|
|
|
|
|
|
|
long ts = System.currentTimeMillis(); |
|
|
|
|
|
Alarm alarm = Alarm.builder().tenantId(tenantId).originator(childId) |
|
|
|
|
|
.type(TEST_ALARM) |
|
|
|
|
|
.propagate(true) |
|
|
|
|
|
.severity(AlarmSeverity.CRITICAL).status(AlarmStatus.ACTIVE_UNACK) |
|
|
|
|
|
.startTs(ts).build(); |
|
|
|
|
|
|
|
|
|
|
|
Alarm created = alarmService.createOrUpdateAlarm(alarm); |
|
|
|
|
|
|
|
|
|
|
|
TimePageData<AlarmInfo> alarms = alarmService.findAlarms(tenantId, 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(tenantId, 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)); |
|
|
|
|
|
|
|
|
|
|
|
List<EntityRelation> toAlarmRelations = relationService.findByTo(tenantId, created.getId(), RelationTypeGroup.ALARM); |
|
|
|
|
|
Assert.assertEquals(8, toAlarmRelations.size()); |
|
|
|
|
|
|
|
|
|
|
|
List<EntityRelation> fromChildRelations = relationService.findByFrom(tenantId, childId, RelationTypeGroup.ALARM); |
|
|
|
|
|
Assert.assertEquals(4, fromChildRelations.size()); |
|
|
|
|
|
|
|
|
|
|
|
List<EntityRelation> fromParentRelations = relationService.findByFrom(tenantId, childId, RelationTypeGroup.ALARM); |
|
|
|
|
|
Assert.assertEquals(4, fromParentRelations.size()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue("Alarm was not deleted when expected", alarmService.deleteAlarm(tenantId, created.getId())); |
|
|
|
|
|
|
|
|
|
|
|
Alarm fetched = alarmService.findAlarmByIdAsync(tenantId, created.getId()).get(); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertNull("Alarm was returned when it was expected to be null", fetched); |
|
|
|
|
|
|
|
|
|
|
|
alarms = alarmService.findAlarms(tenantId, 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()); |
|
|
|
|
|
|
|
|
|
|
|
// Check parent relation
|
|
|
|
|
|
alarms = alarmService.findAlarms(tenantId, 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()); |
|
|
|
|
|
|
|
|
|
|
|
toAlarmRelations = relationService.findByTo(tenantId, created.getId(), RelationTypeGroup.ALARM); |
|
|
|
|
|
Assert.assertEquals(0, toAlarmRelations.size()); |
|
|
|
|
|
|
|
|
|
|
|
fromChildRelations = relationService.findByFrom(tenantId, childId, RelationTypeGroup.ALARM); |
|
|
|
|
|
Assert.assertEquals(0, fromChildRelations.size()); |
|
|
|
|
|
|
|
|
|
|
|
fromParentRelations = relationService.findByFrom(tenantId, childId, RelationTypeGroup.ALARM); |
|
|
|
|
|
Assert.assertEquals(0, fromParentRelations.size()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|