|
@@ -19,31 +19,24 @@ import com.fasterxml.jackson.core.type.TypeReference; |
|
@@ -19,31 +19,24 @@ import com.fasterxml.jackson.core.type.TypeReference; |
19
|
import org.junit.Assert;
|
19
|
import org.junit.Assert;
|
20
|
import org.junit.Test;
|
20
|
import org.junit.Test;
|
21
|
import org.thingsboard.server.common.data.Device;
|
21
|
import org.thingsboard.server.common.data.Device;
|
22
|
-import org.thingsboard.server.common.data.OtaPackageInfo;
|
|
|
23
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredentials;
|
22
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredentials;
|
24
|
import org.thingsboard.server.common.data.kv.KvEntry;
|
23
|
import org.thingsboard.server.common.data.kv.KvEntry;
|
25
|
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
24
|
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
26
|
import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus;
|
25
|
import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus;
|
27
|
-import org.thingsboard.server.common.data.query.EntityData;
|
|
|
28
|
-import org.thingsboard.server.common.data.query.EntityDataPageLink;
|
|
|
29
|
-import org.thingsboard.server.common.data.query.EntityDataQuery;
|
|
|
30
|
import org.thingsboard.server.common.data.query.EntityKey;
|
26
|
import org.thingsboard.server.common.data.query.EntityKey;
|
31
|
import org.thingsboard.server.common.data.query.EntityKeyType;
|
27
|
import org.thingsboard.server.common.data.query.EntityKeyType;
|
32
|
-import org.thingsboard.server.common.data.query.SingleEntityFilter;
|
|
|
33
|
-import org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper;
|
|
|
34
|
-import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd;
|
|
|
35
|
-import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate;
|
|
|
36
|
-import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd;
|
|
|
37
|
import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
|
28
|
import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
|
38
|
|
29
|
|
39
|
import java.util.Arrays;
|
30
|
import java.util.Arrays;
|
40
|
import java.util.Collections;
|
31
|
import java.util.Collections;
|
|
|
32
|
+import java.util.Comparator;
|
41
|
import java.util.List;
|
33
|
import java.util.List;
|
42
|
import java.util.stream.Collectors;
|
34
|
import java.util.stream.Collectors;
|
43
|
|
35
|
|
44
|
import static org.thingsboard.rest.client.utils.RestJsonConverter.toTimeseries;
|
36
|
import static org.thingsboard.rest.client.utils.RestJsonConverter.toTimeseries;
|
45
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED;
|
37
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADED;
|
46
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING;
|
38
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.DOWNLOADING;
|
|
|
39
|
+import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.FAILED;
|
47
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.INITIATED;
|
40
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.INITIATED;
|
48
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.QUEUED;
|
41
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.QUEUED;
|
49
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATED;
|
42
|
import static org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus.UPDATED;
|
|
@@ -138,116 +131,102 @@ public class NoSecLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest { |
|
@@ -138,116 +131,102 @@ public class NoSecLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest { |
138
|
|
131
|
|
139
|
@Test
|
132
|
@Test
|
140
|
public void testFirmwareUpdateWithClientWithoutFirmwareInfo() throws Exception {
|
133
|
public void testFirmwareUpdateWithClientWithoutFirmwareInfo() throws Exception {
|
141
|
- createDeviceProfile(TRANSPORT_CONFIGURATION);
|
|
|
142
|
- NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
|
|
|
143
|
- clientCredentials.setEndpoint(ENDPOINT);
|
|
|
144
|
- Device device = createDevice(clientCredentials);
|
|
|
145
|
-
|
|
|
146
|
- OtaPackageInfo firmware = createFirmware();
|
|
|
147
|
-
|
|
|
148
|
- LwM2MTestClient client = new LwM2MTestClient(executor, ENDPOINT);
|
|
|
149
|
- client.init(SECURITY, COAP_CONFIG);
|
134
|
+ LwM2MTestClient client = null;
|
|
|
135
|
+ try {
|
|
|
136
|
+ createDeviceProfile(TRANSPORT_CONFIGURATION);
|
|
|
137
|
+ NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
|
|
|
138
|
+ clientCredentials.setEndpoint(ENDPOINT);
|
|
|
139
|
+ Device device = createDevice(clientCredentials);
|
150
|
|
140
|
|
151
|
- Thread.sleep(1000);
|
141
|
+ client = new LwM2MTestClient(executor, ENDPOINT);
|
|
|
142
|
+ client.init(SECURITY, COAP_CONFIG);
|
152
|
|
143
|
|
153
|
- device.setFirmwareId(firmware.getId());
|
144
|
+ Thread.sleep(1000);
|
154
|
|
145
|
|
155
|
- device = doPost("/api/device", device, Device.class);
|
146
|
+ device.setFirmwareId(createFirmware().getId());
|
|
|
147
|
+ device = doPost("/api/device", device, Device.class);
|
156
|
|
148
|
|
157
|
- Thread.sleep(1000);
|
149
|
+ Thread.sleep(5000);
|
158
|
|
150
|
|
159
|
- SingleEntityFilter sef = new SingleEntityFilter();
|
|
|
160
|
- sef.setSingleEntity(device.getId());
|
|
|
161
|
- LatestValueCmd latestCmd = new LatestValueCmd();
|
|
|
162
|
- latestCmd.setKeys(Collections.singletonList(new EntityKey(EntityKeyType.TIME_SERIES, "fw_state")));
|
|
|
163
|
- EntityDataQuery edq = new EntityDataQuery(sef, new EntityDataPageLink(1, 0, null, null),
|
|
|
164
|
- Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
151
|
+ List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getId().getId() + "/values/timeseries?keys=fw_state", new TypeReference<>() {
|
|
|
152
|
+ }));
|
165
|
|
153
|
|
166
|
- EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
|
|
|
167
|
- TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper();
|
|
|
168
|
- wrapper.setEntityDataCmds(Collections.singletonList(cmd));
|
154
|
+ List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
|
169
|
|
155
|
|
170
|
- wsClient.send(mapper.writeValueAsString(wrapper));
|
|
|
171
|
- wsClient.waitForReply();
|
156
|
+ List<OtaPackageUpdateStatus> expectedStatuses = Collections.singletonList(FAILED);
|
172
|
|
157
|
|
173
|
- wsClient.registerWaitForUpdate();
|
|
|
174
|
-
|
|
|
175
|
- String msg = wsClient.waitForUpdate();
|
|
|
176
|
-
|
|
|
177
|
- EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
|
178
|
- Assert.assertEquals(1, update.getCmdId());
|
|
|
179
|
- List<EntityData> eData = update.getUpdate();
|
|
|
180
|
- Assert.assertNotNull(eData);
|
|
|
181
|
- Assert.assertEquals(1, eData.size());
|
|
|
182
|
- Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
|
|
|
183
|
- Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES));
|
|
|
184
|
- var tsValue = eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("fw_state");
|
|
|
185
|
- Assert.assertEquals("FAILED", tsValue.getValue());
|
|
|
186
|
- client.destroy();
|
158
|
+ Assert.assertEquals(expectedStatuses, statuses);
|
|
|
159
|
+ } finally {
|
|
|
160
|
+ if(client != null) {
|
|
|
161
|
+ client.destroy();
|
|
|
162
|
+ }
|
|
|
163
|
+ }
|
187
|
}
|
164
|
}
|
188
|
|
165
|
|
189
|
@Test
|
166
|
@Test
|
190
|
public void testFirmwareUpdateByObject5() throws Exception {
|
167
|
public void testFirmwareUpdateByObject5() throws Exception {
|
191
|
- createDeviceProfile(OTA_TRANSPORT_CONFIGURATION);
|
|
|
192
|
- NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
|
|
|
193
|
- clientCredentials.setEndpoint("OTA_" + ENDPOINT);
|
|
|
194
|
- Device device = createDevice(clientCredentials);
|
|
|
195
|
-
|
|
|
196
|
- OtaPackageInfo firmware = createFirmware();
|
168
|
+ LwM2MTestClient client = null;
|
|
|
169
|
+ try {
|
|
|
170
|
+ createDeviceProfile(OTA_TRANSPORT_CONFIGURATION);
|
|
|
171
|
+ NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
|
|
|
172
|
+ clientCredentials.setEndpoint("OTA_" + ENDPOINT);
|
|
|
173
|
+ Device device = createDevice(clientCredentials);
|
197
|
|
174
|
|
198
|
- LwM2MTestClient client = new LwM2MTestClient(executor, "OTA_" + ENDPOINT);
|
|
|
199
|
- client.init(SECURITY, COAP_CONFIG);
|
175
|
+ device.setFirmwareId(createFirmware().getId());
|
|
|
176
|
+ device = doPost("/api/device", device, Device.class);
|
|
|
177
|
+ Thread.sleep(1000);
|
200
|
|
178
|
|
201
|
- Thread.sleep(1000);
|
179
|
+ client = new LwM2MTestClient(executor, "OTA_" + ENDPOINT);
|
|
|
180
|
+ client.init(SECURITY, COAP_CONFIG);
|
202
|
|
181
|
|
203
|
- device.setFirmwareId(firmware.getId());
|
182
|
+ Thread.sleep(3000);
|
204
|
|
183
|
|
205
|
- device = doPost("/api/device", device, Device.class);
|
184
|
+ List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
|
|
|
185
|
+ }));
|
206
|
|
186
|
|
207
|
- Thread.sleep(4000);
|
187
|
+ List<OtaPackageUpdateStatus> statuses = ts.stream().sorted(Comparator.comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
|
208
|
|
188
|
|
209
|
- List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
|
|
|
210
|
- }));
|
189
|
+ List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED);
|
211
|
|
190
|
|
212
|
- List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
|
|
|
213
|
-
|
|
|
214
|
- List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED);
|
|
|
215
|
-
|
|
|
216
|
- Assert.assertEquals(expectedStatuses, statuses);
|
|
|
217
|
-
|
|
|
218
|
- client.destroy();
|
191
|
+ Assert.assertEquals(expectedStatuses, statuses);
|
|
|
192
|
+ } finally {
|
|
|
193
|
+ if (client != null) {
|
|
|
194
|
+ client.destroy();
|
|
|
195
|
+ }
|
|
|
196
|
+ }
|
219
|
}
|
197
|
}
|
220
|
|
198
|
|
221
|
@Test
|
199
|
@Test
|
222
|
public void testSoftwareUpdateByObject9() throws Exception {
|
200
|
public void testSoftwareUpdateByObject9() throws Exception {
|
223
|
- createDeviceProfile(OTA_TRANSPORT_CONFIGURATION);
|
|
|
224
|
- NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
|
|
|
225
|
- clientCredentials.setEndpoint("OTA_" + ENDPOINT);
|
|
|
226
|
- Device device = createDevice(clientCredentials);
|
201
|
+ LwM2MTestClient client = null;
|
|
|
202
|
+ try {
|
|
|
203
|
+ createDeviceProfile(OTA_TRANSPORT_CONFIGURATION);
|
|
|
204
|
+ NoSecClientCredentials clientCredentials = new NoSecClientCredentials();
|
|
|
205
|
+ clientCredentials.setEndpoint("OTA_" + ENDPOINT);
|
|
|
206
|
+ Device device = createDevice(clientCredentials);
|
227
|
|
207
|
|
228
|
- OtaPackageInfo software = createSoftware();
|
208
|
+ device.setSoftwareId(createSoftware().getId());
|
|
|
209
|
+ device = doPost("/api/device", device, Device.class);
|
229
|
|
210
|
|
230
|
- LwM2MTestClient client = new LwM2MTestClient(executor, "OTA_" + ENDPOINT);
|
|
|
231
|
- client.init(SECURITY, COAP_CONFIG);
|
211
|
+ Thread.sleep(1000);
|
232
|
|
212
|
|
233
|
- Thread.sleep(1000);
|
213
|
+ client = new LwM2MTestClient(executor, "OTA_" + ENDPOINT);
|
|
|
214
|
+ client.init(SECURITY, COAP_CONFIG);
|
234
|
|
215
|
|
235
|
- device.setSoftwareId(software.getId());
|
216
|
+ Thread.sleep(3000);
|
236
|
|
217
|
|
237
|
- device = doPost("/api/device", device, Device.class);
|
218
|
+ List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getId().getId() + "/values/timeseries?orderBy=ASC&keys=sw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
|
|
|
219
|
+ }));
|
238
|
|
220
|
|
239
|
- Thread.sleep(4000);
|
221
|
+ List<OtaPackageUpdateStatus> statuses = ts.stream().sorted(Comparator.comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
|
240
|
|
222
|
|
241
|
- List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getId().getId() + "/values/timeseries?orderBy=ASC&keys=sw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
|
|
|
242
|
- }));
|
223
|
+ List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED);
|
243
|
|
224
|
|
244
|
- List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
|
|
|
245
|
-
|
|
|
246
|
- List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED);
|
|
|
247
|
-
|
|
|
248
|
- Assert.assertEquals(expectedStatuses, statuses);
|
|
|
249
|
-
|
|
|
250
|
- client.destroy();
|
225
|
+ Assert.assertEquals(expectedStatuses, statuses);
|
|
|
226
|
+ } finally {
|
|
|
227
|
+ if (client != null) {
|
|
|
228
|
+ client.destroy();
|
|
|
229
|
+ }
|
|
|
230
|
+ }
|
251
|
}
|
231
|
}
|
252
|
-
|
|
|
253
|
} |
232
|
} |