Browse Source

fix_bug: lwm2m object5 and object9

pull/7047/head
nickAS21 4 years ago
parent
commit
3eb5fddbe2
  1. 56
      application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java

56
application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java

@ -33,12 +33,10 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertTrue;
import static org.thingsboard.rest.client.utils.RestJsonConverter.toTimeseries; import static org.thingsboard.rest.client.utils.RestJsonConverter.toTimeseries;
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED; import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED;
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING; import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING;
@ -92,7 +90,10 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
" ],\n" + " ],\n" +
" \"attributeLwm2m\": {}\n" + " \"attributeLwm2m\": {}\n" +
" }"; " }";
@Test
private List<OtaPackageUpdateStatus> expectedStatuses;
@Test
public void testFirmwareUpdateWithClientWithoutFirmwareOtaInfoFromProfile() throws Exception { public void testFirmwareUpdateWithClientWithoutFirmwareOtaInfoFromProfile() throws Exception {
Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE)); Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE));
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
@ -128,24 +129,14 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
assertThat(savedDevice).as("saved device").isNotNull(); assertThat(savedDevice).as("saved device").isNotNull();
assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice); assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice);
final List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, FAILED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED); expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED);
Predicate predicate = argument -> ((List)argument).size() >= expectedStatuses.size();
List<TsKvEntry> ts = await("await on timeseries") List<TsKvEntry> ts = await("await on timeseries")
.atMost(30, TimeUnit.SECONDS) .atMost(30, TimeUnit.SECONDS)
.until(() -> toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + .until(() -> toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" +
savedDevice.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" + savedDevice.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" +
System.currentTimeMillis(), new TypeReference<>() { System.currentTimeMillis(), new TypeReference<>() {
})), predicate); })), this::predicateForStatuses);
List<OtaPackageUpdateStatus> statuses = ts.stream().sorted(Comparator log.warn("Object5: Got the ts: {}", ts);
.comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString)
.map(OtaPackageUpdateStatus::valueOf)
.collect(Collectors.toList());
statuses.removeAll(expectedStatuses);
if (statuses.isEmpty()) {
log.trace("Statuses must be empty [{}]", statuses);
}
assertTrue(statuses.isEmpty());
} }
/** /**
@ -167,27 +158,13 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
assertThat(savedDevice).as("saved device").isNotNull(); assertThat(savedDevice).as("saved device").isNotNull();
assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice); assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice);
final List<OtaPackageUpdateStatus> expectedStatuses = List.of( expectedStatuses = List.of(
QUEUED, INITIATED, FAILED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED); QUEUED, INITIATED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED);
log.warn("AWAIT atMost {} SECONDS on timeseries List<TsKvEntry> by API with list size {}...", TIMEOUT, expectedStatuses.size());
Predicate predicate = argument -> ((List)argument).size() >= expectedStatuses.size();
List<TsKvEntry> ts = await("await on timeseries") List<TsKvEntry> ts = await("await on timeseries")
.atMost(30, TimeUnit.SECONDS) .atMost(30, TimeUnit.SECONDS)
.until(() -> getSwStateTelemetryFromAPI(device.getId().getId()), predicate); .until(() -> getSwStateTelemetryFromAPI(device.getId().getId()), this::predicateForStatuses);
log.warn("Got the ts: {}", ts); log.warn("Object9: Got the ts: {}", ts);
ts.sort(Comparator.comparingLong(TsKvEntry::getTs));
ts.forEach((x) -> log.warn("ts: ordered:{} ", x));
List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString)
.map(OtaPackageUpdateStatus::valueOf)
.collect(Collectors.toList());
log.warn("Converted ts to statuses: {}", statuses);
statuses.removeAll(expectedStatuses);
if (statuses.isEmpty()) {
log.trace("Statuses must be empty [{}]", statuses);
}
assertTrue(statuses.isEmpty());
} }
private Device getDeviceFromAPI(UUID deviceId) throws Exception { private Device getDeviceFromAPI(UUID deviceId) throws Exception {
@ -202,4 +179,13 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
log.warn("Fetched telemetry by API for deviceId {}, list size {}, tsKvEntries {}", deviceId, tsKvEntries.size(), tsKvEntries); log.warn("Fetched telemetry by API for deviceId {}, list size {}, tsKvEntries {}", deviceId, tsKvEntries.size(), tsKvEntries);
return tsKvEntries; return tsKvEntries;
} }
private boolean predicateForStatuses (List<TsKvEntry> ts) {
List<OtaPackageUpdateStatus> statuses = ts.stream().sorted(Comparator
.comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString)
.map(OtaPackageUpdateStatus::valueOf)
.collect(Collectors.toList());
log.warn("{}", statuses);
return statuses.containsAll(expectedStatuses);
}
} }

Loading…
Cancel
Save