Search in sources :

Example 1 with EntityRelation

use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.

the class BaseRelationServiceTest method testSaveRelationWithEmptyTo.

@Test(expected = DataValidationException.class)
public void testSaveRelationWithEmptyTo() throws ExecutionException, InterruptedException {
    EntityRelation relation = new EntityRelation();
    relation.setFrom(new AssetId(UUIDs.timeBased()));
    relation.setType(EntityRelation.CONTAINS_TYPE);
    Assert.assertTrue(saveRelation(relation));
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Example 2 with EntityRelation

use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.

the class BaseRelationServiceTest method testDeleteEntityRelations.

@Test
public void testDeleteEntityRelations() throws ExecutionException, InterruptedException {
    AssetId parentId = new AssetId(UUIDs.timeBased());
    AssetId childId = new AssetId(UUIDs.timeBased());
    AssetId subChildId = new AssetId(UUIDs.timeBased());
    EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
    EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE);
    saveRelation(relationA);
    saveRelation(relationB);
    Assert.assertTrue(relationService.deleteEntityRelationsAsync(childId).get());
    Assert.assertFalse(relationService.checkRelation(parentId, childId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());
    Assert.assertFalse(relationService.checkRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Example 3 with EntityRelation

use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.

the class BaseRelationServiceTest method testDeleteRelation.

@Test
public void testDeleteRelation() throws ExecutionException, InterruptedException {
    AssetId parentId = new AssetId(UUIDs.timeBased());
    AssetId childId = new AssetId(UUIDs.timeBased());
    AssetId subChildId = new AssetId(UUIDs.timeBased());
    EntityRelation relationA = new EntityRelation(parentId, childId, EntityRelation.CONTAINS_TYPE);
    EntityRelation relationB = new EntityRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE);
    saveRelation(relationA);
    saveRelation(relationB);
    Assert.assertTrue(relationService.deleteRelationAsync(relationA).get());
    Assert.assertFalse(relationService.checkRelation(parentId, childId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());
    Assert.assertTrue(relationService.checkRelation(childId, subChildId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());
    Assert.assertTrue(relationService.deleteRelationAsync(childId, subChildId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Example 4 with EntityRelation

use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.

the class BaseRelationServiceTest method testSaveRelation.

@Test
public void testSaveRelation() 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(saveRelation(relation));
    Assert.assertTrue(relationService.checkRelation(parentId, childId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());
    Assert.assertFalse(relationService.checkRelation(parentId, childId, "NOT_EXISTING_TYPE", RelationTypeGroup.COMMON).get());
    Assert.assertFalse(relationService.checkRelation(childId, parentId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.COMMON).get());
    Assert.assertFalse(relationService.checkRelation(childId, parentId, "NOT_EXISTING_TYPE", RelationTypeGroup.COMMON).get());
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Example 5 with EntityRelation

use of org.thingsboard.server.common.data.relation.EntityRelation in project thingsboard by thingsboard.

the class BaseRelationServiceTest method testCyclicRecursiveRelation.

@Test
public void testCyclicRecursiveRelation() throws ExecutionException, InterruptedException {
    // A -> B -> C -> A
    AssetId assetA = new AssetId(UUIDs.timeBased());
    AssetId assetB = new AssetId(UUIDs.timeBased());
    AssetId assetC = new AssetId(UUIDs.timeBased());
    EntityRelation relationA = new EntityRelation(assetA, assetB, EntityRelation.CONTAINS_TYPE);
    EntityRelation relationB = new EntityRelation(assetB, assetC, EntityRelation.CONTAINS_TYPE);
    EntityRelation relationC = new EntityRelation(assetC, assetA, EntityRelation.CONTAINS_TYPE);
    saveRelation(relationA);
    saveRelation(relationB);
    saveRelation(relationC);
    EntityRelationsQuery query = new EntityRelationsQuery();
    query.setParameters(new RelationsSearchParameters(assetA, EntitySearchDirection.FROM, -1));
    query.setFilters(Collections.singletonList(new EntityTypeFilter(EntityRelation.CONTAINS_TYPE, Collections.singletonList(EntityType.ASSET))));
    List<EntityRelation> relations = relationService.findByQuery(query).get();
    Assert.assertEquals(3, relations.size());
    Assert.assertTrue(relations.contains(relationA));
    Assert.assertTrue(relations.contains(relationB));
    Assert.assertTrue(relations.contains(relationC));
}
Also used : EntityTypeFilter(org.thingsboard.server.common.data.relation.EntityTypeFilter) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) EntityRelationsQuery(org.thingsboard.server.common.data.relation.EntityRelationsQuery) RelationsSearchParameters(org.thingsboard.server.common.data.relation.RelationsSearchParameters) AssetId(org.thingsboard.server.common.data.id.AssetId) Test(org.junit.Test)

Aggregations

EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)28 AssetId (org.thingsboard.server.common.data.id.AssetId)13 Test (org.junit.Test)12 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)6 Futures (com.google.common.util.concurrent.Futures)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 Slf4j (lombok.extern.slf4j.Slf4j)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 EntityId (org.thingsboard.server.common.data.id.EntityId)6 List (java.util.List)5 ExecutionException (java.util.concurrent.ExecutionException)5 EntityType (org.thingsboard.server.common.data.EntityType)5 Function (com.google.common.base.Function)4 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)4 Component (org.springframework.stereotype.Component)4 CustomerId (org.thingsboard.server.common.data.id.CustomerId)4 TenantId (org.thingsboard.server.common.data.id.TenantId)4 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)4 RelationTypeGroup (org.thingsboard.server.common.data.relation.RelationTypeGroup)4