diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java index 266b7e8fa6..8c44e8236e 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java +++ b/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.UUID; import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; 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.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED; import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING; @@ -92,7 +90,10 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest { " ],\n" + " \"attributeLwm2m\": {}\n" + " }"; - @Test + + private List expectedStatuses; + + @Test public void testFirmwareUpdateWithClientWithoutFirmwareOtaInfoFromProfile() throws Exception { Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE)); createDeviceProfile(transportConfiguration); @@ -128,24 +129,14 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest { assertThat(savedDevice).as("saved device").isNotNull(); assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice); - final List expectedStatuses = Arrays.asList(QUEUED, INITIATED, FAILED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED); - Predicate predicate = argument -> ((List)argument).size() >= expectedStatuses.size(); + expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED); List ts = await("await on timeseries") .atMost(30, TimeUnit.SECONDS) .until(() -> toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() { - })), predicate); - List statuses = ts.stream().sorted(Comparator - .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()); + })), this::predicateForStatuses); + log.warn("Object5: Got the ts: {}", ts); } /** @@ -167,27 +158,13 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest { assertThat(savedDevice).as("saved device").isNotNull(); assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice); - final List expectedStatuses = List.of( - QUEUED, INITIATED, FAILED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED); - log.warn("AWAIT atMost {} SECONDS on timeseries List by API with list size {}...", TIMEOUT, expectedStatuses.size()); - Predicate predicate = argument -> ((List)argument).size() >= expectedStatuses.size(); + expectedStatuses = List.of( + QUEUED, INITIATED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED); + List ts = await("await on timeseries") .atMost(30, TimeUnit.SECONDS) - .until(() -> getSwStateTelemetryFromAPI(device.getId().getId()), predicate); - log.warn("Got the ts: {}", ts); - - ts.sort(Comparator.comparingLong(TsKvEntry::getTs)); - ts.forEach((x) -> log.warn("ts: ordered:{} ", x)); - List 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()); + .until(() -> getSwStateTelemetryFromAPI(device.getId().getId()), this::predicateForStatuses); + log.warn("Object9: Got the ts: {}", ts); } 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); return tsKvEntries; } + + private boolean predicateForStatuses (List ts) { + List statuses = ts.stream().sorted(Comparator + .comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString) + .map(OtaPackageUpdateStatus::valueOf) + .collect(Collectors.toList()); + log.warn("{}", statuses); + return statuses.containsAll(expectedStatuses); + } }