Search in sources :

Example 1 with EdgeSearchQueryFilter

use of org.thingsboard.server.common.data.query.EdgeSearchQueryFilter in project thingsboard by thingsboard.

the class BaseEntityServiceTest method testCountHierarchicalEntitiesByEdgeSearchQuery.

@Test
public void testCountHierarchicalEntitiesByEdgeSearchQuery() throws InterruptedException {
    for (int i = 0; i < 5; i++) {
        Edge edge = createEdge(i, "type" + i);
        edge = edgeService.saveEdge(edge);
        // TO make sure devices have different created time
        Thread.sleep(1);
        EntityRelation er = new EntityRelation();
        er.setFrom(tenantId);
        er.setTo(edge.getId());
        er.setType("Manages");
        er.setTypeGroup(RelationTypeGroup.COMMON);
        relationService.saveRelation(tenantId, er);
    }
    EdgeSearchQueryFilter filter = new EdgeSearchQueryFilter();
    filter.setRootEntity(tenantId);
    filter.setDirection(EntitySearchDirection.FROM);
    filter.setRelationType("Manages");
    EntityCountQuery countQuery = new EntityCountQuery(filter);
    long count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(5, count);
    filter.setEdgeTypes(Arrays.asList("type0", "type1"));
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(2, count);
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) EdgeSearchQueryFilter(org.thingsboard.server.common.data.query.EdgeSearchQueryFilter) EntityCountQuery(org.thingsboard.server.common.data.query.EntityCountQuery) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Edge (org.thingsboard.server.common.data.edge.Edge)1 CustomerId (org.thingsboard.server.common.data.id.CustomerId)1 EdgeSearchQueryFilter (org.thingsboard.server.common.data.query.EdgeSearchQueryFilter)1 EntityCountQuery (org.thingsboard.server.common.data.query.EntityCountQuery)1 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)1