Search in sources :

Example 1 with EntityListFilter

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

the class BaseEntityServiceTest method testCountEntitiesByQuery.

@Test
public void testCountEntitiesByQuery() throws InterruptedException {
    List<Device> devices = new ArrayList<>();
    for (int i = 0; i < 97; i++) {
        Device device = new Device();
        device.setTenantId(tenantId);
        device.setName("Device" + i);
        device.setType("default");
        device.setLabel("testLabel" + (int) (Math.random() * 1000));
        devices.add(deviceService.saveDevice(device));
    }
    DeviceTypeFilter filter = new DeviceTypeFilter();
    filter.setDeviceType("default");
    filter.setDeviceNameFilter("");
    EntityCountQuery countQuery = new EntityCountQuery(filter);
    long count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(97, count);
    filter.setDeviceType("unknown");
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(0, count);
    filter.setDeviceType("default");
    filter.setDeviceNameFilter("Device1");
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(11, count);
    EntityListFilter entityListFilter = new EntityListFilter();
    entityListFilter.setEntityType(EntityType.DEVICE);
    entityListFilter.setEntityList(devices.stream().map(Device::getId).map(DeviceId::toString).collect(Collectors.toList()));
    countQuery = new EntityCountQuery(entityListFilter);
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(97, count);
    deviceService.deleteDevicesByTenantId(tenantId);
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(0, count);
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceTypeFilter(org.thingsboard.server.common.data.query.DeviceTypeFilter) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ArrayList(java.util.ArrayList) EntityCountQuery(org.thingsboard.server.common.data.query.EntityCountQuery) EntityListFilter(org.thingsboard.server.common.data.query.EntityListFilter) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Test(org.junit.Test)

Example 2 with EntityListFilter

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

the class BaseEntityQueryControllerTest method testCountEntitiesByQuery.

@Test
public void testCountEntitiesByQuery() throws Exception {
    List<Device> devices = new ArrayList<>();
    for (int i = 0; i < 97; i++) {
        Device device = new Device();
        device.setName("Device" + i);
        device.setType("default");
        device.setLabel("testLabel" + (int) (Math.random() * 1000));
        devices.add(doPost("/api/device", device, Device.class));
        Thread.sleep(1);
    }
    DeviceTypeFilter filter = new DeviceTypeFilter();
    filter.setDeviceType("default");
    filter.setDeviceNameFilter("");
    EntityCountQuery countQuery = new EntityCountQuery(filter);
    Long count = doPostWithResponse("/api/entitiesQuery/count", countQuery, Long.class);
    Assert.assertEquals(97, count.longValue());
    filter.setDeviceType("unknown");
    count = doPostWithResponse("/api/entitiesQuery/count", countQuery, Long.class);
    Assert.assertEquals(0, count.longValue());
    filter.setDeviceType("default");
    filter.setDeviceNameFilter("Device1");
    count = doPostWithResponse("/api/entitiesQuery/count", countQuery, Long.class);
    Assert.assertEquals(11, count.longValue());
    EntityListFilter entityListFilter = new EntityListFilter();
    entityListFilter.setEntityType(EntityType.DEVICE);
    entityListFilter.setEntityList(devices.stream().map(Device::getId).map(DeviceId::toString).collect(Collectors.toList()));
    countQuery = new EntityCountQuery(entityListFilter);
    count = doPostWithResponse("/api/entitiesQuery/count", countQuery, Long.class);
    Assert.assertEquals(97, count.longValue());
    EntityTypeFilter filter2 = new EntityTypeFilter();
    filter2.setEntityType(EntityType.DEVICE);
    EntityCountQuery countQuery2 = new EntityCountQuery(filter2);
    Long count2 = doPostWithResponse("/api/entitiesQuery/count", countQuery2, Long.class);
    Assert.assertEquals(97, count2.longValue());
}
Also used : EntityTypeFilter(org.thingsboard.server.common.data.query.EntityTypeFilter) Device(org.thingsboard.server.common.data.Device) DeviceTypeFilter(org.thingsboard.server.common.data.query.DeviceTypeFilter) DeviceId(org.thingsboard.server.common.data.id.DeviceId) ArrayList(java.util.ArrayList) EntityCountQuery(org.thingsboard.server.common.data.query.EntityCountQuery) EntityListFilter(org.thingsboard.server.common.data.query.EntityListFilter) Test(org.junit.Test)

Example 3 with EntityListFilter

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

the class BaseEntityServiceTest method testCountEdgeEntitiesByQuery.

@Test
public void testCountEdgeEntitiesByQuery() throws InterruptedException {
    List<Edge> edges = new ArrayList<>();
    for (int i = 0; i < 97; i++) {
        Edge edge = createEdge(i, "default");
        edges.add(edgeService.saveEdge(edge));
    }
    EdgeTypeFilter filter = new EdgeTypeFilter();
    filter.setEdgeType("default");
    filter.setEdgeNameFilter("");
    EntityCountQuery countQuery = new EntityCountQuery(filter);
    long count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(97, count);
    filter.setEdgeType("unknown");
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(0, count);
    filter.setEdgeType("default");
    filter.setEdgeNameFilter("Edge1");
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(11, count);
    EntityListFilter entityListFilter = new EntityListFilter();
    entityListFilter.setEntityType(EntityType.EDGE);
    entityListFilter.setEntityList(edges.stream().map(Edge::getId).map(EdgeId::toString).collect(Collectors.toList()));
    countQuery = new EntityCountQuery(entityListFilter);
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(97, count);
    edgeService.deleteEdgesByTenantId(tenantId);
    count = entityService.countEntitiesByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), countQuery);
    Assert.assertEquals(0, count);
}
Also used : EdgeId(org.thingsboard.server.common.data.id.EdgeId) ArrayList(java.util.ArrayList) EntityCountQuery(org.thingsboard.server.common.data.query.EntityCountQuery) EntityListFilter(org.thingsboard.server.common.data.query.EntityListFilter) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Edge(org.thingsboard.server.common.data.edge.Edge) EdgeTypeFilter(org.thingsboard.server.common.data.query.EdgeTypeFilter) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 EntityCountQuery (org.thingsboard.server.common.data.query.EntityCountQuery)3 EntityListFilter (org.thingsboard.server.common.data.query.EntityListFilter)3 Device (org.thingsboard.server.common.data.Device)2 CustomerId (org.thingsboard.server.common.data.id.CustomerId)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)2 DeviceTypeFilter (org.thingsboard.server.common.data.query.DeviceTypeFilter)2 Edge (org.thingsboard.server.common.data.edge.Edge)1 EdgeId (org.thingsboard.server.common.data.id.EdgeId)1 EdgeTypeFilter (org.thingsboard.server.common.data.query.EdgeTypeFilter)1 EntityTypeFilter (org.thingsboard.server.common.data.query.EntityTypeFilter)1