|
|
|
@ -118,8 +118,10 @@ import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.thingsboard.server.common.data.AttributeScope.SERVER_SCOPE; |
|
|
|
import static org.thingsboard.server.common.data.query.EntityKeyType.ATTRIBUTE; |
|
|
|
import static org.thingsboard.server.common.data.query.EntityKeyType.ENTITY_FIELD; |
|
|
|
import static org.thingsboard.server.common.data.query.EntityKeyType.SERVER_ATTRIBUTE; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@DaoSqlTest |
|
|
|
@ -604,7 +606,7 @@ public class EntityServiceTest extends AbstractControllerTest { |
|
|
|
List<ListenableFuture<AttributesSaveResult>> attributeFutures = new ArrayList<>(); |
|
|
|
for (int i = 0; i < assets.size(); i++) { |
|
|
|
Asset asset = assets.get(i); |
|
|
|
attributeFutures.add(saveLongAttribute(asset.getId(), "consumption", consumptions.get(i), AttributeScope.SERVER_SCOPE)); |
|
|
|
attributeFutures.add(saveLongAttribute(asset.getId(), "consumption", consumptions.get(i), SERVER_SCOPE)); |
|
|
|
} |
|
|
|
Futures.allAsList(attributeFutures).get(); |
|
|
|
|
|
|
|
@ -1745,6 +1747,37 @@ public class EntityServiceTest extends AbstractControllerTest { |
|
|
|
deviceService.deleteDevicesByTenantId(tenantId); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFindTenantTelemetry() { |
|
|
|
// save timeseries by sys admin
|
|
|
|
BasicTsKvEntry timeseries = new BasicTsKvEntry(42L, new DoubleDataEntry("temperature", 45.5)); |
|
|
|
timeseriesService.save(TenantId.SYS_TENANT_ID, tenantId, timeseries); |
|
|
|
|
|
|
|
AttributeKvEntry attr = new BaseAttributeKvEntry( new LongDataEntry("attr", 10L), 42L); |
|
|
|
attributesService.save(TenantId.SYS_TENANT_ID, tenantId, SERVER_SCOPE, List.of(attr)); |
|
|
|
|
|
|
|
SingleEntityFilter singleEntityFilter = new SingleEntityFilter(); |
|
|
|
singleEntityFilter.setSingleEntity(AliasEntityId.fromEntityId(tenantId)); |
|
|
|
|
|
|
|
List<EntityKey> entityFields = List.of( |
|
|
|
new EntityKey(ENTITY_FIELD, "name") |
|
|
|
); |
|
|
|
List<EntityKey> latestValues = List.of( |
|
|
|
new EntityKey(EntityKeyType.TIME_SERIES, "temperature"), |
|
|
|
new EntityKey(EntityKeyType.SERVER_ATTRIBUTE, "attr") |
|
|
|
); |
|
|
|
|
|
|
|
EntityDataPageLink pageLink = new EntityDataPageLink(1000, 0, null, null); |
|
|
|
EntityDataQuery query = new EntityDataQuery(singleEntityFilter, pageLink, entityFields, latestValues, null); |
|
|
|
|
|
|
|
PageData<EntityData> result = findByQueryAndCheck(query, 1); |
|
|
|
|
|
|
|
String tsValue = result.getData().get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("temperature").getValue(); |
|
|
|
String attrValue = result.getData().get(0).getLatest().get(SERVER_ATTRIBUTE).get("attr").getValue(); |
|
|
|
assertThat(tsValue).isEqualTo("45.5"); |
|
|
|
assertThat(attrValue).isEqualTo("10"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBuildStringPredicateQueryOperations() throws ExecutionException, InterruptedException { |
|
|
|
|
|
|
|
|