3 changed files with 55 additions and 102 deletions
@ -1,94 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2025 The Thingsboard Authors |
|
||||
* |
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
* you may not use this file except in compliance with the License. |
|
||||
* You may obtain a copy of the License at |
|
||||
* |
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||
* |
|
||||
* Unless required by applicable law or agreed to in writing, software |
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
* See the License for the specific language governing permissions and |
|
||||
* limitations under the License. |
|
||||
*/ |
|
||||
package org.thingsboard.server.transport.lwm2m.ota.sql; |
|
||||
|
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.junit.Test; |
|
||||
import org.thingsboard.server.common.data.Device; |
|
||||
import org.thingsboard.server.common.data.DeviceProfile; |
|
||||
import org.thingsboard.server.common.data.OtaPackageInfo; |
|
||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials; |
|
||||
import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration; |
|
||||
import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
||||
import org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest; |
|
||||
|
|
||||
import java.util.Arrays; |
|
||||
import java.util.List; |
|
||||
import java.util.concurrent.TimeUnit; |
|
||||
|
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
|
||||
import static org.awaitility.Awaitility.await; |
|
||||
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.INITIATED; |
|
||||
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.QUEUED; |
|
||||
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATED; |
|
||||
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATING; |
|
||||
import static org.thingsboard.server.dao.service.OtaPackageServiceTest.TARGET_FW_VERSION; |
|
||||
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.BINARY_APP_DATA_CONTAINER; |
|
||||
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfileBootstrapConfigType.NONE; |
|
||||
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.RESOURCE_ID_0; |
|
||||
import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_INSTANCE_ID; |
|
||||
|
|
||||
@Slf4j |
|
||||
public class Ota5LwM2MIntegrationWith19Test extends AbstractOtaLwM2MIntegrationTest { |
|
||||
|
|
||||
/** |
|
||||
* ObjectId = 19/65533/0 |
|
||||
* { |
|
||||
* "title" : "My firmware", |
|
||||
* "version" : "fw.v.1.5.0-update", |
|
||||
* "checksum" : "4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a", |
|
||||
* "fileSize" : 1, |
|
||||
* "fileName" : "filename.txt" |
|
||||
* } |
|
||||
* to base64 |
|
||||
* /5/0/5 -> Update Result (Res); 5/0/3 -> State; |
|
||||
* => ((Res>=0 && Res<=9) && State=0) |
|
||||
* => Write to Package/Write to Package URI -> DOWNLOADING ((Res>=0 && Res<=9) && State=1) |
|
||||
* => Download Finished -> DOWNLOADED ((Res==0 || Res=8) && State=2) |
|
||||
* => Executable resource Update is triggered / Initiate Firmware Update -> UPDATING (Res=0 && State=3) |
|
||||
* => Update Successful [Res==1] |
|
||||
* => Start / Res=0 -> "IDLE" .... |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
@Test |
|
||||
public void testFirmwareUpdateByObject5WithObject19_Ok() throws Exception { |
|
||||
Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration19(OBSERVE_ATTRIBUTES_WITH_PARAMS_OTA5_19, getBootstrapServerCredentialsNoSec(NONE)); |
|
||||
DeviceProfile deviceProfile = createLwm2mDeviceProfile("profileFor" + this.CLIENT_ENDPOINT_OTA5, transportConfiguration); |
|
||||
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA5)); |
|
||||
final Device device = createLwm2mDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA5, deviceProfile.getId()); |
|
||||
createNewClient(SECURITY_NO_SEC, null, false, this.CLIENT_ENDPOINT_OTA5, device.getId().getId().toString()); |
|
||||
awaitObserveReadAll(6, device.getId().getId().toString()); |
|
||||
|
|
||||
OtaPackageInfo otaPackageInfo = createFirmware(TARGET_FW_VERSION, deviceProfile.getId()); |
|
||||
device.setFirmwareId(otaPackageInfo.getId()); |
|
||||
final Device savedDevice = doPost("/api/device", device, Device.class); |
|
||||
|
|
||||
assertThat(savedDevice).as("saved device").isNotNull(); |
|
||||
assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice); |
|
||||
|
|
||||
expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED); |
|
||||
List<TsKvEntry> ts = await("await on timeseries for FW") |
|
||||
.atMost(TIMEOUT, TimeUnit.SECONDS) |
|
||||
.until(() -> getFwSwStateTelemetryFromAPI(device.getId().getId(), "fw_state"), this::predicateForStatuses); |
|
||||
|
|
||||
String ver_Id_19 = lwM2MTestClient.getLeshanClient().getObjectTree().getModel().getObjectModel(BINARY_APP_DATA_CONTAINER).version; |
|
||||
String resourceIdVer = "/" + BINARY_APP_DATA_CONTAINER + "_" + ver_Id_19 + "/" + FW_INSTANCE_ID + "/" + RESOURCE_ID_0; |
|
||||
resultReadOtaParams_19(resourceIdVer, otaPackageInfo); |
|
||||
log.warn("Object5 with Object19: Got the ts: {}", ts); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue