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);
}
Aggregations