Search in sources :

Example 1 with AssetId

use of org.thingsboard.server.common.data.id.AssetId 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 AssetId

use of org.thingsboard.server.common.data.id.AssetId 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 AssetId

use of org.thingsboard.server.common.data.id.AssetId 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 AssetId

use of org.thingsboard.server.common.data.id.AssetId 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 AssetId

use of org.thingsboard.server.common.data.id.AssetId 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

AssetId (org.thingsboard.server.common.data.id.AssetId)21 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)13 Test (org.junit.Test)12 Asset (org.thingsboard.server.common.data.asset.Asset)8 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 TenantId (org.thingsboard.server.common.data.id.TenantId)5 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)5 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 Customer (org.thingsboard.server.common.data.Customer)4 EntityRelationsQuery (org.thingsboard.server.common.data.relation.EntityRelationsQuery)2 EntityTypeFilter (org.thingsboard.server.common.data.relation.EntityTypeFilter)2 RelationsSearchParameters (org.thingsboard.server.common.data.relation.RelationsSearchParameters)2 Function (com.google.common.base.Function)1 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1