Commit c5c8fbd3f73e5def00efd4390449ca99acaf080f
Committed by
GitHub
1 parent
dff593a3
[3.2.2] [WIP] coap transport (#4239)
* init CoapDeviceProfile & added ui components * added transport payload type configuration for default coap device type * added AbstractCoapTransportResource & updated efento resource * fixed coap device profile save & update * fixed Attribute Updates notifications * revert CoapOkCallback onSuccess changes * updated provision request to handle proto payload type * fix license * updated Rpc subscribe/unsubscribe action * add more device emulator clients * added fix for Coap Transport: ability to handle requests with oneElementUriPaths and MultiElementUriPaths * fix TbCoapServer implementation * changed response type to CREATED in POST requests * improved implementation * fix typos * minor bug-fixes & improvements * fix TbCoapServerMessageDeliverer class * improved relay sensor implementation * added tests for CoAP transport\ * fix typo * removed nosql tests * fix coap endpoint creation & improved getAttributes tests * transport tests refactoring
Showing
100 changed files
with
3371 additions
and
290 deletions
Too many changes to show.
To preserve performance only 100 of 137 files are displayed.
application/src/test/java/org/thingsboard/server/transport/AbstractTransportIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/AbstractMqttIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt; | 16 | +package org.thingsboard.server.transport; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.node.ObjectNode; | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
@@ -56,13 +56,14 @@ import static org.junit.Assert.assertNotNull; | @@ -56,13 +56,14 @@ import static org.junit.Assert.assertNotNull; | ||
56 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | 56 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
57 | 57 | ||
58 | @Slf4j | 58 | @Slf4j |
59 | -public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest { | 59 | +public abstract class AbstractTransportIntegrationTest extends AbstractControllerTest { |
60 | 60 | ||
61 | protected static final String MQTT_URL = "tcp://localhost:1883"; | 61 | protected static final String MQTT_URL = "tcp://localhost:1883"; |
62 | + protected static final String COAP_BASE_URL = "coap://localhost:5683/api/v1/"; | ||
62 | 63 | ||
63 | - private static final AtomicInteger atomicInteger = new AtomicInteger(2); | 64 | + protected static final AtomicInteger atomicInteger = new AtomicInteger(2); |
64 | 65 | ||
65 | - public static final String DEVICE_TELEMETRY_PROTO_SCHEMA = "syntax =\"proto3\";\n" + | 66 | + protected static final String DEVICE_TELEMETRY_PROTO_SCHEMA = "syntax =\"proto3\";\n" + |
66 | "\n" + | 67 | "\n" + |
67 | "package test;\n" + | 68 | "package test;\n" + |
68 | "\n" + | 69 | "\n" + |
@@ -83,7 +84,7 @@ public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest | @@ -83,7 +84,7 @@ public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest | ||
83 | " }\n" + | 84 | " }\n" + |
84 | "}"; | 85 | "}"; |
85 | 86 | ||
86 | - public static final String DEVICE_ATTRIBUTES_PROTO_SCHEMA = "syntax =\"proto3\";\n" + | 87 | + protected static final String DEVICE_ATTRIBUTES_PROTO_SCHEMA = "syntax =\"proto3\";\n" + |
87 | "\n" + | 88 | "\n" + |
88 | "package test;\n" + | 89 | "package test;\n" + |
89 | "\n" + | 90 | "\n" + |
@@ -110,81 +111,8 @@ public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest | @@ -110,81 +111,8 @@ public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest | ||
110 | protected Device savedDevice; | 111 | protected Device savedDevice; |
111 | protected String accessToken; | 112 | protected String accessToken; |
112 | 113 | ||
113 | - protected Device savedGateway; | ||
114 | - protected String gatewayAccessToken; | ||
115 | - | ||
116 | protected DeviceProfile deviceProfile; | 114 | protected DeviceProfile deviceProfile; |
117 | 115 | ||
118 | - protected void processBeforeTest (String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic) throws Exception { | ||
119 | - this.processBeforeTest(deviceName, gatewayName, payloadType, telemetryTopic, attributesTopic, null, null, DeviceProfileProvisionType.DISABLED, null, null); | ||
120 | - } | ||
121 | - | ||
122 | - protected void processBeforeTest(String deviceName, | ||
123 | - String gatewayName, | ||
124 | - TransportPayloadType payloadType, | ||
125 | - String telemetryTopic, | ||
126 | - String attributesTopic, | ||
127 | - String telemetryProtoSchema, | ||
128 | - String attributesProtoSchema, | ||
129 | - DeviceProfileProvisionType provisionType, | ||
130 | - String provisionKey, String provisionSecret | ||
131 | - ) throws Exception { | ||
132 | - loginSysAdmin(); | ||
133 | - | ||
134 | - Tenant tenant = new Tenant(); | ||
135 | - tenant.setTitle("My tenant"); | ||
136 | - savedTenant = doPost("/api/tenant", tenant, Tenant.class); | ||
137 | - Assert.assertNotNull(savedTenant); | ||
138 | - | ||
139 | - tenantAdmin = new User(); | ||
140 | - tenantAdmin.setAuthority(Authority.TENANT_ADMIN); | ||
141 | - tenantAdmin.setTenantId(savedTenant.getId()); | ||
142 | - tenantAdmin.setEmail("tenant" + atomicInteger.getAndIncrement() + "@thingsboard.org"); | ||
143 | - tenantAdmin.setFirstName("Joe"); | ||
144 | - tenantAdmin.setLastName("Downs"); | ||
145 | - | ||
146 | - tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); | ||
147 | - | ||
148 | - Device device = new Device(); | ||
149 | - device.setName(deviceName); | ||
150 | - device.setType("default"); | ||
151 | - | ||
152 | - Device gateway = new Device(); | ||
153 | - gateway.setName(gatewayName); | ||
154 | - gateway.setType("default"); | ||
155 | - ObjectNode additionalInfo = mapper.createObjectNode(); | ||
156 | - additionalInfo.put("gateway", true); | ||
157 | - gateway.setAdditionalInfo(additionalInfo); | ||
158 | - | ||
159 | - if (payloadType != null) { | ||
160 | - DeviceProfile mqttDeviceProfile = createMqttDeviceProfile(payloadType, telemetryTopic, attributesTopic, telemetryProtoSchema, attributesProtoSchema, provisionType, provisionKey, provisionSecret); | ||
161 | - deviceProfile = doPost("/api/deviceProfile", mqttDeviceProfile, DeviceProfile.class); | ||
162 | - device.setType(deviceProfile.getName()); | ||
163 | - device.setDeviceProfileId(deviceProfile.getId()); | ||
164 | - gateway.setType(deviceProfile.getName()); | ||
165 | - gateway.setDeviceProfileId(deviceProfile.getId()); | ||
166 | - } | ||
167 | - | ||
168 | - savedDevice = doPost("/api/device", device, Device.class); | ||
169 | - | ||
170 | - DeviceCredentials deviceCredentials = | ||
171 | - doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); | ||
172 | - | ||
173 | - savedGateway = doPost("/api/device", gateway, Device.class); | ||
174 | - | ||
175 | - DeviceCredentials gatewayCredentials = | ||
176 | - doGet("/api/device/" + savedGateway.getId().getId().toString() + "/credentials", DeviceCredentials.class); | ||
177 | - | ||
178 | - assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); | ||
179 | - accessToken = deviceCredentials.getCredentialsId(); | ||
180 | - assertNotNull(accessToken); | ||
181 | - | ||
182 | - assertEquals(savedGateway.getId(), gatewayCredentials.getDeviceId()); | ||
183 | - gatewayAccessToken = gatewayCredentials.getCredentialsId(); | ||
184 | - assertNotNull(gatewayAccessToken); | ||
185 | - | ||
186 | - } | ||
187 | - | ||
188 | protected void processAfterTest() throws Exception { | 116 | protected void processAfterTest() throws Exception { |
189 | loginSysAdmin(); | 117 | loginSysAdmin(); |
190 | if (savedTenant != null) { | 118 | if (savedTenant != null) { |
@@ -192,22 +120,6 @@ public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest | @@ -192,22 +120,6 @@ public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest | ||
192 | } | 120 | } |
193 | } | 121 | } |
194 | 122 | ||
195 | - protected MqttAsyncClient getMqttAsyncClient(String accessToken) throws MqttException { | ||
196 | - String clientId = MqttAsyncClient.generateClientId(); | ||
197 | - MqttAsyncClient client = new MqttAsyncClient(MQTT_URL, clientId, new MemoryPersistence()); | ||
198 | - | ||
199 | - MqttConnectOptions options = new MqttConnectOptions(); | ||
200 | - options.setUserName(accessToken); | ||
201 | - client.connect(options).waitForCompletion(); | ||
202 | - return client; | ||
203 | - } | ||
204 | - | ||
205 | - protected void publishMqttMsg(MqttAsyncClient client, byte[] payload, String topic) throws MqttException { | ||
206 | - MqttMessage message = new MqttMessage(); | ||
207 | - message.setPayload(payload); | ||
208 | - client.publish(topic, message); | ||
209 | - } | ||
210 | - | ||
211 | protected List<TransportProtos.KeyValueProto> getKvProtos(List<String> expectedKeys) { | 123 | protected List<TransportProtos.KeyValueProto> getKvProtos(List<String> expectedKeys) { |
212 | List<TransportProtos.KeyValueProto> keyValueProtos = new ArrayList<>(); | 124 | List<TransportProtos.KeyValueProto> keyValueProtos = new ArrayList<>(); |
213 | TransportProtos.KeyValueProto strKeyValueProto = getKeyValueProto(expectedKeys.get(0), "value1", TransportProtos.KeyValueType.STRING_V); | 125 | TransportProtos.KeyValueProto strKeyValueProto = getKeyValueProto(expectedKeys.get(0), "value1", TransportProtos.KeyValueType.STRING_V); |
@@ -247,72 +159,6 @@ public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest | @@ -247,72 +159,6 @@ public abstract class AbstractMqttIntegrationTest extends AbstractControllerTest | ||
247 | return keyValueProtoBuilder.build(); | 159 | return keyValueProtoBuilder.build(); |
248 | } | 160 | } |
249 | 161 | ||
250 | - protected DeviceProfile createMqttDeviceProfile(TransportPayloadType transportPayloadType, | ||
251 | - String telemetryTopic, String attributesTopic, | ||
252 | - String telemetryProtoSchema, String attributesProtoSchema, | ||
253 | - DeviceProfileProvisionType provisionType, | ||
254 | - String provisionKey, String provisionSecret) { | ||
255 | - DeviceProfile deviceProfile = new DeviceProfile(); | ||
256 | - deviceProfile.setName(transportPayloadType.name()); | ||
257 | - deviceProfile.setType(DeviceProfileType.DEFAULT); | ||
258 | - deviceProfile.setTransportType(DeviceTransportType.MQTT); | ||
259 | - deviceProfile.setProvisionType(provisionType); | ||
260 | - deviceProfile.setProvisionDeviceKey(provisionKey); | ||
261 | - deviceProfile.setDescription(transportPayloadType.name() + " Test"); | ||
262 | - DeviceProfileData deviceProfileData = new DeviceProfileData(); | ||
263 | - DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration(); | ||
264 | - MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = new MqttDeviceProfileTransportConfiguration(); | ||
265 | - if (!StringUtils.isEmpty(telemetryTopic)) { | ||
266 | - mqttDeviceProfileTransportConfiguration.setDeviceTelemetryTopic(telemetryTopic); | ||
267 | - } | ||
268 | - if (!StringUtils.isEmpty(attributesTopic)) { | ||
269 | - mqttDeviceProfileTransportConfiguration.setDeviceAttributesTopic(attributesTopic); | ||
270 | - } | ||
271 | - TransportPayloadTypeConfiguration transportPayloadTypeConfiguration; | ||
272 | - if (TransportPayloadType.JSON.equals(transportPayloadType)) { | ||
273 | - transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration(); | ||
274 | - } else { | ||
275 | - ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration(); | ||
276 | - if (StringUtils.isEmpty(telemetryProtoSchema)) { | ||
277 | - telemetryProtoSchema = DEVICE_TELEMETRY_PROTO_SCHEMA; | ||
278 | - } | ||
279 | - if (StringUtils.isEmpty(attributesProtoSchema)) { | ||
280 | - attributesProtoSchema = DEVICE_ATTRIBUTES_PROTO_SCHEMA; | ||
281 | - } | ||
282 | - protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema); | ||
283 | - protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema); | ||
284 | - transportPayloadTypeConfiguration = protoTransportPayloadConfiguration; | ||
285 | - } | ||
286 | - mqttDeviceProfileTransportConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration); | ||
287 | - deviceProfileData.setTransportConfiguration(mqttDeviceProfileTransportConfiguration); | ||
288 | - DeviceProfileProvisionConfiguration provisionConfiguration; | ||
289 | - switch (provisionType) { | ||
290 | - case ALLOW_CREATE_NEW_DEVICES: | ||
291 | - provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(provisionSecret); | ||
292 | - break; | ||
293 | - case CHECK_PRE_PROVISIONED_DEVICES: | ||
294 | - provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(provisionSecret); | ||
295 | - break; | ||
296 | - case DISABLED: | ||
297 | - default: | ||
298 | - provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(provisionSecret); | ||
299 | - break; | ||
300 | - } | ||
301 | - deviceProfileData.setProvisionConfiguration(provisionConfiguration); | ||
302 | - deviceProfileData.setConfiguration(configuration); | ||
303 | - deviceProfile.setProfileData(deviceProfileData); | ||
304 | - deviceProfile.setDefault(false); | ||
305 | - deviceProfile.setDefaultRuleChainId(null); | ||
306 | - return deviceProfile; | ||
307 | - } | ||
308 | - | ||
309 | - protected TransportProtos.PostAttributeMsg getPostAttributeMsg(List<String> expectedKeys) { | ||
310 | - List<TransportProtos.KeyValueProto> kvProtos = getKvProtos(expectedKeys); | ||
311 | - TransportProtos.PostAttributeMsg.Builder builder = TransportProtos.PostAttributeMsg.newBuilder(); | ||
312 | - builder.addAllKv(kvProtos); | ||
313 | - return builder.build(); | ||
314 | - } | ||
315 | - | ||
316 | protected <T> T doExecuteWithRetriesAndInterval(SupplierWithThrowable<T> supplier, int retries, int intervalMs) throws Exception { | 162 | protected <T> T doExecuteWithRetriesAndInterval(SupplierWithThrowable<T> supplier, int retries, int intervalMs) throws Exception { |
317 | int count = 0; | 163 | int count = 0; |
318 | T result = null; | 164 | T result = null; |
application/src/test/java/org/thingsboard/server/transport/TransportNoSqlTestSuite.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/MqttNoSqlTestSuite.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt; | 16 | +package org.thingsboard.server.transport; |
17 | 17 | ||
18 | import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; | 18 | import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; |
19 | import org.junit.BeforeClass; | 19 | import org.junit.BeforeClass; |
@@ -28,8 +28,8 @@ import java.util.Arrays; | @@ -28,8 +28,8 @@ import java.util.Arrays; | ||
28 | 28 | ||
29 | @RunWith(ClasspathSuite.class) | 29 | @RunWith(ClasspathSuite.class) |
30 | @ClasspathSuite.ClassnameFilters({ | 30 | @ClasspathSuite.ClassnameFilters({ |
31 | - "org.thingsboard.server.mqtt.*.nosql.*Test"}) | ||
32 | -public class MqttNoSqlTestSuite { | 31 | + "org.thingsboard.server.transport.*.telemetry.timeseries.nosql.*Test"}) |
32 | +public class TransportNoSqlTestSuite { | ||
33 | 33 | ||
34 | @ClassRule | 34 | @ClassRule |
35 | public static CustomSqlUnit sqlUnit = new CustomSqlUnit( | 35 | public static CustomSqlUnit sqlUnit = new CustomSqlUnit( |
application/src/test/java/org/thingsboard/server/transport/TransportSqlTestSuite.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/MqttSqlTestSuite.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt; | 16 | +package org.thingsboard.server.transport; |
17 | 17 | ||
18 | import org.junit.BeforeClass; | 18 | import org.junit.BeforeClass; |
19 | import org.junit.ClassRule; | 19 | import org.junit.ClassRule; |
@@ -26,15 +26,15 @@ import java.util.Arrays; | @@ -26,15 +26,15 @@ import java.util.Arrays; | ||
26 | 26 | ||
27 | @RunWith(ClasspathSuite.class) | 27 | @RunWith(ClasspathSuite.class) |
28 | @ClasspathSuite.ClassnameFilters({ | 28 | @ClasspathSuite.ClassnameFilters({ |
29 | - "org.thingsboard.server.mqtt.rpc.sql.*Test", | ||
30 | - "org.thingsboard.server.mqtt.telemetry.timeseries.sql.*Test", | ||
31 | - "org.thingsboard.server.mqtt.telemetry.attributes.sql.*Test", | ||
32 | - "org.thingsboard.server.mqtt.attributes.updates.sql.*Test", | ||
33 | - "org.thingsboard.server.mqtt.attributes.request.sql.*Test", | ||
34 | - "org.thingsboard.server.mqtt.claim.sql.*Test", | ||
35 | - "org.thingsboard.server.mqtt.provision.sql.*Test" | 29 | + "org.thingsboard.server.transport.*.rpc.sql.*Test", |
30 | + "org.thingsboard.server.transport.*.telemetry.timeseries.sql.*Test", | ||
31 | + "org.thingsboard.server.transport.*.telemetry.attributes.sql.*Test", | ||
32 | + "org.thingsboard.server.transport.*.attributes.updates.sql.*Test", | ||
33 | + "org.thingsboard.server.transport.*.attributes.request.sql.*Test", | ||
34 | + "org.thingsboard.server.transport.*.claim.sql.*Test", | ||
35 | + "org.thingsboard.server.transport.*.provision.sql.*Test" | ||
36 | }) | 36 | }) |
37 | -public class MqttSqlTestSuite { | 37 | +public class TransportSqlTestSuite { |
38 | 38 | ||
39 | @ClassRule | 39 | @ClassRule |
40 | public static CustomSqlUnit sqlUnit = new CustomSqlUnit( | 40 | public static CustomSqlUnit sqlUnit = new CustomSqlUnit( |
application/src/test/java/org/thingsboard/server/transport/coap/AbstractCoapIntegrationTest.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.eclipse.californium.core.CoapClient; | ||
20 | +import org.junit.Assert; | ||
21 | +import org.springframework.util.StringUtils; | ||
22 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
23 | +import org.thingsboard.server.common.data.Device; | ||
24 | +import org.thingsboard.server.common.data.DeviceProfile; | ||
25 | +import org.thingsboard.server.common.data.DeviceProfileProvisionType; | ||
26 | +import org.thingsboard.server.common.data.DeviceProfileType; | ||
27 | +import org.thingsboard.server.common.data.DeviceTransportType; | ||
28 | +import org.thingsboard.server.common.data.Tenant; | ||
29 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
30 | +import org.thingsboard.server.common.data.User; | ||
31 | +import org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration; | ||
32 | +import org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration; | ||
33 | +import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; | ||
34 | +import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; | ||
35 | +import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration; | ||
36 | +import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration; | ||
37 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileData; | ||
38 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileProvisionConfiguration; | ||
39 | +import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration; | ||
40 | +import org.thingsboard.server.common.data.device.profile.EfentoCoapDeviceTypeConfiguration; | ||
41 | +import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; | ||
42 | +import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; | ||
43 | +import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; | ||
44 | +import org.thingsboard.server.common.data.security.Authority; | ||
45 | +import org.thingsboard.server.common.data.security.DeviceCredentials; | ||
46 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
47 | +import org.thingsboard.server.transport.AbstractTransportIntegrationTest; | ||
48 | + | ||
49 | +import static org.junit.Assert.assertEquals; | ||
50 | +import static org.junit.Assert.assertNotNull; | ||
51 | + | ||
52 | +@Slf4j | ||
53 | +public abstract class AbstractCoapIntegrationTest extends AbstractTransportIntegrationTest { | ||
54 | + | ||
55 | + protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception { | ||
56 | + this.processBeforeTest(deviceName, coapDeviceType, payloadType, null, null, DeviceProfileProvisionType.DISABLED, null, null); | ||
57 | + } | ||
58 | + | ||
59 | + protected void processBeforeTest(String deviceName, | ||
60 | + CoapDeviceType coapDeviceType, | ||
61 | + TransportPayloadType payloadType, | ||
62 | + String telemetryProtoSchema, | ||
63 | + String attributesProtoSchema, | ||
64 | + DeviceProfileProvisionType provisionType, | ||
65 | + String provisionKey, String provisionSecret | ||
66 | + ) throws Exception { | ||
67 | + loginSysAdmin(); | ||
68 | + | ||
69 | + Tenant tenant = new Tenant(); | ||
70 | + tenant.setTitle("My tenant"); | ||
71 | + savedTenant = doPost("/api/tenant", tenant, Tenant.class); | ||
72 | + Assert.assertNotNull(savedTenant); | ||
73 | + | ||
74 | + tenantAdmin = new User(); | ||
75 | + tenantAdmin.setAuthority(Authority.TENANT_ADMIN); | ||
76 | + tenantAdmin.setTenantId(savedTenant.getId()); | ||
77 | + tenantAdmin.setEmail("tenant" + atomicInteger.getAndIncrement() + "@thingsboard.org"); | ||
78 | + tenantAdmin.setFirstName("Joe"); | ||
79 | + tenantAdmin.setLastName("Downs"); | ||
80 | + | ||
81 | + tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); | ||
82 | + | ||
83 | + Device device = new Device(); | ||
84 | + device.setName(deviceName); | ||
85 | + device.setType("default"); | ||
86 | + | ||
87 | + if (coapDeviceType != null) { | ||
88 | + DeviceProfile coapDeviceProfile = createCoapDeviceProfile(payloadType, coapDeviceType, attributesProtoSchema, provisionType, provisionKey, provisionSecret, telemetryProtoSchema); | ||
89 | + deviceProfile = doPost("/api/deviceProfile", coapDeviceProfile, DeviceProfile.class); | ||
90 | + device.setType(deviceProfile.getName()); | ||
91 | + device.setDeviceProfileId(deviceProfile.getId()); | ||
92 | + } | ||
93 | + | ||
94 | + savedDevice = doPost("/api/device", device, Device.class); | ||
95 | + | ||
96 | + DeviceCredentials deviceCredentials = | ||
97 | + doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); | ||
98 | + | ||
99 | + assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); | ||
100 | + accessToken = deviceCredentials.getCredentialsId(); | ||
101 | + assertNotNull(accessToken); | ||
102 | + | ||
103 | + } | ||
104 | + | ||
105 | + protected DeviceProfile createCoapDeviceProfile(TransportPayloadType transportPayloadType, CoapDeviceType coapDeviceType, | ||
106 | + String attributesProtoSchema, DeviceProfileProvisionType provisionType, | ||
107 | + String provisionKey, String provisionSecret, String telemetryProtoSchema) { | ||
108 | + DeviceProfile deviceProfile = new DeviceProfile(); | ||
109 | + deviceProfile.setName(transportPayloadType.name()); | ||
110 | + deviceProfile.setType(DeviceProfileType.DEFAULT); | ||
111 | + deviceProfile.setProvisionType(provisionType); | ||
112 | + deviceProfile.setProvisionDeviceKey(provisionKey); | ||
113 | + deviceProfile.setDescription(transportPayloadType.name() + " Test"); | ||
114 | + DeviceProfileData deviceProfileData = new DeviceProfileData(); | ||
115 | + DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration(); | ||
116 | + deviceProfile.setTransportType(DeviceTransportType.COAP); | ||
117 | + CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = new CoapDeviceProfileTransportConfiguration(); | ||
118 | + CoapDeviceTypeConfiguration coapDeviceTypeConfiguration; | ||
119 | + if (CoapDeviceType.DEFAULT.equals(coapDeviceType)) { | ||
120 | + DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = new DefaultCoapDeviceTypeConfiguration(); | ||
121 | + TransportPayloadTypeConfiguration transportPayloadTypeConfiguration; | ||
122 | + if (TransportPayloadType.PROTOBUF.equals(transportPayloadType)) { | ||
123 | + ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration(); | ||
124 | + if (StringUtils.isEmpty(telemetryProtoSchema)) { | ||
125 | + telemetryProtoSchema = DEVICE_TELEMETRY_PROTO_SCHEMA; | ||
126 | + } | ||
127 | + if (StringUtils.isEmpty(attributesProtoSchema)) { | ||
128 | + attributesProtoSchema = DEVICE_ATTRIBUTES_PROTO_SCHEMA; | ||
129 | + } | ||
130 | + protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema); | ||
131 | + protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema); | ||
132 | + transportPayloadTypeConfiguration = protoTransportPayloadConfiguration; | ||
133 | + } else { | ||
134 | + transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration(); | ||
135 | + } | ||
136 | + defaultCoapDeviceTypeConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration); | ||
137 | + coapDeviceTypeConfiguration = defaultCoapDeviceTypeConfiguration; | ||
138 | + } else { | ||
139 | + coapDeviceTypeConfiguration = new EfentoCoapDeviceTypeConfiguration(); | ||
140 | + } | ||
141 | + coapDeviceProfileTransportConfiguration.setCoapDeviceTypeConfiguration(coapDeviceTypeConfiguration); | ||
142 | + deviceProfileData.setTransportConfiguration(coapDeviceProfileTransportConfiguration); | ||
143 | + DeviceProfileProvisionConfiguration provisionConfiguration; | ||
144 | + switch (provisionType) { | ||
145 | + case ALLOW_CREATE_NEW_DEVICES: | ||
146 | + provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(provisionSecret); | ||
147 | + break; | ||
148 | + case CHECK_PRE_PROVISIONED_DEVICES: | ||
149 | + provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(provisionSecret); | ||
150 | + break; | ||
151 | + case DISABLED: | ||
152 | + default: | ||
153 | + provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(provisionSecret); | ||
154 | + break; | ||
155 | + } | ||
156 | + deviceProfileData.setProvisionConfiguration(provisionConfiguration); | ||
157 | + deviceProfileData.setConfiguration(configuration); | ||
158 | + deviceProfile.setProfileData(deviceProfileData); | ||
159 | + deviceProfile.setDefault(false); | ||
160 | + deviceProfile.setDefaultRuleChainId(null); | ||
161 | + return deviceProfile; | ||
162 | + } | ||
163 | + | ||
164 | + protected CoapClient getCoapClient(FeatureType featureType) { | ||
165 | + return new CoapClient(getFeatureTokenUrl(accessToken, featureType)); | ||
166 | + } | ||
167 | + | ||
168 | + protected CoapClient getCoapClient(String featureTokenUrl) { | ||
169 | + return new CoapClient(featureTokenUrl); | ||
170 | + } | ||
171 | + | ||
172 | + protected String getFeatureTokenUrl(String token, FeatureType featureType) { | ||
173 | + return COAP_BASE_URL + token + "/" + featureType.name().toLowerCase(); | ||
174 | + } | ||
175 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest; | ||
20 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
21 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
22 | +import org.thingsboard.server.gen.transport.TransportProtos; | ||
23 | + | ||
24 | +import java.util.ArrayList; | ||
25 | +import java.util.List; | ||
26 | + | ||
27 | +@Slf4j | ||
28 | +public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoapIntegrationTest { | ||
29 | + | ||
30 | + protected static final String POST_ATTRIBUTES_PAYLOAD = "{\"attribute1\":\"value1\",\"attribute2\":true,\"attribute3\":42.0,\"attribute4\":73," + | ||
31 | + "\"attribute5\":{\"someNumber\":42,\"someArray\":[1,2,3],\"someNestedObject\":{\"key\":\"value\"}}}"; | ||
32 | + | ||
33 | + protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception { | ||
34 | + super.processBeforeTest(deviceName, coapDeviceType, payloadType); | ||
35 | + } | ||
36 | + | ||
37 | + protected void processAfterTest() throws Exception { | ||
38 | + super.processAfterTest(); | ||
39 | + } | ||
40 | + | ||
41 | + protected List<TransportProtos.TsKvProto> getTsKvProtoList() { | ||
42 | + TransportProtos.TsKvProto tsKvProtoAttribute1 = getTsKvProto("attribute1", "value1", TransportProtos.KeyValueType.STRING_V); | ||
43 | + TransportProtos.TsKvProto tsKvProtoAttribute2 = getTsKvProto("attribute2", "true", TransportProtos.KeyValueType.BOOLEAN_V); | ||
44 | + TransportProtos.TsKvProto tsKvProtoAttribute3 = getTsKvProto("attribute3", "42.0", TransportProtos.KeyValueType.DOUBLE_V); | ||
45 | + TransportProtos.TsKvProto tsKvProtoAttribute4 = getTsKvProto("attribute4", "73", TransportProtos.KeyValueType.LONG_V); | ||
46 | + TransportProtos.TsKvProto tsKvProtoAttribute5 = getTsKvProto("attribute5", "{\"someNumber\":42,\"someArray\":[1,2,3],\"someNestedObject\":{\"key\":\"value\"}}", TransportProtos.KeyValueType.JSON_V); | ||
47 | + List<TransportProtos.TsKvProto> tsKvProtoList = new ArrayList<>(); | ||
48 | + tsKvProtoList.add(tsKvProtoAttribute1); | ||
49 | + tsKvProtoList.add(tsKvProtoAttribute2); | ||
50 | + tsKvProtoList.add(tsKvProtoAttribute3); | ||
51 | + tsKvProtoList.add(tsKvProtoAttribute4); | ||
52 | + tsKvProtoList.add(tsKvProtoAttribute5); | ||
53 | + return tsKvProtoList; | ||
54 | + } | ||
55 | + | ||
56 | + protected TransportProtos.TsKvProto getTsKvProto(String key, String value, TransportProtos.KeyValueType keyValueType) { | ||
57 | + TransportProtos.TsKvProto.Builder tsKvProtoBuilder = TransportProtos.TsKvProto.newBuilder(); | ||
58 | + TransportProtos.KeyValueProto keyValueProto = getKeyValueProto(key, value, keyValueType); | ||
59 | + tsKvProtoBuilder.setKv(keyValueProto); | ||
60 | + return tsKvProtoBuilder.build(); | ||
61 | + } | ||
62 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.request; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
19 | +import com.google.protobuf.InvalidProtocolBufferException; | ||
20 | +import lombok.extern.slf4j.Slf4j; | ||
21 | +import org.eclipse.californium.core.CoapClient; | ||
22 | +import org.eclipse.californium.core.CoapResponse; | ||
23 | +import org.eclipse.californium.core.coap.CoAP; | ||
24 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
25 | +import org.junit.After; | ||
26 | +import org.junit.Before; | ||
27 | +import org.junit.Test; | ||
28 | +import org.thingsboard.server.transport.coap.attributes.AbstractCoapAttributesIntegrationTest; | ||
29 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
30 | +import org.thingsboard.server.dao.util.mapping.JacksonUtil; | ||
31 | + | ||
32 | +import java.nio.charset.StandardCharsets; | ||
33 | +import java.util.List; | ||
34 | + | ||
35 | +import static org.junit.Assert.assertEquals; | ||
36 | +import static org.junit.Assert.assertNotNull; | ||
37 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
38 | + | ||
39 | +@Slf4j | ||
40 | +public abstract class AbstractCoapAttributesRequestIntegrationTest extends AbstractCoapAttributesIntegrationTest { | ||
41 | + | ||
42 | + protected static final long CLIENT_REQUEST_TIMEOUT = 60000L; | ||
43 | + | ||
44 | + @Before | ||
45 | + public void beforeTest() throws Exception { | ||
46 | + processBeforeTest("Test Request attribute values from the server", null, null); | ||
47 | + } | ||
48 | + | ||
49 | + @After | ||
50 | + public void afterTest() throws Exception { | ||
51 | + processAfterTest(); | ||
52 | + } | ||
53 | + | ||
54 | + @Test | ||
55 | + public void testRequestAttributesValuesFromTheServer() throws Exception { | ||
56 | + processTestRequestAttributesValuesFromTheServer(); | ||
57 | + } | ||
58 | + | ||
59 | + protected void processTestRequestAttributesValuesFromTheServer() throws Exception { | ||
60 | + postAttributes(); | ||
61 | + | ||
62 | + long start = System.currentTimeMillis(); | ||
63 | + long end = System.currentTimeMillis() + 5000; | ||
64 | + | ||
65 | + List<String> savedAttributeKeys = null; | ||
66 | + while (start <= end) { | ||
67 | + savedAttributeKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() {}); | ||
68 | + if (savedAttributeKeys.size() == 5) { | ||
69 | + break; | ||
70 | + } | ||
71 | + Thread.sleep(100); | ||
72 | + start += 100; | ||
73 | + } | ||
74 | + assertNotNull(savedAttributeKeys); | ||
75 | + | ||
76 | + String keys = "attribute1,attribute2,attribute3,attribute4,attribute5"; | ||
77 | + String featureTokenUrl = getFeatureTokenUrl(accessToken, FeatureType.ATTRIBUTES) + "?clientKeys=" + keys + "&sharedKeys=" + keys; | ||
78 | + CoapClient client = getCoapClient(featureTokenUrl); | ||
79 | + | ||
80 | + CoapResponse getAttributesResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).get(); | ||
81 | + validateResponse(getAttributesResponse); | ||
82 | + } | ||
83 | + | ||
84 | + protected void postAttributes() throws Exception { | ||
85 | + doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD, String.class, status().isOk()); | ||
86 | + CoapClient client = getCoapClient(FeatureType.ATTRIBUTES); | ||
87 | + CoapResponse coapResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).post(POST_ATTRIBUTES_PAYLOAD.getBytes(), MediaTypeRegistry.APPLICATION_JSON); | ||
88 | + assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode()); | ||
89 | + } | ||
90 | + | ||
91 | + protected void validateResponse(CoapResponse getAttributesResponse) throws InvalidProtocolBufferException { | ||
92 | + assertEquals(CoAP.ResponseCode.CONTENT, getAttributesResponse.getCode()); | ||
93 | + String expectedRequestPayload = "{\"client\":{\"attribute1\":\"value1\",\"attribute2\":true,\"attribute3\":42.0,\"attribute4\":73,\"attribute5\":{\"someNumber\":42,\"someArray\":[1,2,3],\"someNestedObject\":{\"key\":\"value\"}}},\"shared\":{\"attribute1\":\"value1\",\"attribute2\":true,\"attribute3\":42.0,\"attribute4\":73,\"attribute5\":{\"someNumber\":42,\"someArray\":[1,2,3],\"someNestedObject\":{\"key\":\"value\"}}}}"; | ||
94 | + assertEquals(JacksonUtil.toJsonNode(expectedRequestPayload), JacksonUtil.toJsonNode(new String(getAttributesResponse.getPayload(), StandardCharsets.UTF_8))); | ||
95 | + } | ||
96 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.request; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
23 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
24 | + | ||
25 | +@Slf4j | ||
26 | +public abstract class AbstractCoapAttributesRequestJsonIntegrationTest extends AbstractCoapAttributesRequestIntegrationTest { | ||
27 | + | ||
28 | + @Before | ||
29 | + public void beforeTest() throws Exception { | ||
30 | + processBeforeTest("Test Request attribute values from the server json", CoapDeviceType.DEFAULT, TransportPayloadType.JSON); | ||
31 | + } | ||
32 | + | ||
33 | + @After | ||
34 | + public void afterTest() throws Exception { | ||
35 | + processAfterTest(); | ||
36 | + } | ||
37 | + | ||
38 | + @Test | ||
39 | + public void testRequestAttributesValuesFromTheServer() throws Exception { | ||
40 | + super.testRequestAttributesValuesFromTheServer(); | ||
41 | + } | ||
42 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.request; | ||
17 | + | ||
18 | +import com.github.os72.protobuf.dynamic.DynamicSchema; | ||
19 | +import com.google.protobuf.Descriptors; | ||
20 | +import com.google.protobuf.DynamicMessage; | ||
21 | +import com.google.protobuf.InvalidProtocolBufferException; | ||
22 | +import com.squareup.wire.schema.internal.parser.ProtoFileElement; | ||
23 | +import lombok.extern.slf4j.Slf4j; | ||
24 | +import org.eclipse.californium.core.CoapClient; | ||
25 | +import org.eclipse.californium.core.CoapResponse; | ||
26 | +import org.eclipse.californium.core.coap.CoAP; | ||
27 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
28 | +import org.junit.After; | ||
29 | +import org.junit.Test; | ||
30 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
31 | +import org.thingsboard.server.common.data.DeviceProfileProvisionType; | ||
32 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
33 | +import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; | ||
34 | +import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; | ||
35 | +import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration; | ||
36 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; | ||
37 | +import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; | ||
38 | +import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; | ||
39 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
40 | +import org.thingsboard.server.gen.transport.TransportProtos; | ||
41 | + | ||
42 | +import java.util.List; | ||
43 | +import java.util.stream.Collectors; | ||
44 | + | ||
45 | +import static org.junit.Assert.assertEquals; | ||
46 | +import static org.junit.Assert.assertNotNull; | ||
47 | +import static org.junit.Assert.assertTrue; | ||
48 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
49 | + | ||
50 | +@Slf4j | ||
51 | +public abstract class AbstractCoapAttributesRequestProtoIntegrationTest extends AbstractCoapAttributesRequestIntegrationTest { | ||
52 | + | ||
53 | + public static final String ATTRIBUTES_SCHEMA_STR = "syntax =\"proto3\";\n" + | ||
54 | + "\n" + | ||
55 | + "package test;\n" + | ||
56 | + "\n" + | ||
57 | + "message PostAttributes {\n" + | ||
58 | + " string attribute1 = 1;\n" + | ||
59 | + " bool attribute2 = 2;\n" + | ||
60 | + " double attribute3 = 3;\n" + | ||
61 | + " int32 attribute4 = 4;\n" + | ||
62 | + " JsonObject attribute5 = 5;\n" + | ||
63 | + "\n" + | ||
64 | + " message JsonObject {\n" + | ||
65 | + " int32 someNumber = 6;\n" + | ||
66 | + " repeated int32 someArray = 7;\n" + | ||
67 | + " NestedJsonObject someNestedObject = 8;\n" + | ||
68 | + " message NestedJsonObject {\n" + | ||
69 | + " string key = 9;\n" + | ||
70 | + " }\n" + | ||
71 | + " }\n" + | ||
72 | + "}"; | ||
73 | + | ||
74 | + @After | ||
75 | + public void afterTest() throws Exception { | ||
76 | + processAfterTest(); | ||
77 | + } | ||
78 | + | ||
79 | + @Test | ||
80 | + public void testRequestAttributesValuesFromTheServer() throws Exception { | ||
81 | + super.processBeforeTest("Test Request attribute values from the server proto", CoapDeviceType.DEFAULT, | ||
82 | + TransportPayloadType.PROTOBUF, null, ATTRIBUTES_SCHEMA_STR, DeviceProfileProvisionType.DISABLED, null, null); | ||
83 | + processTestRequestAttributesValuesFromTheServer(); | ||
84 | + } | ||
85 | + | ||
86 | + protected void postAttributes() throws Exception { | ||
87 | + doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD, String.class, status().isOk()); | ||
88 | + DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); | ||
89 | + assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration); | ||
90 | + CoapDeviceProfileTransportConfiguration coapTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration; | ||
91 | + CoapDeviceTypeConfiguration coapDeviceTypeConfiguration = coapTransportConfiguration.getCoapDeviceTypeConfiguration(); | ||
92 | + assertTrue(coapDeviceTypeConfiguration instanceof DefaultCoapDeviceTypeConfiguration); | ||
93 | + DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = (DefaultCoapDeviceTypeConfiguration) coapDeviceTypeConfiguration; | ||
94 | + TransportPayloadTypeConfiguration transportPayloadTypeConfiguration = defaultCoapDeviceTypeConfiguration.getTransportPayloadTypeConfiguration(); | ||
95 | + assertTrue(transportPayloadTypeConfiguration instanceof ProtoTransportPayloadConfiguration); | ||
96 | + ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = (ProtoTransportPayloadConfiguration) transportPayloadTypeConfiguration; | ||
97 | + ProtoFileElement transportProtoSchema = protoTransportPayloadConfiguration.getTransportProtoSchema(ATTRIBUTES_SCHEMA_STR); | ||
98 | + DynamicSchema attributesSchema = protoTransportPayloadConfiguration.getDynamicSchema(transportProtoSchema, ProtoTransportPayloadConfiguration.ATTRIBUTES_PROTO_SCHEMA); | ||
99 | + | ||
100 | + DynamicMessage.Builder nestedJsonObjectBuilder = attributesSchema.newMessageBuilder("PostAttributes.JsonObject.NestedJsonObject"); | ||
101 | + Descriptors.Descriptor nestedJsonObjectBuilderDescriptor = nestedJsonObjectBuilder.getDescriptorForType(); | ||
102 | + assertNotNull(nestedJsonObjectBuilderDescriptor); | ||
103 | + DynamicMessage nestedJsonObject = nestedJsonObjectBuilder.setField(nestedJsonObjectBuilderDescriptor.findFieldByName("key"), "value").build(); | ||
104 | + | ||
105 | + DynamicMessage.Builder jsonObjectBuilder = attributesSchema.newMessageBuilder("PostAttributes.JsonObject"); | ||
106 | + Descriptors.Descriptor jsonObjectBuilderDescriptor = jsonObjectBuilder.getDescriptorForType(); | ||
107 | + assertNotNull(jsonObjectBuilderDescriptor); | ||
108 | + DynamicMessage jsonObject = jsonObjectBuilder | ||
109 | + .setField(jsonObjectBuilderDescriptor.findFieldByName("someNumber"), 42) | ||
110 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 1) | ||
111 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 2) | ||
112 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 3) | ||
113 | + .setField(jsonObjectBuilderDescriptor.findFieldByName("someNestedObject"), nestedJsonObject) | ||
114 | + .build(); | ||
115 | + | ||
116 | + DynamicMessage.Builder postAttributesBuilder = attributesSchema.newMessageBuilder("PostAttributes"); | ||
117 | + Descriptors.Descriptor postAttributesMsgDescriptor = postAttributesBuilder.getDescriptorForType(); | ||
118 | + assertNotNull(postAttributesMsgDescriptor); | ||
119 | + DynamicMessage postAttributesMsg = postAttributesBuilder | ||
120 | + .setField(postAttributesMsgDescriptor.findFieldByName("attribute1"), "value1") | ||
121 | + .setField(postAttributesMsgDescriptor.findFieldByName("attribute2"), true) | ||
122 | + .setField(postAttributesMsgDescriptor.findFieldByName("attribute3"), 42.0) | ||
123 | + .setField(postAttributesMsgDescriptor.findFieldByName("attribute4"), 73) | ||
124 | + .setField(postAttributesMsgDescriptor.findFieldByName("attribute5"), jsonObject) | ||
125 | + .build(); | ||
126 | + byte[] payload = postAttributesMsg.toByteArray(); | ||
127 | + CoapClient client = getCoapClient(FeatureType.ATTRIBUTES); | ||
128 | + CoapResponse coapResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).post(payload, MediaTypeRegistry.APPLICATION_JSON); | ||
129 | + assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode()); | ||
130 | + } | ||
131 | + | ||
132 | + protected void validateResponse(CoapResponse getAttributesResponse) throws InvalidProtocolBufferException { | ||
133 | + TransportProtos.GetAttributeResponseMsg expectedAttributesResponse = getExpectedAttributeResponseMsg(); | ||
134 | + TransportProtos.GetAttributeResponseMsg actualAttributesResponse = TransportProtos.GetAttributeResponseMsg.parseFrom(getAttributesResponse.getPayload()); | ||
135 | + assertEquals(expectedAttributesResponse.getRequestId(), actualAttributesResponse.getRequestId()); | ||
136 | + List<TransportProtos.KeyValueProto> expectedClientKeyValueProtos = expectedAttributesResponse.getClientAttributeListList().stream().map(TransportProtos.TsKvProto::getKv).collect(Collectors.toList()); | ||
137 | + List<TransportProtos.KeyValueProto> expectedSharedKeyValueProtos = expectedAttributesResponse.getSharedAttributeListList().stream().map(TransportProtos.TsKvProto::getKv).collect(Collectors.toList()); | ||
138 | + List<TransportProtos.KeyValueProto> actualClientKeyValueProtos = actualAttributesResponse.getClientAttributeListList().stream().map(TransportProtos.TsKvProto::getKv).collect(Collectors.toList()); | ||
139 | + List<TransportProtos.KeyValueProto> actualSharedKeyValueProtos = actualAttributesResponse.getSharedAttributeListList().stream().map(TransportProtos.TsKvProto::getKv).collect(Collectors.toList()); | ||
140 | + assertTrue(actualClientKeyValueProtos.containsAll(expectedClientKeyValueProtos)); | ||
141 | + assertTrue(actualSharedKeyValueProtos.containsAll(expectedSharedKeyValueProtos)); | ||
142 | + } | ||
143 | + | ||
144 | + private TransportProtos.GetAttributeResponseMsg getExpectedAttributeResponseMsg() { | ||
145 | + TransportProtos.GetAttributeResponseMsg.Builder result = TransportProtos.GetAttributeResponseMsg.newBuilder(); | ||
146 | + List<TransportProtos.TsKvProto> tsKvProtoList = getTsKvProtoList(); | ||
147 | + result.addAllClientAttributeList(tsKvProtoList); | ||
148 | + result.addAllSharedAttributeList(tsKvProtoList); | ||
149 | + result.setRequestId(0); | ||
150 | + return result.build(); | ||
151 | + } | ||
152 | + | ||
153 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.request.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.attributes.request.AbstractCoapAttributesRequestJsonIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapAttributesRequestJsonSqlIntegrationTest extends AbstractCoapAttributesRequestJsonIntegrationTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.request.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.attributes.request.AbstractCoapAttributesRequestProtoIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapAttributesRequestProtoSqlIntegrationTest extends AbstractCoapAttributesRequestProtoIntegrationTest { | ||
23 | +} |
application/src/test/java/org/thingsboard/server/transport/coap/attributes/request/sql/CoapAttributesRequestSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/nosql/MqttAttributesNoSqlProtoIntegrationTest.java
@@ -13,11 +13,11 @@ | @@ -13,11 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes.nosql; | 16 | +package org.thingsboard.server.transport.coap.attributes.request.sql; |
17 | 17 | ||
18 | -import org.thingsboard.server.dao.service.DaoNoSqlTest; | ||
19 | -import org.thingsboard.server.mqtt.telemetry.attributes.AbstractMqttAttributesProtoIntegrationTest; | 18 | +import org.thingsboard.server.transport.coap.attributes.request.AbstractCoapAttributesRequestIntegrationTest; |
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | 20 | ||
21 | -@DaoNoSqlTest | ||
22 | -public class MqttAttributesNoSqlProtoIntegrationTest extends AbstractMqttAttributesProtoIntegrationTest { | 21 | +@DaoSqlTest |
22 | +public class CoapAttributesRequestSqlIntegrationTest extends AbstractCoapAttributesRequestIntegrationTest { | ||
23 | } | 23 | } |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.updates; | ||
17 | + | ||
18 | +import com.google.protobuf.InvalidProtocolBufferException; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.eclipse.californium.core.CoapClient; | ||
21 | +import org.eclipse.californium.core.CoapHandler; | ||
22 | +import org.eclipse.californium.core.CoapObserveRelation; | ||
23 | +import org.eclipse.californium.core.CoapResponse; | ||
24 | +import org.eclipse.californium.core.coap.CoAP; | ||
25 | +import org.eclipse.californium.core.coap.Request; | ||
26 | +import org.junit.After; | ||
27 | +import org.junit.Before; | ||
28 | +import org.junit.Test; | ||
29 | +import org.thingsboard.server.transport.coap.attributes.AbstractCoapAttributesIntegrationTest; | ||
30 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
31 | +import org.thingsboard.server.dao.util.mapping.JacksonUtil; | ||
32 | + | ||
33 | +import java.nio.charset.StandardCharsets; | ||
34 | +import java.util.concurrent.CountDownLatch; | ||
35 | +import java.util.concurrent.TimeUnit; | ||
36 | + | ||
37 | +import static org.junit.Assert.assertEquals; | ||
38 | +import static org.junit.Assert.assertNotNull; | ||
39 | +import static org.junit.Assert.assertTrue; | ||
40 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
41 | + | ||
42 | +@Slf4j | ||
43 | +public abstract class AbstractCoapAttributesUpdatesIntegrationTest extends AbstractCoapAttributesIntegrationTest { | ||
44 | + | ||
45 | + private static final String RESPONSE_ATTRIBUTES_PAYLOAD_DELETED = "{\"deleted\":[\"attribute5\"]}"; | ||
46 | + | ||
47 | + @Before | ||
48 | + public void beforeTest() throws Exception { | ||
49 | + processBeforeTest("Test Subscribe to attribute updates", null, null); | ||
50 | + } | ||
51 | + | ||
52 | + @After | ||
53 | + public void afterTest() throws Exception { | ||
54 | + processAfterTest(); | ||
55 | + } | ||
56 | + | ||
57 | + @Test | ||
58 | + public void testSubscribeToAttributesUpdatesFromTheServer() throws Exception { | ||
59 | + processTestSubscribeToAttributesUpdates(); | ||
60 | + } | ||
61 | + | ||
62 | + protected void processTestSubscribeToAttributesUpdates() throws Exception { | ||
63 | + | ||
64 | + CoapClient client = getCoapClient(FeatureType.ATTRIBUTES); | ||
65 | + | ||
66 | + CountDownLatch latch = new CountDownLatch(1); | ||
67 | + TestCoapCallback testCoapCallback = new TestCoapCallback(latch); | ||
68 | + | ||
69 | + Request request = Request.newGet().setObserve(); | ||
70 | + request.setType(CoAP.Type.CON); | ||
71 | + CoapObserveRelation observeRelation = client.observe(request, testCoapCallback); | ||
72 | + | ||
73 | + Thread.sleep(1000); | ||
74 | + | ||
75 | + doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD, String.class, status().isOk()); | ||
76 | + latch.await(3, TimeUnit.SECONDS); | ||
77 | + | ||
78 | + validateUpdateAttributesResponse(testCoapCallback); | ||
79 | + | ||
80 | + latch = new CountDownLatch(1); | ||
81 | + | ||
82 | + doDelete("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/SHARED_SCOPE?keys=attribute5", String.class); | ||
83 | + latch.await(3, TimeUnit.SECONDS); | ||
84 | + | ||
85 | + validateDeleteAttributesResponse(testCoapCallback); | ||
86 | + | ||
87 | + observeRelation.proactiveCancel(); | ||
88 | + assertTrue(observeRelation.isCanceled()); | ||
89 | + } | ||
90 | + | ||
91 | + protected void validateUpdateAttributesResponse(TestCoapCallback callback) throws InvalidProtocolBufferException { | ||
92 | + assertNotNull(callback.getPayloadBytes()); | ||
93 | + assertNotNull(callback.getObserve()); | ||
94 | + assertEquals(0, callback.getObserve().intValue()); | ||
95 | + String response = new String(callback.getPayloadBytes(), StandardCharsets.UTF_8); | ||
96 | + assertEquals(JacksonUtil.toJsonNode(POST_ATTRIBUTES_PAYLOAD), JacksonUtil.toJsonNode(response)); | ||
97 | + } | ||
98 | + | ||
99 | + protected void validateDeleteAttributesResponse(TestCoapCallback callback) throws InvalidProtocolBufferException { | ||
100 | + assertNotNull(callback.getPayloadBytes()); | ||
101 | + assertNotNull(callback.getObserve()); | ||
102 | + assertEquals(1, callback.getObserve().intValue()); | ||
103 | + String response = new String(callback.getPayloadBytes(), StandardCharsets.UTF_8); | ||
104 | + assertEquals(JacksonUtil.toJsonNode(RESPONSE_ATTRIBUTES_PAYLOAD_DELETED), JacksonUtil.toJsonNode(response)); | ||
105 | + } | ||
106 | + | ||
107 | + protected static class TestCoapCallback implements CoapHandler { | ||
108 | + | ||
109 | + private final CountDownLatch latch; | ||
110 | + | ||
111 | + private Integer observe; | ||
112 | + private byte[] payloadBytes; | ||
113 | + | ||
114 | + public byte[] getPayloadBytes() { | ||
115 | + return payloadBytes; | ||
116 | + } | ||
117 | + | ||
118 | + public Integer getObserve() { | ||
119 | + return observe; | ||
120 | + } | ||
121 | + | ||
122 | + private TestCoapCallback(CountDownLatch latch) { | ||
123 | + this.latch = latch; | ||
124 | + } | ||
125 | + | ||
126 | + @Override | ||
127 | + public void onLoad(CoapResponse response) { | ||
128 | + assertNotNull(response.getPayload()); | ||
129 | + assertEquals(response.getCode(), CoAP.ResponseCode.CONTENT); | ||
130 | + observe = response.getOptions().getObserve(); | ||
131 | + payloadBytes = response.getPayload(); | ||
132 | + latch.countDown(); | ||
133 | + } | ||
134 | + | ||
135 | + @Override | ||
136 | + public void onError() { | ||
137 | + log.warn("Command Response Ack Error, No connect"); | ||
138 | + } | ||
139 | + | ||
140 | + } | ||
141 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.updates; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
23 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
24 | + | ||
25 | +@Slf4j | ||
26 | +public abstract class AbstractCoapAttributesUpdatesJsonIntegrationTest extends AbstractCoapAttributesUpdatesIntegrationTest { | ||
27 | + | ||
28 | + @Before | ||
29 | + public void beforeTest() throws Exception { | ||
30 | + processBeforeTest("Test Subscribe to attribute updates", CoapDeviceType.DEFAULT, TransportPayloadType.JSON); | ||
31 | + } | ||
32 | + | ||
33 | + @After | ||
34 | + public void afterTest() throws Exception { | ||
35 | + processAfterTest(); | ||
36 | + } | ||
37 | + | ||
38 | + @Test | ||
39 | + public void testSubscribeToAttributesUpdatesFromTheServer() throws Exception { | ||
40 | + super.testSubscribeToAttributesUpdatesFromTheServer(); | ||
41 | + } | ||
42 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.updates; | ||
17 | + | ||
18 | +import com.google.protobuf.InvalidProtocolBufferException; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
24 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
25 | +import org.thingsboard.server.gen.transport.TransportProtos; | ||
26 | + | ||
27 | +import java.util.List; | ||
28 | +import java.util.stream.Collectors; | ||
29 | + | ||
30 | +import static org.junit.Assert.assertEquals; | ||
31 | +import static org.junit.Assert.assertNotNull; | ||
32 | +import static org.junit.Assert.assertTrue; | ||
33 | + | ||
34 | +@Slf4j | ||
35 | +public abstract class AbstractCoapAttributesUpdatesProtoIntegrationTest extends AbstractCoapAttributesUpdatesIntegrationTest { | ||
36 | + | ||
37 | + @Before | ||
38 | + public void beforeTest() throws Exception { | ||
39 | + processBeforeTest("Test Subscribe to attribute updates", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF); | ||
40 | + } | ||
41 | + | ||
42 | + @After | ||
43 | + public void afterTest() throws Exception { | ||
44 | + processAfterTest(); | ||
45 | + } | ||
46 | + | ||
47 | + @Test | ||
48 | + public void testSubscribeToAttributesUpdatesFromTheServer() throws Exception { | ||
49 | + processTestSubscribeToAttributesUpdates(); | ||
50 | + } | ||
51 | + | ||
52 | + protected void validateUpdateAttributesResponse(TestCoapCallback callback) throws InvalidProtocolBufferException { | ||
53 | + assertNotNull(callback.getPayloadBytes()); | ||
54 | + TransportProtos.AttributeUpdateNotificationMsg.Builder attributeUpdateNotificationMsgBuilder = TransportProtos.AttributeUpdateNotificationMsg.newBuilder(); | ||
55 | + List<TransportProtos.TsKvProto> tsKvProtoList = getTsKvProtoList(); | ||
56 | + attributeUpdateNotificationMsgBuilder.addAllSharedUpdated(tsKvProtoList); | ||
57 | + | ||
58 | + TransportProtos.AttributeUpdateNotificationMsg expectedAttributeUpdateNotificationMsg = attributeUpdateNotificationMsgBuilder.build(); | ||
59 | + TransportProtos.AttributeUpdateNotificationMsg actualAttributeUpdateNotificationMsg = TransportProtos.AttributeUpdateNotificationMsg.parseFrom(callback.getPayloadBytes()); | ||
60 | + | ||
61 | + List<TransportProtos.KeyValueProto> actualSharedUpdatedList = actualAttributeUpdateNotificationMsg.getSharedUpdatedList().stream().map(TransportProtos.TsKvProto::getKv).collect(Collectors.toList()); | ||
62 | + List<TransportProtos.KeyValueProto> expectedSharedUpdatedList = expectedAttributeUpdateNotificationMsg.getSharedUpdatedList().stream().map(TransportProtos.TsKvProto::getKv).collect(Collectors.toList()); | ||
63 | + | ||
64 | + assertEquals(expectedSharedUpdatedList.size(), actualSharedUpdatedList.size()); | ||
65 | + assertTrue(actualSharedUpdatedList.containsAll(expectedSharedUpdatedList)); | ||
66 | + | ||
67 | + } | ||
68 | + | ||
69 | + protected void validateDeleteAttributesResponse(TestCoapCallback callback) throws InvalidProtocolBufferException { | ||
70 | + assertNotNull(callback.getPayloadBytes()); | ||
71 | + TransportProtos.AttributeUpdateNotificationMsg.Builder attributeUpdateNotificationMsgBuilder = TransportProtos.AttributeUpdateNotificationMsg.newBuilder(); | ||
72 | + attributeUpdateNotificationMsgBuilder.addSharedDeleted("attribute5"); | ||
73 | + | ||
74 | + TransportProtos.AttributeUpdateNotificationMsg expectedAttributeUpdateNotificationMsg = attributeUpdateNotificationMsgBuilder.build(); | ||
75 | + TransportProtos.AttributeUpdateNotificationMsg actualAttributeUpdateNotificationMsg = TransportProtos.AttributeUpdateNotificationMsg.parseFrom(callback.getPayloadBytes()); | ||
76 | + | ||
77 | + assertEquals(expectedAttributeUpdateNotificationMsg.getSharedDeletedList().size(), actualAttributeUpdateNotificationMsg.getSharedDeletedList().size()); | ||
78 | + assertEquals("attribute5", actualAttributeUpdateNotificationMsg.getSharedDeletedList().get(0)); | ||
79 | + | ||
80 | + } | ||
81 | + | ||
82 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.updates.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.attributes.updates.AbstractCoapAttributesUpdatesIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapAttributesUpdatesSqlIntegrationTest extends AbstractCoapAttributesUpdatesIntegrationTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.updates.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.attributes.updates.AbstractCoapAttributesUpdatesJsonIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapAttributesUpdatesSqlJsonIntegrationTest extends AbstractCoapAttributesUpdatesJsonIntegrationTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.attributes.updates.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.attributes.updates.AbstractCoapAttributesUpdatesProtoIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapAttributesUpdatesSqlProtoIntegrationTest extends AbstractCoapAttributesUpdatesProtoIntegrationTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.claim; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.eclipse.californium.core.CoapClient; | ||
20 | +import org.eclipse.californium.core.CoapResponse; | ||
21 | +import org.eclipse.californium.core.coap.CoAP; | ||
22 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
23 | +import org.eclipse.californium.elements.exception.ConnectorException; | ||
24 | +import org.junit.After; | ||
25 | +import org.junit.Before; | ||
26 | +import org.junit.Test; | ||
27 | +import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest; | ||
28 | +import org.thingsboard.server.common.data.ClaimRequest; | ||
29 | +import org.thingsboard.server.common.data.Customer; | ||
30 | +import org.thingsboard.server.common.data.Device; | ||
31 | +import org.thingsboard.server.common.data.User; | ||
32 | +import org.thingsboard.server.common.data.security.Authority; | ||
33 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
34 | +import org.thingsboard.server.dao.device.claim.ClaimResponse; | ||
35 | +import org.thingsboard.server.dao.device.claim.ClaimResult; | ||
36 | + | ||
37 | +import java.io.IOException; | ||
38 | + | ||
39 | +import static org.junit.Assert.assertEquals; | ||
40 | +import static org.junit.Assert.assertNotNull; | ||
41 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
42 | + | ||
43 | +@Slf4j | ||
44 | +public abstract class AbstractCoapClaimDeviceTest extends AbstractCoapIntegrationTest { | ||
45 | + | ||
46 | + protected static final String CUSTOMER_USER_PASSWORD = "customerUser123!"; | ||
47 | + | ||
48 | + protected User customerAdmin; | ||
49 | + protected Customer savedCustomer; | ||
50 | + | ||
51 | + @Before | ||
52 | + public void beforeTest() throws Exception { | ||
53 | + super.processBeforeTest("Test Claim device", null, null); | ||
54 | + createCustomerAndUser(); | ||
55 | + } | ||
56 | + | ||
57 | + protected void createCustomerAndUser() throws Exception { | ||
58 | + Customer customer = new Customer(); | ||
59 | + customer.setTenantId(savedTenant.getId()); | ||
60 | + customer.setTitle("Test Claiming Customer"); | ||
61 | + savedCustomer = doPost("/api/customer", customer, Customer.class); | ||
62 | + assertNotNull(savedCustomer); | ||
63 | + assertEquals(savedTenant.getId(), savedCustomer.getTenantId()); | ||
64 | + | ||
65 | + User user = new User(); | ||
66 | + user.setAuthority(Authority.CUSTOMER_USER); | ||
67 | + user.setTenantId(savedTenant.getId()); | ||
68 | + user.setCustomerId(savedCustomer.getId()); | ||
69 | + user.setEmail("customer@thingsboard.org"); | ||
70 | + | ||
71 | + customerAdmin = createUser(user, CUSTOMER_USER_PASSWORD); | ||
72 | + assertNotNull(customerAdmin); | ||
73 | + assertEquals(customerAdmin.getCustomerId(), savedCustomer.getId()); | ||
74 | + } | ||
75 | + | ||
76 | + @After | ||
77 | + public void afterTest() throws Exception { | ||
78 | + super.processAfterTest(); | ||
79 | + } | ||
80 | + | ||
81 | + @Test | ||
82 | + public void testClaimingDevice() throws Exception { | ||
83 | + processTestClaimingDevice(false); | ||
84 | + } | ||
85 | + | ||
86 | + @Test | ||
87 | + public void testClaimingDeviceWithoutSecretAndDuration() throws Exception { | ||
88 | + processTestClaimingDevice(true); | ||
89 | + } | ||
90 | + | ||
91 | + protected void processTestClaimingDevice(boolean emptyPayload) throws Exception { | ||
92 | + log.warn("[testClaimingDevice] Device: {}, Transport type: {}", savedDevice.getName(), savedDevice.getType()); | ||
93 | + CoapClient client = getCoapClient(FeatureType.CLAIM); | ||
94 | + byte[] payloadBytes; | ||
95 | + byte[] failurePayloadBytes; | ||
96 | + if (emptyPayload) { | ||
97 | + payloadBytes = "{}".getBytes(); | ||
98 | + failurePayloadBytes = "{\"durationMs\":1}".getBytes(); | ||
99 | + } else { | ||
100 | + payloadBytes = "{\"secretKey\":\"value\", \"durationMs\":60000}".getBytes(); | ||
101 | + failurePayloadBytes = "{\"secretKey\":\"value\", \"durationMs\":1}".getBytes(); | ||
102 | + } | ||
103 | + validateClaimResponse(emptyPayload, client, payloadBytes, failurePayloadBytes); | ||
104 | + } | ||
105 | + | ||
106 | + protected void validateClaimResponse(boolean emptyPayload, CoapClient client, byte[] payloadBytes, byte[] failurePayloadBytes) throws Exception { | ||
107 | + postClaimRequest(client, failurePayloadBytes); | ||
108 | + | ||
109 | + loginUser(customerAdmin.getName(), CUSTOMER_USER_PASSWORD); | ||
110 | + ClaimRequest claimRequest; | ||
111 | + if (!emptyPayload) { | ||
112 | + claimRequest = new ClaimRequest("value"); | ||
113 | + } else { | ||
114 | + claimRequest = new ClaimRequest(null); | ||
115 | + } | ||
116 | + | ||
117 | + ClaimResponse claimResponse = doExecuteWithRetriesAndInterval( | ||
118 | + () -> doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest()), | ||
119 | + 20, | ||
120 | + 100 | ||
121 | + ); | ||
122 | + | ||
123 | + assertEquals(claimResponse, ClaimResponse.FAILURE); | ||
124 | + | ||
125 | + postClaimRequest(client, payloadBytes); | ||
126 | + | ||
127 | + ClaimResult claimResult = doExecuteWithRetriesAndInterval( | ||
128 | + () -> doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResult.class, status().isOk()), | ||
129 | + 20, | ||
130 | + 100 | ||
131 | + ); | ||
132 | + assertEquals(claimResult.getResponse(), ClaimResponse.SUCCESS); | ||
133 | + Device claimedDevice = claimResult.getDevice(); | ||
134 | + assertNotNull(claimedDevice); | ||
135 | + assertNotNull(claimedDevice.getCustomerId()); | ||
136 | + assertEquals(customerAdmin.getCustomerId(), claimedDevice.getCustomerId()); | ||
137 | + | ||
138 | + claimResponse = doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest()); | ||
139 | + assertEquals(claimResponse, ClaimResponse.CLAIMED); | ||
140 | + } | ||
141 | + | ||
142 | + private void postClaimRequest(CoapClient client, byte[] payload) throws IOException, ConnectorException { | ||
143 | + CoapResponse coapResponse = client.setTimeout((long) 60000).post(payload, MediaTypeRegistry.APPLICATION_JSON); | ||
144 | + assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode()); | ||
145 | + } | ||
146 | + | ||
147 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.claim; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
23 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
24 | + | ||
25 | +@Slf4j | ||
26 | +public abstract class AbstractCoapClaimJsonDeviceTest extends AbstractCoapClaimDeviceTest { | ||
27 | + | ||
28 | + @Before | ||
29 | + public void beforeTest() throws Exception { | ||
30 | + super.processBeforeTest("Test Claim device Json", CoapDeviceType.DEFAULT, TransportPayloadType.JSON); | ||
31 | + createCustomerAndUser(); | ||
32 | + } | ||
33 | + | ||
34 | + @After | ||
35 | + public void afterTest() throws Exception { | ||
36 | + super.afterTest(); | ||
37 | + } | ||
38 | + | ||
39 | + @Test | ||
40 | + public void testClaimingDevice() throws Exception { | ||
41 | + super.testClaimingDevice(); | ||
42 | + } | ||
43 | + | ||
44 | + @Test | ||
45 | + public void testClaimingDeviceWithoutSecretAndDuration() throws Exception { | ||
46 | + super.testClaimingDeviceWithoutSecretAndDuration(); | ||
47 | + } | ||
48 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.claim; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.eclipse.californium.core.CoapClient; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
24 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
25 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
26 | +import org.thingsboard.server.gen.transport.TransportApiProtos; | ||
27 | + | ||
28 | +@Slf4j | ||
29 | +public abstract class AbstractCoapClaimProtoDeviceTest extends AbstractCoapClaimDeviceTest { | ||
30 | + | ||
31 | + @Before | ||
32 | + public void beforeTest() throws Exception { | ||
33 | + processBeforeTest("Test Claim device Proto", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF); | ||
34 | + createCustomerAndUser(); | ||
35 | + } | ||
36 | + | ||
37 | + @After | ||
38 | + public void afterTest() throws Exception { super.afterTest(); } | ||
39 | + | ||
40 | + @Test | ||
41 | + public void testClaimingDevice() throws Exception { | ||
42 | + processTestClaimingDevice(false); | ||
43 | + } | ||
44 | + | ||
45 | + @Test | ||
46 | + public void testClaimingDeviceWithoutSecretAndDuration() throws Exception { | ||
47 | + processTestClaimingDevice(true); | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + protected void processTestClaimingDevice(boolean emptyPayload) throws Exception { | ||
52 | + CoapClient client = getCoapClient(FeatureType.CLAIM); | ||
53 | + byte[] payloadBytes; | ||
54 | + if (emptyPayload) { | ||
55 | + TransportApiProtos.ClaimDevice claimDevice = getClaimDevice(0, emptyPayload); | ||
56 | + payloadBytes = claimDevice.toByteArray(); | ||
57 | + } else { | ||
58 | + TransportApiProtos.ClaimDevice claimDevice = getClaimDevice(60000, emptyPayload); | ||
59 | + payloadBytes = claimDevice.toByteArray(); | ||
60 | + } | ||
61 | + TransportApiProtos.ClaimDevice claimDevice = getClaimDevice(1, emptyPayload); | ||
62 | + byte[] failurePayloadBytes = claimDevice.toByteArray(); | ||
63 | + validateClaimResponse(emptyPayload, client, payloadBytes, failurePayloadBytes); | ||
64 | + } | ||
65 | + | ||
66 | + private TransportApiProtos.ClaimDevice getClaimDevice(long duration, boolean emptyPayload) { | ||
67 | + TransportApiProtos.ClaimDevice.Builder claimDeviceBuilder = TransportApiProtos.ClaimDevice.newBuilder(); | ||
68 | + if (!emptyPayload) { | ||
69 | + claimDeviceBuilder.setSecretKey("value"); | ||
70 | + } | ||
71 | + if (duration > 0) { | ||
72 | + claimDeviceBuilder.setSecretKey("value"); | ||
73 | + claimDeviceBuilder.setDurationMs(duration); | ||
74 | + } else { | ||
75 | + claimDeviceBuilder.setDurationMs(0); | ||
76 | + } | ||
77 | + return claimDeviceBuilder.build(); | ||
78 | + } | ||
79 | + | ||
80 | + | ||
81 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.claim.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.claim.AbstractCoapClaimJsonDeviceTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapClaimDeviceJsonSqlTest extends AbstractCoapClaimJsonDeviceTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.claim.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.claim.AbstractCoapClaimProtoDeviceTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapClaimDeviceProtoSqlTest extends AbstractCoapClaimProtoDeviceTest { | ||
23 | +} |
application/src/test/java/org/thingsboard/server/transport/coap/claim/sql/CoapClaimDeviceSqlTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/updates/nosql/MqttAttributesUpdatesNoSqlIntegrationTest.java
@@ -13,12 +13,11 @@ | @@ -13,12 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.updates.nosql; | 16 | +package org.thingsboard.server.transport.coap.claim.sql; |
17 | 17 | ||
18 | -import org.thingsboard.server.dao.service.DaoNoSqlTest; | ||
19 | -import org.thingsboard.server.mqtt.attributes.updates.AbstractMqttAttributesUpdatesJsonIntegrationTest; | 18 | +import org.thingsboard.server.transport.coap.claim.AbstractCoapClaimDeviceTest; |
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | 20 | ||
21 | - | ||
22 | -@DaoNoSqlTest | ||
23 | -public class MqttAttributesUpdatesNoSqlIntegrationTest extends AbstractMqttAttributesUpdatesJsonIntegrationTest { | 21 | +@DaoSqlTest |
22 | +public class CoapClaimDeviceSqlTest extends AbstractCoapClaimDeviceTest { | ||
24 | } | 23 | } |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.provision; | ||
17 | + | ||
18 | +import com.google.gson.JsonObject; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.eclipse.californium.core.CoapClient; | ||
21 | +import org.eclipse.californium.core.CoapResponse; | ||
22 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
23 | +import org.eclipse.californium.elements.exception.ConnectorException; | ||
24 | +import org.junit.After; | ||
25 | +import org.junit.Assert; | ||
26 | +import org.junit.Test; | ||
27 | +import org.springframework.beans.factory.annotation.Autowired; | ||
28 | +import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest; | ||
29 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
30 | +import org.thingsboard.server.common.data.Device; | ||
31 | +import org.thingsboard.server.common.data.DeviceProfileProvisionType; | ||
32 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
33 | +import org.thingsboard.server.common.data.security.DeviceCredentials; | ||
34 | +import org.thingsboard.server.common.msg.EncryptionUtil; | ||
35 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
36 | +import org.thingsboard.server.common.transport.util.JsonUtils; | ||
37 | +import org.thingsboard.server.dao.device.DeviceCredentialsService; | ||
38 | +import org.thingsboard.server.dao.device.DeviceService; | ||
39 | +import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; | ||
40 | + | ||
41 | +import java.io.IOException; | ||
42 | + | ||
43 | +import static org.junit.Assert.assertEquals; | ||
44 | + | ||
45 | +@Slf4j | ||
46 | +public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIntegrationTest { | ||
47 | + | ||
48 | + @Autowired | ||
49 | + DeviceCredentialsService deviceCredentialsService; | ||
50 | + | ||
51 | + @Autowired | ||
52 | + DeviceService deviceService; | ||
53 | + | ||
54 | + @After | ||
55 | + public void afterTest() throws Exception { | ||
56 | + super.processAfterTest(); | ||
57 | + } | ||
58 | + | ||
59 | + @Test | ||
60 | + public void testProvisioningDisabledDevice() throws Exception { | ||
61 | + processTestProvisioningDisabledDevice(); | ||
62 | + } | ||
63 | + | ||
64 | + @Test | ||
65 | + public void testProvisioningCheckPreProvisionedDevice() throws Exception { | ||
66 | + processTestProvisioningCheckPreProvisionedDevice(); | ||
67 | + } | ||
68 | + | ||
69 | + @Test | ||
70 | + public void testProvisioningCreateNewDeviceWithoutCredentials() throws Exception { | ||
71 | + processTestProvisioningCreateNewDeviceWithoutCredentials(); | ||
72 | + } | ||
73 | + | ||
74 | + @Test | ||
75 | + public void testProvisioningCreateNewDeviceWithAccessToken() throws Exception { | ||
76 | + processTestProvisioningCreateNewDeviceWithAccessToken(); | ||
77 | + } | ||
78 | + | ||
79 | + @Test | ||
80 | + public void testProvisioningCreateNewDeviceWithCert() throws Exception { | ||
81 | + processTestProvisioningCreateNewDeviceWithCert(); | ||
82 | + } | ||
83 | + | ||
84 | + @Test | ||
85 | + public void testProvisioningWithBadKeyDevice() throws Exception { | ||
86 | + processTestProvisioningWithBadKeyDevice(); | ||
87 | + } | ||
88 | + | ||
89 | + | ||
90 | + private void processTestProvisioningDisabledDevice() throws Exception { | ||
91 | + super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, DeviceProfileProvisionType.DISABLED, null, null); | ||
92 | + byte[] result = createCoapClientAndPublish().getPayload(); | ||
93 | + JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); | ||
94 | + Assert.assertEquals("Provision data was not found!", response.get("errorMsg").getAsString()); | ||
95 | + Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.get("status").getAsString()); | ||
96 | + } | ||
97 | + | ||
98 | + | ||
99 | + private void processTestProvisioningCreateNewDeviceWithoutCredentials() throws Exception { | ||
100 | + super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, "testProvisionKey", "testProvisionSecret"); | ||
101 | + byte[] result = createCoapClientAndPublish().getPayload(); | ||
102 | + JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); | ||
103 | + | ||
104 | + Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); | ||
105 | + | ||
106 | + Assert.assertNotNull(createdDevice); | ||
107 | + | ||
108 | + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); | ||
109 | + | ||
110 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); | ||
111 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | ||
112 | + } | ||
113 | + | ||
114 | + | ||
115 | + private void processTestProvisioningCreateNewDeviceWithAccessToken() throws Exception { | ||
116 | + super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, "testProvisionKey", "testProvisionSecret"); | ||
117 | + String requestCredentials = ",\"credentialsType\": \"ACCESS_TOKEN\",\"token\": \"test_token\""; | ||
118 | + byte[] result = createCoapClientAndPublish(requestCredentials).getPayload(); | ||
119 | + JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); | ||
120 | + | ||
121 | + Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); | ||
122 | + | ||
123 | + Assert.assertNotNull(createdDevice); | ||
124 | + | ||
125 | + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); | ||
126 | + | ||
127 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); | ||
128 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "ACCESS_TOKEN"); | ||
129 | + Assert.assertEquals(deviceCredentials.getCredentialsId(), "test_token"); | ||
130 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | ||
131 | + } | ||
132 | + | ||
133 | + | ||
134 | + private void processTestProvisioningCreateNewDeviceWithCert() throws Exception { | ||
135 | + super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, "testProvisionKey", "testProvisionSecret"); | ||
136 | + String requestCredentials = ",\"credentialsType\": \"X509_CERTIFICATE\",\"hash\": \"testHash\""; | ||
137 | + byte[] result = createCoapClientAndPublish(requestCredentials).getPayload(); | ||
138 | + JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); | ||
139 | + | ||
140 | + Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); | ||
141 | + | ||
142 | + Assert.assertNotNull(createdDevice); | ||
143 | + | ||
144 | + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); | ||
145 | + | ||
146 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); | ||
147 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "X509_CERTIFICATE"); | ||
148 | + | ||
149 | + String cert = EncryptionUtil.trimNewLines(deviceCredentials.getCredentialsValue()); | ||
150 | + String sha3Hash = EncryptionUtil.getSha3Hash(cert); | ||
151 | + | ||
152 | + Assert.assertEquals(deviceCredentials.getCredentialsId(), sha3Hash); | ||
153 | + | ||
154 | + Assert.assertEquals(deviceCredentials.getCredentialsValue(), "testHash"); | ||
155 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | ||
156 | + } | ||
157 | + | ||
158 | + private void processTestProvisioningCheckPreProvisionedDevice() throws Exception { | ||
159 | + super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, "testProvisionKey", "testProvisionSecret"); | ||
160 | + byte[] result = createCoapClientAndPublish().getPayload(); | ||
161 | + JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); | ||
162 | + | ||
163 | + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), savedDevice.getId()); | ||
164 | + | ||
165 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString()); | ||
166 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString()); | ||
167 | + } | ||
168 | + | ||
169 | + private void processTestProvisioningWithBadKeyDevice() throws Exception { | ||
170 | + super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, "testProvisionKeyOrig", "testProvisionSecret"); | ||
171 | + byte[] result = createCoapClientAndPublish().getPayload(); | ||
172 | + JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject(); | ||
173 | + Assert.assertEquals("Provision data was not found!", response.get("errorMsg").getAsString()); | ||
174 | + Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.get("status").getAsString()); | ||
175 | + } | ||
176 | + | ||
177 | + private CoapResponse createCoapClientAndPublish() throws Exception { | ||
178 | + return createCoapClientAndPublish(""); | ||
179 | + } | ||
180 | + | ||
181 | + private CoapResponse createCoapClientAndPublish(String deviceCredentials) throws Exception { | ||
182 | + String provisionRequestMsg = createTestProvisionMessage(deviceCredentials); | ||
183 | + CoapClient client = getCoapClient(FeatureType.PROVISION); | ||
184 | + return postProvision(client, provisionRequestMsg.getBytes()); | ||
185 | + } | ||
186 | + | ||
187 | + | ||
188 | + private CoapResponse postProvision(CoapClient client, byte[] payload) throws IOException, ConnectorException { | ||
189 | + return client.setTimeout((long) 60000).post(payload, MediaTypeRegistry.APPLICATION_JSON); | ||
190 | + } | ||
191 | + | ||
192 | + private String createTestProvisionMessage(String deviceCredentials) { | ||
193 | + return "{\"deviceName\":\"Test Provision device\",\"provisionDeviceKey\":\"testProvisionKey\", \"provisionDeviceSecret\":\"testProvisionSecret\"" + deviceCredentials + "}"; | ||
194 | + } | ||
195 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.provision; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.eclipse.californium.core.CoapClient; | ||
20 | +import org.eclipse.californium.core.CoapResponse; | ||
21 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
22 | +import org.eclipse.californium.elements.exception.ConnectorException; | ||
23 | +import org.junit.After; | ||
24 | +import org.junit.Assert; | ||
25 | +import org.junit.Test; | ||
26 | +import org.springframework.beans.factory.annotation.Autowired; | ||
27 | +import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest; | ||
28 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
29 | +import org.thingsboard.server.common.data.Device; | ||
30 | +import org.thingsboard.server.common.data.DeviceProfileProvisionType; | ||
31 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
32 | +import org.thingsboard.server.common.data.security.DeviceCredentials; | ||
33 | +import org.thingsboard.server.common.data.security.DeviceCredentialsType; | ||
34 | +import org.thingsboard.server.common.msg.EncryptionUtil; | ||
35 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
36 | +import org.thingsboard.server.dao.device.DeviceCredentialsService; | ||
37 | +import org.thingsboard.server.dao.device.DeviceService; | ||
38 | +import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; | ||
39 | +import org.thingsboard.server.gen.transport.TransportProtos.CredentialsDataProto; | ||
40 | +import org.thingsboard.server.gen.transport.TransportProtos.CredentialsType; | ||
41 | +import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceCredentialsMsg; | ||
42 | +import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceRequestMsg; | ||
43 | +import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceResponseMsg; | ||
44 | +import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg; | ||
45 | +import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg; | ||
46 | + | ||
47 | +import java.io.IOException; | ||
48 | + | ||
49 | +@Slf4j | ||
50 | +public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapIntegrationTest { | ||
51 | + | ||
52 | + @Autowired | ||
53 | + DeviceCredentialsService deviceCredentialsService; | ||
54 | + | ||
55 | + @Autowired | ||
56 | + DeviceService deviceService; | ||
57 | + | ||
58 | + @After | ||
59 | + public void afterTest() throws Exception { | ||
60 | + super.processAfterTest(); | ||
61 | + } | ||
62 | + | ||
63 | + @Test | ||
64 | + public void testProvisioningDisabledDevice() throws Exception { | ||
65 | + processTestProvisioningDisabledDevice(); | ||
66 | + } | ||
67 | + | ||
68 | + @Test | ||
69 | + public void testProvisioningCheckPreProvisionedDevice() throws Exception { | ||
70 | + processTestProvisioningCheckPreProvisionedDevice(); | ||
71 | + } | ||
72 | + | ||
73 | + @Test | ||
74 | + public void testProvisioningCreateNewDeviceWithoutCredentials() throws Exception { | ||
75 | + processTestProvisioningCreateNewDeviceWithoutCredentials(); | ||
76 | + } | ||
77 | + | ||
78 | + @Test | ||
79 | + public void testProvisioningCreateNewDeviceWithAccessToken() throws Exception { | ||
80 | + processTestProvisioningCreateNewDeviceWithAccessToken(); | ||
81 | + } | ||
82 | + | ||
83 | + @Test | ||
84 | + public void testProvisioningCreateNewDeviceWithCert() throws Exception { | ||
85 | + processTestProvisioningCreateNewDeviceWithCert(); | ||
86 | + } | ||
87 | + | ||
88 | + @Test | ||
89 | + public void testProvisioningWithBadKeyDevice() throws Exception { | ||
90 | + processTestProvisioningWithBadKeyDevice(); | ||
91 | + } | ||
92 | + | ||
93 | + | ||
94 | + private void processTestProvisioningDisabledDevice() throws Exception { | ||
95 | + super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, DeviceProfileProvisionType.DISABLED, null, null); | ||
96 | + ProvisionDeviceResponseMsg result = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish().getPayload()); | ||
97 | + Assert.assertNotNull(result); | ||
98 | + Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), result.getStatus().toString()); | ||
99 | + } | ||
100 | + | ||
101 | + private void processTestProvisioningCreateNewDeviceWithoutCredentials() throws Exception { | ||
102 | + super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, "testProvisionKey", "testProvisionSecret"); | ||
103 | + ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish().getPayload()); | ||
104 | + | ||
105 | + Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); | ||
106 | + | ||
107 | + Assert.assertNotNull(createdDevice); | ||
108 | + | ||
109 | + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); | ||
110 | + | ||
111 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | ||
112 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | ||
113 | + } | ||
114 | + | ||
115 | + private void processTestProvisioningCreateNewDeviceWithAccessToken() throws Exception { | ||
116 | + super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, "testProvisionKey", "testProvisionSecret"); | ||
117 | + CredentialsDataProto requestCredentials = CredentialsDataProto.newBuilder().setValidateDeviceTokenRequestMsg(ValidateDeviceTokenRequestMsg.newBuilder().setToken("test_token").build()).build(); | ||
118 | + | ||
119 | + ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish(createTestsProvisionMessage(CredentialsType.ACCESS_TOKEN, requestCredentials)).getPayload()); | ||
120 | + | ||
121 | + Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); | ||
122 | + | ||
123 | + Assert.assertNotNull(createdDevice); | ||
124 | + | ||
125 | + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); | ||
126 | + | ||
127 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | ||
128 | + Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.ACCESS_TOKEN); | ||
129 | + Assert.assertEquals(deviceCredentials.getCredentialsId(), "test_token"); | ||
130 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | ||
131 | + } | ||
132 | + | ||
133 | + private void processTestProvisioningCreateNewDeviceWithCert() throws Exception { | ||
134 | + super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, "testProvisionKey", "testProvisionSecret"); | ||
135 | + CredentialsDataProto requestCredentials = CredentialsDataProto.newBuilder().setValidateDeviceX509CertRequestMsg(ValidateDeviceX509CertRequestMsg.newBuilder().setHash("testHash").build()).build(); | ||
136 | + | ||
137 | + ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish(createTestsProvisionMessage(CredentialsType.X509_CERTIFICATE, requestCredentials)).getPayload()); | ||
138 | + | ||
139 | + Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device"); | ||
140 | + | ||
141 | + Assert.assertNotNull(createdDevice); | ||
142 | + | ||
143 | + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId()); | ||
144 | + | ||
145 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | ||
146 | + Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.X509_CERTIFICATE); | ||
147 | + | ||
148 | + String cert = EncryptionUtil.trimNewLines(deviceCredentials.getCredentialsValue()); | ||
149 | + String sha3Hash = EncryptionUtil.getSha3Hash(cert); | ||
150 | + | ||
151 | + Assert.assertEquals(deviceCredentials.getCredentialsId(), sha3Hash); | ||
152 | + | ||
153 | + Assert.assertEquals(deviceCredentials.getCredentialsValue(), "testHash"); | ||
154 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | ||
155 | + } | ||
156 | + | ||
157 | + private void processTestProvisioningCheckPreProvisionedDevice() throws Exception { | ||
158 | + super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, "testProvisionKey", "testProvisionSecret"); | ||
159 | + ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish().getPayload()); | ||
160 | + | ||
161 | + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), savedDevice.getId()); | ||
162 | + | ||
163 | + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString()); | ||
164 | + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString()); | ||
165 | + } | ||
166 | + | ||
167 | + private void processTestProvisioningWithBadKeyDevice() throws Exception { | ||
168 | + super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, "testProvisionKeyOrig", "testProvisionSecret"); | ||
169 | + ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish().getPayload()); | ||
170 | + Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.getStatus().toString()); | ||
171 | + } | ||
172 | + | ||
173 | + private CoapResponse createCoapClientAndPublish() throws Exception { | ||
174 | + byte[] provisionRequestMsg = createTestProvisionMessage(); | ||
175 | + return createCoapClientAndPublish(provisionRequestMsg); | ||
176 | + } | ||
177 | + | ||
178 | + private CoapResponse createCoapClientAndPublish(byte[] provisionRequestMsg) throws Exception { | ||
179 | + CoapClient client = getCoapClient(FeatureType.PROVISION); | ||
180 | + return postProvision(client, provisionRequestMsg); | ||
181 | + } | ||
182 | + | ||
183 | + private CoapResponse postProvision(CoapClient client, byte[] payload) throws IOException, ConnectorException { | ||
184 | + return client.setTimeout((long) 60000).post(payload, MediaTypeRegistry.APPLICATION_JSON); | ||
185 | + } | ||
186 | + | ||
187 | + private byte[] createTestsProvisionMessage(CredentialsType credentialsType, CredentialsDataProto credentialsData) throws Exception { | ||
188 | + return ProvisionDeviceRequestMsg.newBuilder() | ||
189 | + .setDeviceName("Test Provision device") | ||
190 | + .setCredentialsType(credentialsType != null ? credentialsType : CredentialsType.ACCESS_TOKEN) | ||
191 | + .setCredentialsDataProto(credentialsData != null ? credentialsData: CredentialsDataProto.newBuilder().build()) | ||
192 | + .setProvisionDeviceCredentialsMsg( | ||
193 | + ProvisionDeviceCredentialsMsg.newBuilder() | ||
194 | + .setProvisionDeviceKey("testProvisionKey") | ||
195 | + .setProvisionDeviceSecret("testProvisionSecret") | ||
196 | + ).build() | ||
197 | + .toByteArray(); | ||
198 | + } | ||
199 | + | ||
200 | + | ||
201 | + private byte[] createTestProvisionMessage() throws Exception { | ||
202 | + return createTestsProvisionMessage(null, null); | ||
203 | + } | ||
204 | + | ||
205 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.provision.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.provision.AbstractCoapProvisionJsonDeviceTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapProvisionDeviceJsonSqlTest extends AbstractCoapProvisionJsonDeviceTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.provision.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.provision.AbstractCoapProvisionProtoDeviceTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapProvisionDeviceProtoSqlTest extends AbstractCoapProvisionProtoDeviceTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.rpc; | ||
17 | + | ||
18 | +import com.datastax.oss.driver.api.core.uuid.Uuids; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Assert; | ||
22 | +import org.junit.Before; | ||
23 | +import org.junit.Test; | ||
24 | +import org.thingsboard.server.service.security.AccessValidator; | ||
25 | + | ||
26 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
27 | + | ||
28 | +@Slf4j | ||
29 | +public abstract class AbstractCoapServerSideRpcDefaultIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest { | ||
30 | + | ||
31 | + @Before | ||
32 | + public void beforeTest() throws Exception { | ||
33 | + processBeforeTest("RPC test device", null, null); | ||
34 | + } | ||
35 | + | ||
36 | + @After | ||
37 | + public void afterTest() throws Exception { | ||
38 | + super.processAfterTest(); | ||
39 | + } | ||
40 | + | ||
41 | + @Test | ||
42 | + public void testServerCoapOneWayRpcDeviceOffline() throws Exception { | ||
43 | + String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"24\",\"value\": 1},\"timeout\": 6000}"; | ||
44 | + String deviceId = savedDevice.getId().getId().toString(); | ||
45 | + | ||
46 | + doPostAsync("/api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class, status().is(409), | ||
47 | + asyncContextTimeoutToUseRpcPlugin); | ||
48 | + } | ||
49 | + | ||
50 | + @Test | ||
51 | + public void testServerCoapOneWayRpcDeviceDoesNotExist() throws Exception { | ||
52 | + String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"25\",\"value\": 1}}"; | ||
53 | + String nonExistentDeviceId = Uuids.timeBased().toString(); | ||
54 | + | ||
55 | + String result = doPostAsync("/api/plugins/rpc/oneway/" + nonExistentDeviceId, setGpioRequest, String.class, | ||
56 | + status().isNotFound()); | ||
57 | + Assert.assertEquals(AccessValidator.DEVICE_WITH_REQUESTED_ID_NOT_FOUND, result); | ||
58 | + } | ||
59 | + | ||
60 | + @Test | ||
61 | + public void testServerCoapTwoWayRpcDeviceOffline() throws Exception { | ||
62 | + String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"27\",\"value\": 1},\"timeout\": 6000}"; | ||
63 | + String deviceId = savedDevice.getId().getId().toString(); | ||
64 | + | ||
65 | + doPostAsync("/api/plugins/rpc/twoway/" + deviceId, setGpioRequest, String.class, status().is(409), | ||
66 | + asyncContextTimeoutToUseRpcPlugin); | ||
67 | + } | ||
68 | + | ||
69 | + @Test | ||
70 | + public void testServerCoapTwoWayRpcDeviceDoesNotExist() throws Exception { | ||
71 | + String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"28\",\"value\": 1}}"; | ||
72 | + String nonExistentDeviceId = Uuids.timeBased().toString(); | ||
73 | + | ||
74 | + String result = doPostAsync("/api/plugins/rpc/twoway/" + nonExistentDeviceId, setGpioRequest, String.class, | ||
75 | + status().isNotFound()); | ||
76 | + Assert.assertEquals(AccessValidator.DEVICE_WITH_REQUESTED_ID_NOT_FOUND, result); | ||
77 | + } | ||
78 | + | ||
79 | + @Test | ||
80 | + public void testServerCoapOneWayRpc() throws Exception { | ||
81 | + processOneWayRpcTest(); | ||
82 | + } | ||
83 | + | ||
84 | + @Test | ||
85 | + public void testServerCoapTwoWayRpc() throws Exception { | ||
86 | + processTwoWayRpcTest(); | ||
87 | + } | ||
88 | + | ||
89 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.rpc; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.apache.commons.lang3.StringUtils; | ||
20 | +import org.eclipse.californium.core.CoapClient; | ||
21 | +import org.eclipse.californium.core.CoapHandler; | ||
22 | +import org.eclipse.californium.core.CoapObserveRelation; | ||
23 | +import org.eclipse.californium.core.CoapResponse; | ||
24 | +import org.eclipse.californium.core.coap.CoAP; | ||
25 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
26 | +import org.eclipse.californium.core.coap.Request; | ||
27 | +import org.junit.Assert; | ||
28 | +import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest; | ||
29 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
30 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
31 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
32 | + | ||
33 | +import java.util.concurrent.CountDownLatch; | ||
34 | +import java.util.concurrent.TimeUnit; | ||
35 | + | ||
36 | +import static org.junit.Assert.assertEquals; | ||
37 | +import static org.junit.Assert.assertNotNull; | ||
38 | +import static org.junit.Assert.assertTrue; | ||
39 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
40 | + | ||
41 | +@Slf4j | ||
42 | +public abstract class AbstractCoapServerSideRpcIntegrationTest extends AbstractCoapIntegrationTest { | ||
43 | + | ||
44 | + protected static final String DEVICE_RESPONSE = "{\"value1\":\"A\",\"value2\":\"B\"}"; | ||
45 | + | ||
46 | + protected Long asyncContextTimeoutToUseRpcPlugin; | ||
47 | + | ||
48 | + protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception { | ||
49 | + super.processBeforeTest(deviceName, coapDeviceType, payloadType); | ||
50 | + asyncContextTimeoutToUseRpcPlugin = 10000L; | ||
51 | + } | ||
52 | + | ||
53 | + protected void processOneWayRpcTest() throws Exception { | ||
54 | + CoapClient client = getCoapClient(FeatureType.RPC); | ||
55 | + client.useCONs(); | ||
56 | + | ||
57 | + CountDownLatch latch = new CountDownLatch(1); | ||
58 | + TestCoapCallback testCoapCallback = new TestCoapCallback(client, latch, true); | ||
59 | + | ||
60 | + Request request = Request.newGet().setObserve(); | ||
61 | + CoapObserveRelation observeRelation = client.observe(request, testCoapCallback); | ||
62 | + | ||
63 | + String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}"; | ||
64 | + String deviceId = savedDevice.getId().getId().toString(); | ||
65 | + String result = doPostAsync("/api/plugins/rpc/oneway/" + deviceId, setGpioRequest, String.class, status().isOk()); | ||
66 | + Assert.assertTrue(StringUtils.isEmpty(result)); | ||
67 | + latch.await(3, TimeUnit.SECONDS); | ||
68 | + assertEquals(0, testCoapCallback.getObserve().intValue()); | ||
69 | + observeRelation.proactiveCancel(); | ||
70 | + assertTrue(observeRelation.isCanceled()); | ||
71 | + } | ||
72 | + | ||
73 | + protected void processTwoWayRpcTest() throws Exception { | ||
74 | + CoapClient client = getCoapClient(FeatureType.RPC); | ||
75 | + client.useCONs(); | ||
76 | + | ||
77 | + CountDownLatch latch = new CountDownLatch(1); | ||
78 | + TestCoapCallback testCoapCallback = new TestCoapCallback(client, latch, false); | ||
79 | + | ||
80 | + Request request = Request.newGet().setObserve(); | ||
81 | + request.setType(CoAP.Type.CON); | ||
82 | + CoapObserveRelation observeRelation = client.observe(request, testCoapCallback); | ||
83 | + | ||
84 | + String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"26\",\"value\": 1}}"; | ||
85 | + String deviceId = savedDevice.getId().getId().toString(); | ||
86 | + | ||
87 | + String expected = "{\"value1\":\"A\",\"value2\":\"B\"}"; | ||
88 | + | ||
89 | + String result = doPostAsync("/api/plugins/rpc/twoway/" + deviceId, setGpioRequest, String.class, status().isOk()); | ||
90 | + latch.await(3, TimeUnit.SECONDS); | ||
91 | + | ||
92 | + assertEquals(expected, result); | ||
93 | + assertEquals(0, testCoapCallback.getObserve().intValue()); | ||
94 | + observeRelation.proactiveCancel(); | ||
95 | + assertTrue(observeRelation.isCanceled()); | ||
96 | + | ||
97 | +// // TODO: 3/11/21 Fix test to validate next RPC | ||
98 | +// latch = new CountDownLatch(1); | ||
99 | +// | ||
100 | +// result = doPostAsync("/api/plugins/rpc/twoway/" + deviceId, setGpioRequest, String.class, status().isOk()); | ||
101 | +// latch.await(3, TimeUnit.SECONDS); | ||
102 | +// | ||
103 | +// assertEquals(expected, result); | ||
104 | +// assertEquals(1, testCoapCallback.getObserve().intValue()); | ||
105 | + } | ||
106 | + | ||
107 | + protected void processOnLoadResponse(CoapResponse response, CoapClient client, Integer observe, CountDownLatch latch) { | ||
108 | + client.setURI(getRpcResponseFeatureTokenUrl(accessToken, observe)); | ||
109 | + client.post(new CoapHandler() { | ||
110 | + @Override | ||
111 | + public void onLoad(CoapResponse response) { | ||
112 | + log.warn("Command Response Ack: {}, {}", response.getCode(), response.getResponseText()); | ||
113 | + latch.countDown(); | ||
114 | + } | ||
115 | + | ||
116 | + @Override | ||
117 | + public void onError() { | ||
118 | + log.warn("Command Response Ack Error, No connect"); | ||
119 | + } | ||
120 | + }, DEVICE_RESPONSE, MediaTypeRegistry.APPLICATION_JSON); | ||
121 | + } | ||
122 | + | ||
123 | + protected String getRpcResponseFeatureTokenUrl(String token, int requestId) { | ||
124 | + return COAP_BASE_URL + token + "/" + FeatureType.RPC.name().toLowerCase() + "/" + requestId; | ||
125 | + } | ||
126 | + | ||
127 | + private class TestCoapCallback implements CoapHandler { | ||
128 | + | ||
129 | + private final CoapClient client; | ||
130 | + private final CountDownLatch latch; | ||
131 | + private final boolean isOneWayRpc; | ||
132 | + | ||
133 | + public Integer getObserve() { | ||
134 | + return observe; | ||
135 | + } | ||
136 | + | ||
137 | + private Integer observe; | ||
138 | + | ||
139 | + private TestCoapCallback(CoapClient client, CountDownLatch latch, boolean isOneWayRpc) { | ||
140 | + this.client = client; | ||
141 | + this.latch = latch; | ||
142 | + this.isOneWayRpc = isOneWayRpc; | ||
143 | + } | ||
144 | + | ||
145 | + @Override | ||
146 | + public void onLoad(CoapResponse response) { | ||
147 | + log.warn("coap response: {}, {}", response, response.getCode()); | ||
148 | + assertNotNull(response.getPayload()); | ||
149 | + assertEquals(response.getCode(), CoAP.ResponseCode.CONTENT); | ||
150 | + observe = response.getOptions().getObserve(); | ||
151 | + if (!isOneWayRpc) { | ||
152 | + processOnLoadResponse(response, client, observe, latch); | ||
153 | + } else { | ||
154 | + latch.countDown(); | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + @Override | ||
159 | + public void onError() { | ||
160 | + log.warn("Command Response Ack Error, No connect"); | ||
161 | + } | ||
162 | + | ||
163 | + } | ||
164 | + | ||
165 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.rpc; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
23 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
24 | + | ||
25 | +@Slf4j | ||
26 | +public abstract class AbstractCoapServerSideRpcJsonIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest { | ||
27 | + | ||
28 | + @Before | ||
29 | + public void beforeTest() throws Exception { | ||
30 | + processBeforeTest("RPC test device", CoapDeviceType.DEFAULT, TransportPayloadType.JSON); | ||
31 | + } | ||
32 | + | ||
33 | + @After | ||
34 | + public void afterTest() throws Exception { | ||
35 | + super.processAfterTest(); | ||
36 | + } | ||
37 | + | ||
38 | + @Test | ||
39 | + public void testServerMqttOneWayRpc() throws Exception { | ||
40 | + processOneWayRpcTest(); | ||
41 | + } | ||
42 | + | ||
43 | + @Test | ||
44 | + public void testServerMqttTwoWayRpc() throws Exception { | ||
45 | + processTwoWayRpcTest(); | ||
46 | + } | ||
47 | + | ||
48 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.rpc; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.eclipse.californium.core.CoapClient; | ||
20 | +import org.eclipse.californium.core.CoapHandler; | ||
21 | +import org.eclipse.californium.core.CoapResponse; | ||
22 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
23 | +import org.junit.After; | ||
24 | +import org.junit.Before; | ||
25 | +import org.junit.Test; | ||
26 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
27 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
28 | +import org.thingsboard.server.gen.transport.TransportProtos; | ||
29 | + | ||
30 | +import java.util.concurrent.CountDownLatch; | ||
31 | + | ||
32 | +@Slf4j | ||
33 | +public abstract class AbstractCoapServerSideRpcProtoIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest { | ||
34 | + | ||
35 | + @Before | ||
36 | + public void beforeTest() throws Exception { | ||
37 | + processBeforeTest("RPC test device", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF); | ||
38 | + } | ||
39 | + | ||
40 | + @After | ||
41 | + public void afterTest() throws Exception { | ||
42 | + super.processAfterTest(); | ||
43 | + } | ||
44 | + | ||
45 | + @Test | ||
46 | + public void testServerMqttOneWayRpc() throws Exception { | ||
47 | + processOneWayRpcTest(); | ||
48 | + } | ||
49 | + | ||
50 | + @Test | ||
51 | + public void testServerMqttTwoWayRpc() throws Exception { | ||
52 | + processTwoWayRpcTest(); | ||
53 | + } | ||
54 | + | ||
55 | + @Override | ||
56 | + protected void processOnLoadResponse(CoapResponse response, CoapClient client, Integer observe, CountDownLatch latch) { | ||
57 | + client.setURI(getRpcResponseFeatureTokenUrl(accessToken, observe)); | ||
58 | + TransportProtos.ToDeviceRpcResponseMsg toDeviceRpcResponseMsg = TransportProtos.ToDeviceRpcResponseMsg.newBuilder() | ||
59 | + .setPayload(DEVICE_RESPONSE) | ||
60 | + .setRequestId(observe) | ||
61 | + .build(); | ||
62 | + client.post(new CoapHandler() { | ||
63 | + @Override | ||
64 | + public void onLoad(CoapResponse response) { | ||
65 | + log.warn("Command Response Ack: {}, {}", response.getCode(), response.getResponseText()); | ||
66 | + latch.countDown(); | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public void onError() { | ||
71 | + log.warn("Command Response Ack Error, No connect"); | ||
72 | + } | ||
73 | + }, toDeviceRpcResponseMsg.toByteArray(), MediaTypeRegistry.APPLICATION_JSON); | ||
74 | + } | ||
75 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.rpc.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.rpc.AbstractCoapServerSideRpcJsonIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapServerSideRpcJsonSqlIntegrationTest extends AbstractCoapServerSideRpcJsonIntegrationTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.rpc.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.rpc.AbstractCoapServerSideRpcProtoIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | + | ||
22 | +@DaoSqlTest | ||
23 | +public class CoapServerSideRpcProtoSqlIntegrationTest extends AbstractCoapServerSideRpcProtoIntegrationTest { | ||
24 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.rpc.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.rpc.AbstractCoapServerSideRpcDefaultIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +@DaoSqlTest | ||
22 | +public class CoapServerSideRpcSqlIntegrationTest extends AbstractCoapServerSideRpcDefaultIntegrationTest { | ||
23 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.attributes; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
19 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
20 | +import lombok.extern.slf4j.Slf4j; | ||
21 | +import org.eclipse.californium.core.CoapClient; | ||
22 | +import org.eclipse.californium.core.CoapResponse; | ||
23 | +import org.eclipse.californium.core.coap.CoAP; | ||
24 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
25 | +import org.eclipse.californium.elements.exception.ConnectorException; | ||
26 | +import org.junit.After; | ||
27 | +import org.junit.Before; | ||
28 | +import org.junit.Test; | ||
29 | +import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest; | ||
30 | +import org.thingsboard.server.common.data.id.DeviceId; | ||
31 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
32 | + | ||
33 | +import java.io.IOException; | ||
34 | +import java.util.Arrays; | ||
35 | +import java.util.HashSet; | ||
36 | +import java.util.LinkedHashMap; | ||
37 | +import java.util.List; | ||
38 | +import java.util.Map; | ||
39 | +import java.util.Set; | ||
40 | + | ||
41 | +import static org.junit.Assert.assertEquals; | ||
42 | +import static org.junit.Assert.assertNotNull; | ||
43 | +import static org.junit.Assert.assertTrue; | ||
44 | + | ||
45 | +@Slf4j | ||
46 | +public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoapIntegrationTest { | ||
47 | + | ||
48 | + private static final String PAYLOAD_VALUES_STR = "{\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4," + | ||
49 | + " \"key5\": {\"someNumber\": 42, \"someArray\": [1,2,3], \"someNestedObject\": {\"key\": \"value\"}}}"; | ||
50 | + | ||
51 | + @Before | ||
52 | + public void beforeTest() throws Exception { | ||
53 | + processBeforeTest("Test Post Attributes device", null, null); | ||
54 | + } | ||
55 | + | ||
56 | + @After | ||
57 | + public void afterTest() throws Exception { | ||
58 | + processAfterTest(); | ||
59 | + } | ||
60 | + | ||
61 | + @Test | ||
62 | + public void testPushAttributes() throws Exception { | ||
63 | + List<String> expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5"); | ||
64 | + processAttributesTest(expectedKeys, PAYLOAD_VALUES_STR.getBytes()); | ||
65 | + } | ||
66 | + | ||
67 | + protected void processAttributesTest(List<String> expectedKeys, byte[] payload) throws Exception { | ||
68 | + log.warn("[testPushAttributes] Device: {}, Transport type: {}", savedDevice.getName(), savedDevice.getType()); | ||
69 | + CoapClient client = getCoapClient(FeatureType.ATTRIBUTES); | ||
70 | + | ||
71 | + postAttributes(client, payload); | ||
72 | + | ||
73 | + DeviceId deviceId = savedDevice.getId(); | ||
74 | + | ||
75 | + long start = System.currentTimeMillis(); | ||
76 | + long end = System.currentTimeMillis() + 5000; | ||
77 | + | ||
78 | + List<String> actualKeys = null; | ||
79 | + while (start <= end) { | ||
80 | + actualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() {}); | ||
81 | + if (actualKeys.size() == expectedKeys.size()) { | ||
82 | + break; | ||
83 | + } | ||
84 | + Thread.sleep(100); | ||
85 | + start += 100; | ||
86 | + } | ||
87 | + assertNotNull(actualKeys); | ||
88 | + | ||
89 | + Set<String> actualKeySet = new HashSet<>(actualKeys); | ||
90 | + | ||
91 | + Set<String> expectedKeySet = new HashSet<>(expectedKeys); | ||
92 | + | ||
93 | + assertEquals(expectedKeySet, actualKeySet); | ||
94 | + | ||
95 | + String getAttributesValuesUrl = getAttributesValuesUrl(deviceId, actualKeySet); | ||
96 | + List<Map<String, Object>> values = doGetAsyncTyped(getAttributesValuesUrl, new TypeReference<>() {}); | ||
97 | + assertAttributesValues(values, expectedKeySet); | ||
98 | + String deleteAttributesUrl = "/api/plugins/telemetry/DEVICE/" + deviceId + "/CLIENT_SCOPE?keys=" + String.join(",", actualKeySet); | ||
99 | + doDelete(deleteAttributesUrl); | ||
100 | + } | ||
101 | + | ||
102 | + private void postAttributes(CoapClient client, byte[] payload) throws IOException, ConnectorException { | ||
103 | + if (payload == null) { | ||
104 | + payload = PAYLOAD_VALUES_STR.getBytes(); | ||
105 | + } | ||
106 | + CoapResponse coapResponse = client.setTimeout((long) 60000).post(payload, MediaTypeRegistry.APPLICATION_JSON); | ||
107 | + assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode()); | ||
108 | + } | ||
109 | + | ||
110 | + @SuppressWarnings("unchecked") | ||
111 | + protected void assertAttributesValues(List<Map<String, Object>> deviceValues, Set<String> expectedKeySet) throws JsonProcessingException { | ||
112 | + for (Map<String, Object> map : deviceValues) { | ||
113 | + String key = (String) map.get("key"); | ||
114 | + Object value = map.get("value"); | ||
115 | + assertTrue(expectedKeySet.contains(key)); | ||
116 | + switch (key) { | ||
117 | + case "key1": | ||
118 | + assertEquals("value1", value); | ||
119 | + break; | ||
120 | + case "key2": | ||
121 | + assertEquals(true, value); | ||
122 | + break; | ||
123 | + case "key3": | ||
124 | + assertEquals(3.0, value); | ||
125 | + break; | ||
126 | + case "key4": | ||
127 | + assertEquals(4, value); | ||
128 | + break; | ||
129 | + case "key5": | ||
130 | + assertNotNull(value); | ||
131 | + assertEquals(3, ((LinkedHashMap) value).size()); | ||
132 | + assertEquals(42, ((LinkedHashMap) value).get("someNumber")); | ||
133 | + assertEquals(Arrays.asList(1, 2, 3), ((LinkedHashMap) value).get("someArray")); | ||
134 | + LinkedHashMap<String, String> someNestedObject = (LinkedHashMap) ((LinkedHashMap) value).get("someNestedObject"); | ||
135 | + assertEquals("value", someNestedObject.get("key")); | ||
136 | + break; | ||
137 | + } | ||
138 | + } | ||
139 | + } | ||
140 | + | ||
141 | + private String getAttributesValuesUrl(DeviceId deviceId, Set<String> actualKeySet) { | ||
142 | + return "/api/plugins/telemetry/DEVICE/" + deviceId + "/values/attributes/CLIENT_SCOPE?keys=" + String.join(",", actualKeySet); | ||
143 | + } | ||
144 | + | ||
145 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.attributes; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
23 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
24 | + | ||
25 | +@Slf4j | ||
26 | +public abstract class AbstractCoapAttributesJsonIntegrationTest extends AbstractCoapAttributesIntegrationTest { | ||
27 | + | ||
28 | + @Before | ||
29 | + public void beforeTest() throws Exception { | ||
30 | + processBeforeTest("Test Post Attributes device Json", CoapDeviceType.DEFAULT, TransportPayloadType.JSON); | ||
31 | + } | ||
32 | + | ||
33 | + @After | ||
34 | + public void afterTest() throws Exception { | ||
35 | + processAfterTest(); | ||
36 | + } | ||
37 | + | ||
38 | + @Test | ||
39 | + public void testPushAttributes() throws Exception { | ||
40 | + super.testPushAttributes(); | ||
41 | + } | ||
42 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.attributes; | ||
17 | + | ||
18 | +import com.github.os72.protobuf.dynamic.DynamicSchema; | ||
19 | +import com.google.protobuf.Descriptors; | ||
20 | +import com.google.protobuf.DynamicMessage; | ||
21 | +import com.squareup.wire.schema.internal.parser.ProtoFileElement; | ||
22 | +import lombok.extern.slf4j.Slf4j; | ||
23 | +import org.junit.After; | ||
24 | +import org.junit.Test; | ||
25 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
26 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
27 | +import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; | ||
28 | +import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; | ||
29 | +import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration; | ||
30 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; | ||
31 | +import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; | ||
32 | +import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; | ||
33 | + | ||
34 | +import java.util.Arrays; | ||
35 | +import java.util.List; | ||
36 | + | ||
37 | +import static org.junit.Assert.assertNotNull; | ||
38 | +import static org.junit.Assert.assertTrue; | ||
39 | + | ||
40 | +@Slf4j | ||
41 | +public abstract class AbstractCoapAttributesProtoIntegrationTest extends AbstractCoapAttributesIntegrationTest { | ||
42 | + | ||
43 | + @After | ||
44 | + public void afterTest() throws Exception { | ||
45 | + processAfterTest(); | ||
46 | + } | ||
47 | + | ||
48 | + @Test | ||
49 | + public void testPushAttributes() throws Exception { | ||
50 | + super.processBeforeTest("Test Post Attributes device Proto", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF); | ||
51 | + List<String> expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5"); | ||
52 | + DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); | ||
53 | + assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration); | ||
54 | + CoapDeviceProfileTransportConfiguration coapTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration; | ||
55 | + CoapDeviceTypeConfiguration coapDeviceTypeConfiguration = coapTransportConfiguration.getCoapDeviceTypeConfiguration(); | ||
56 | + assertTrue(coapDeviceTypeConfiguration instanceof DefaultCoapDeviceTypeConfiguration); | ||
57 | + DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = (DefaultCoapDeviceTypeConfiguration) coapDeviceTypeConfiguration; | ||
58 | + TransportPayloadTypeConfiguration transportPayloadTypeConfiguration = defaultCoapDeviceTypeConfiguration.getTransportPayloadTypeConfiguration(); | ||
59 | + assertTrue(transportPayloadTypeConfiguration instanceof ProtoTransportPayloadConfiguration); | ||
60 | + ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = (ProtoTransportPayloadConfiguration) transportPayloadTypeConfiguration; | ||
61 | + ProtoFileElement transportProtoSchemaFile = protoTransportPayloadConfiguration.getTransportProtoSchema(DEVICE_ATTRIBUTES_PROTO_SCHEMA); | ||
62 | + DynamicSchema attributesSchema = protoTransportPayloadConfiguration.getDynamicSchema(transportProtoSchemaFile, ProtoTransportPayloadConfiguration.ATTRIBUTES_PROTO_SCHEMA); | ||
63 | + | ||
64 | + DynamicMessage.Builder nestedJsonObjectBuilder = attributesSchema.newMessageBuilder("PostAttributes.JsonObject.NestedJsonObject"); | ||
65 | + Descriptors.Descriptor nestedJsonObjectBuilderDescriptor = nestedJsonObjectBuilder.getDescriptorForType(); | ||
66 | + assertNotNull(nestedJsonObjectBuilderDescriptor); | ||
67 | + DynamicMessage nestedJsonObject = nestedJsonObjectBuilder.setField(nestedJsonObjectBuilderDescriptor.findFieldByName("key"), "value").build(); | ||
68 | + | ||
69 | + DynamicMessage.Builder jsonObjectBuilder = attributesSchema.newMessageBuilder("PostAttributes.JsonObject"); | ||
70 | + Descriptors.Descriptor jsonObjectBuilderDescriptor = jsonObjectBuilder.getDescriptorForType(); | ||
71 | + assertNotNull(jsonObjectBuilderDescriptor); | ||
72 | + DynamicMessage jsonObject = jsonObjectBuilder | ||
73 | + .setField(jsonObjectBuilderDescriptor.findFieldByName("someNumber"), 42) | ||
74 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 1) | ||
75 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 2) | ||
76 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 3) | ||
77 | + .setField(jsonObjectBuilderDescriptor.findFieldByName("someNestedObject"), nestedJsonObject) | ||
78 | + .build(); | ||
79 | + | ||
80 | + DynamicMessage.Builder postAttributesBuilder = attributesSchema.newMessageBuilder("PostAttributes"); | ||
81 | + Descriptors.Descriptor postAttributesMsgDescriptor = postAttributesBuilder.getDescriptorForType(); | ||
82 | + assertNotNull(postAttributesMsgDescriptor); | ||
83 | + DynamicMessage postAttributesMsg = postAttributesBuilder | ||
84 | + .setField(postAttributesMsgDescriptor.findFieldByName("key1"), "value1") | ||
85 | + .setField(postAttributesMsgDescriptor.findFieldByName("key2"), true) | ||
86 | + .setField(postAttributesMsgDescriptor.findFieldByName("key3"), 3.0) | ||
87 | + .setField(postAttributesMsgDescriptor.findFieldByName("key4"), 4) | ||
88 | + .setField(postAttributesMsgDescriptor.findFieldByName("key5"), jsonObject) | ||
89 | + .build(); | ||
90 | + processAttributesTest(expectedKeys, postAttributesMsg.toByteArray()); | ||
91 | + } | ||
92 | + | ||
93 | +} |
application/src/test/java/org/thingsboard/server/transport/coap/telemetry/attributes/sql/CoapAttributesSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/rpc/nosql/MqttServerSideRpcNoSqlIntegrationTest.java
@@ -13,14 +13,14 @@ | @@ -13,14 +13,14 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.rpc.nosql; | 16 | +package org.thingsboard.server.transport.coap.telemetry.attributes.sql; |
17 | 17 | ||
18 | -import org.thingsboard.server.dao.service.DaoNoSqlTest; | ||
19 | -import org.thingsboard.server.mqtt.rpc.AbstractMqttServerSideRpcDefaultIntegrationTest; | 18 | +import org.thingsboard.server.transport.coap.telemetry.attributes.AbstractCoapAttributesIntegrationTest; |
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Created by Valerii Sosliuk on 8/22/2017. | 22 | * Created by Valerii Sosliuk on 8/22/2017. |
23 | */ | 23 | */ |
24 | -@DaoNoSqlTest | ||
25 | -public class MqttServerSideRpcNoSqlIntegrationTest extends AbstractMqttServerSideRpcDefaultIntegrationTest { | 24 | +@DaoSqlTest |
25 | +public class CoapAttributesSqlIntegrationTest extends AbstractCoapAttributesIntegrationTest { | ||
26 | } | 26 | } |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.attributes.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.telemetry.attributes.AbstractCoapAttributesJsonIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +/** | ||
22 | + * Created by Valerii Sosliuk on 8/22/2017. | ||
23 | + */ | ||
24 | +@DaoSqlTest | ||
25 | +public class CoapAttributesSqlJsonIntegrationTest extends AbstractCoapAttributesJsonIntegrationTest { | ||
26 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.attributes.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.telemetry.attributes.AbstractCoapAttributesProtoIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +/** | ||
22 | + * Created by Valerii Sosliuk on 8/22/2017. | ||
23 | + */ | ||
24 | +@DaoSqlTest | ||
25 | +public class CoapAttributesSqlProtoIntegrationTest extends AbstractCoapAttributesProtoIntegrationTest { | ||
26 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.eclipse.californium.core.CoapClient; | ||
21 | +import org.eclipse.californium.core.CoapResponse; | ||
22 | +import org.eclipse.californium.core.coap.CoAP; | ||
23 | +import org.eclipse.californium.core.coap.MediaTypeRegistry; | ||
24 | +import org.eclipse.californium.elements.exception.ConnectorException; | ||
25 | +import org.junit.After; | ||
26 | +import org.junit.Before; | ||
27 | +import org.junit.Test; | ||
28 | +import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest; | ||
29 | +import org.thingsboard.server.common.msg.session.FeatureType; | ||
30 | + | ||
31 | +import java.io.IOException; | ||
32 | +import java.util.Arrays; | ||
33 | +import java.util.HashSet; | ||
34 | +import java.util.List; | ||
35 | +import java.util.Map; | ||
36 | +import java.util.Set; | ||
37 | + | ||
38 | +import static org.junit.Assert.assertEquals; | ||
39 | +import static org.junit.Assert.assertNotNull; | ||
40 | + | ||
41 | +@Slf4j | ||
42 | +public abstract class AbstractCoapTimeseriesIntegrationTest extends AbstractCoapIntegrationTest { | ||
43 | + | ||
44 | + private static final String PAYLOAD_VALUES_STR = "{\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4," + | ||
45 | + " \"key5\": {\"someNumber\": 42, \"someArray\": [1,2,3], \"someNestedObject\": {\"key\": \"value\"}}}"; | ||
46 | + | ||
47 | + @Before | ||
48 | + public void beforeTest() throws Exception { | ||
49 | + processBeforeTest("Test Post Telemetry device", null, null); | ||
50 | + } | ||
51 | + | ||
52 | + @After | ||
53 | + public void afterTest() throws Exception { | ||
54 | + processAfterTest(); | ||
55 | + } | ||
56 | + | ||
57 | + @Test | ||
58 | + public void testPushTelemetry() throws Exception { | ||
59 | + processTestPostTelemetry(null, false); | ||
60 | + } | ||
61 | + | ||
62 | + @Test | ||
63 | + public void testPushTelemetryWithTs() throws Exception { | ||
64 | + String payloadStr = "{\"ts\": 10000, \"values\": " + PAYLOAD_VALUES_STR + "}"; | ||
65 | + processTestPostTelemetry(payloadStr.getBytes(), true); | ||
66 | + } | ||
67 | + | ||
68 | + protected void processTestPostTelemetry(byte[] payloadBytes, boolean withTs) throws Exception { | ||
69 | + log.warn("[testPushTelemetry] Device: {}, Transport type: {}", savedDevice.getName(), savedDevice.getType()); | ||
70 | + List<String> expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5"); | ||
71 | + CoapClient coapClient = getCoapClient(FeatureType.TELEMETRY); | ||
72 | + postTelemetry(coapClient, payloadBytes); | ||
73 | + | ||
74 | + String deviceId = savedDevice.getId().getId().toString(); | ||
75 | + | ||
76 | + long start = System.currentTimeMillis(); | ||
77 | + long end = System.currentTimeMillis() + 5000; | ||
78 | + | ||
79 | + List<String> actualKeys = null; | ||
80 | + while (start <= end) { | ||
81 | + actualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/timeseries", new TypeReference<>() {}); | ||
82 | + if (actualKeys.size() == expectedKeys.size()) { | ||
83 | + break; | ||
84 | + } | ||
85 | + Thread.sleep(100); | ||
86 | + start += 100; | ||
87 | + } | ||
88 | + assertNotNull(actualKeys); | ||
89 | + | ||
90 | + Set<String> actualKeySet = new HashSet<>(actualKeys); | ||
91 | + Set<String> expectedKeySet = new HashSet<>(expectedKeys); | ||
92 | + | ||
93 | + assertEquals(expectedKeySet, actualKeySet); | ||
94 | + | ||
95 | + String getTelemetryValuesUrl; | ||
96 | + if (withTs) { | ||
97 | + getTelemetryValuesUrl = "/api/plugins/telemetry/DEVICE/" + deviceId + "/values/timeseries?startTs=0&endTs=15000&keys=" + String.join(",", actualKeySet); | ||
98 | + } else { | ||
99 | + getTelemetryValuesUrl = "/api/plugins/telemetry/DEVICE/" + deviceId + "/values/timeseries?keys=" + String.join(",", actualKeySet); | ||
100 | + } | ||
101 | + start = System.currentTimeMillis(); | ||
102 | + end = System.currentTimeMillis() + 5000; | ||
103 | + Map<String, List<Map<String, Object>>> values = null; | ||
104 | + while (start <= end) { | ||
105 | + values = doGetAsyncTyped(getTelemetryValuesUrl, new TypeReference<>() {}); | ||
106 | + boolean valid = values.size() == expectedKeys.size(); | ||
107 | + if (valid) { | ||
108 | + for (String key : expectedKeys) { | ||
109 | + List<Map<String, Object>> tsValues = values.get(key); | ||
110 | + if (tsValues != null && tsValues.size() > 0) { | ||
111 | + Object ts = tsValues.get(0).get("ts"); | ||
112 | + if (ts == null) { | ||
113 | + valid = false; | ||
114 | + break; | ||
115 | + } | ||
116 | + } else { | ||
117 | + valid = false; | ||
118 | + break; | ||
119 | + } | ||
120 | + } | ||
121 | + } | ||
122 | + if (valid) { | ||
123 | + break; | ||
124 | + } | ||
125 | + Thread.sleep(100); | ||
126 | + start += 100; | ||
127 | + } | ||
128 | + assertNotNull(values); | ||
129 | + | ||
130 | + if (withTs) { | ||
131 | + assertTs(values, expectedKeys, 10000, 0); | ||
132 | + } | ||
133 | + assertValues(values, 0); | ||
134 | + } | ||
135 | + | ||
136 | + private void postTelemetry(CoapClient client, byte[] payload) throws IOException, ConnectorException { | ||
137 | + if (payload == null) { | ||
138 | + payload = PAYLOAD_VALUES_STR.getBytes(); | ||
139 | + } | ||
140 | + CoapResponse coapResponse = client.setTimeout((long) 60000).post(payload, MediaTypeRegistry.APPLICATION_JSON); | ||
141 | + assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode()); | ||
142 | + } | ||
143 | + | ||
144 | + private void assertTs(Map<String, List<Map<String, Object>>> deviceValues, List<String> expectedKeys, int ts, int arrayIndex) { | ||
145 | + assertEquals(ts, deviceValues.get(expectedKeys.get(0)).get(arrayIndex).get("ts")); | ||
146 | + assertEquals(ts, deviceValues.get(expectedKeys.get(1)).get(arrayIndex).get("ts")); | ||
147 | + assertEquals(ts, deviceValues.get(expectedKeys.get(2)).get(arrayIndex).get("ts")); | ||
148 | + assertEquals(ts, deviceValues.get(expectedKeys.get(3)).get(arrayIndex).get("ts")); | ||
149 | + assertEquals(ts, deviceValues.get(expectedKeys.get(4)).get(arrayIndex).get("ts")); | ||
150 | + } | ||
151 | + | ||
152 | + private void assertValues(Map<String, List<Map<String, Object>>> deviceValues, int arrayIndex) { | ||
153 | + for (Map.Entry<String, List<Map<String, Object>>> entry : deviceValues.entrySet()) { | ||
154 | + String key = entry.getKey(); | ||
155 | + List<Map<String, Object>> tsKv = entry.getValue(); | ||
156 | + String value = (String) tsKv.get(arrayIndex).get("value"); | ||
157 | + switch (key) { | ||
158 | + case "key1": | ||
159 | + assertEquals("value1", value); | ||
160 | + break; | ||
161 | + case "key2": | ||
162 | + assertEquals("true", value); | ||
163 | + break; | ||
164 | + case "key3": | ||
165 | + assertEquals("3.0", value); | ||
166 | + break; | ||
167 | + case "key4": | ||
168 | + assertEquals("4", value); | ||
169 | + break; | ||
170 | + case "key5": | ||
171 | + assertEquals("{\"someNumber\":42,\"someArray\":[1,2,3],\"someNestedObject\":{\"key\":\"value\"}}", value); | ||
172 | + break; | ||
173 | + } | ||
174 | + } | ||
175 | + } | ||
176 | + | ||
177 | + | ||
178 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries; | ||
17 | + | ||
18 | +import lombok.extern.slf4j.Slf4j; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
23 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
24 | + | ||
25 | +@Slf4j | ||
26 | +public abstract class AbstractCoapTimeseriesJsonIntegrationTest extends AbstractCoapTimeseriesIntegrationTest { | ||
27 | + | ||
28 | + @Before | ||
29 | + public void beforeTest() throws Exception { | ||
30 | + processBeforeTest("Test Post Telemetry device json payload", CoapDeviceType.DEFAULT, TransportPayloadType.JSON); | ||
31 | + } | ||
32 | + | ||
33 | + @After | ||
34 | + public void afterTest() throws Exception { | ||
35 | + processAfterTest(); | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + @Test | ||
40 | + public void testPushTelemetry() throws Exception { | ||
41 | + super.testPushTelemetry(); | ||
42 | + } | ||
43 | + | ||
44 | + @Test | ||
45 | + public void testPushTelemetryWithTs() throws Exception { | ||
46 | + super.testPushTelemetryWithTs(); | ||
47 | + } | ||
48 | + | ||
49 | + | ||
50 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries; | ||
17 | + | ||
18 | +import com.github.os72.protobuf.dynamic.DynamicSchema; | ||
19 | +import com.google.protobuf.Descriptors; | ||
20 | +import com.google.protobuf.DynamicMessage; | ||
21 | +import com.squareup.wire.schema.internal.parser.ProtoFileElement; | ||
22 | +import lombok.extern.slf4j.Slf4j; | ||
23 | +import org.junit.After; | ||
24 | +import org.junit.Test; | ||
25 | +import org.thingsboard.server.common.data.CoapDeviceType; | ||
26 | +import org.thingsboard.server.common.data.DeviceProfileProvisionType; | ||
27 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
28 | +import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; | ||
29 | +import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; | ||
30 | +import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration; | ||
31 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; | ||
32 | +import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; | ||
33 | +import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; | ||
34 | + | ||
35 | +import static org.junit.Assert.assertNotNull; | ||
36 | +import static org.junit.Assert.assertTrue; | ||
37 | + | ||
38 | +@Slf4j | ||
39 | +public abstract class AbstractCoapTimeseriesProtoIntegrationTest extends AbstractCoapTimeseriesIntegrationTest { | ||
40 | + | ||
41 | + @After | ||
42 | + public void afterTest() throws Exception { | ||
43 | + processAfterTest(); | ||
44 | + } | ||
45 | + | ||
46 | + @Test | ||
47 | + public void testPushTelemetry() throws Exception { | ||
48 | + super.processBeforeTest("Test Post Telemetry device proto payload", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF); | ||
49 | + DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); | ||
50 | + assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration); | ||
51 | + CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration; | ||
52 | + CoapDeviceTypeConfiguration coapDeviceTypeConfiguration = coapDeviceProfileTransportConfiguration.getCoapDeviceTypeConfiguration(); | ||
53 | + assertTrue(coapDeviceTypeConfiguration instanceof DefaultCoapDeviceTypeConfiguration); | ||
54 | + DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = (DefaultCoapDeviceTypeConfiguration) coapDeviceTypeConfiguration; | ||
55 | + TransportPayloadTypeConfiguration transportPayloadTypeConfiguration = defaultCoapDeviceTypeConfiguration.getTransportPayloadTypeConfiguration(); | ||
56 | + assertTrue(transportPayloadTypeConfiguration instanceof ProtoTransportPayloadConfiguration); | ||
57 | + ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = (ProtoTransportPayloadConfiguration) transportPayloadTypeConfiguration; | ||
58 | + ProtoFileElement transportProtoSchema = protoTransportPayloadConfiguration.getTransportProtoSchema(DEVICE_TELEMETRY_PROTO_SCHEMA); | ||
59 | + DynamicSchema telemetrySchema = protoTransportPayloadConfiguration.getDynamicSchema(transportProtoSchema, "telemetrySchema"); | ||
60 | + | ||
61 | + DynamicMessage.Builder nestedJsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject.NestedJsonObject"); | ||
62 | + Descriptors.Descriptor nestedJsonObjectBuilderDescriptor = nestedJsonObjectBuilder.getDescriptorForType(); | ||
63 | + assertNotNull(nestedJsonObjectBuilderDescriptor); | ||
64 | + DynamicMessage nestedJsonObject = nestedJsonObjectBuilder.setField(nestedJsonObjectBuilderDescriptor.findFieldByName("key"), "value").build(); | ||
65 | + | ||
66 | + DynamicMessage.Builder jsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject"); | ||
67 | + Descriptors.Descriptor jsonObjectBuilderDescriptor = jsonObjectBuilder.getDescriptorForType(); | ||
68 | + assertNotNull(jsonObjectBuilderDescriptor); | ||
69 | + DynamicMessage jsonObject = jsonObjectBuilder | ||
70 | + .setField(jsonObjectBuilderDescriptor.findFieldByName("someNumber"), 42) | ||
71 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 1) | ||
72 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 2) | ||
73 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 3) | ||
74 | + .setField(jsonObjectBuilderDescriptor.findFieldByName("someNestedObject"), nestedJsonObject) | ||
75 | + .build(); | ||
76 | + | ||
77 | + DynamicMessage.Builder postTelemetryBuilder = telemetrySchema.newMessageBuilder("PostTelemetry"); | ||
78 | + Descriptors.Descriptor postTelemetryMsgDescriptor = postTelemetryBuilder.getDescriptorForType(); | ||
79 | + assertNotNull(postTelemetryMsgDescriptor); | ||
80 | + DynamicMessage postTelemetryMsg = postTelemetryBuilder | ||
81 | + .setField(postTelemetryMsgDescriptor.findFieldByName("key1"), "value1") | ||
82 | + .setField(postTelemetryMsgDescriptor.findFieldByName("key2"), true) | ||
83 | + .setField(postTelemetryMsgDescriptor.findFieldByName("key3"), 3.0) | ||
84 | + .setField(postTelemetryMsgDescriptor.findFieldByName("key4"), 4) | ||
85 | + .setField(postTelemetryMsgDescriptor.findFieldByName("key5"), jsonObject) | ||
86 | + .build(); | ||
87 | + processTestPostTelemetry(postTelemetryMsg.toByteArray(), false); | ||
88 | + } | ||
89 | + | ||
90 | + @Test | ||
91 | + public void testPushTelemetryWithTs() throws Exception { | ||
92 | + String schemaStr = "syntax =\"proto3\";\n" + | ||
93 | + "\n" + | ||
94 | + "package test;\n" + | ||
95 | + "\n" + | ||
96 | + "message PostTelemetry {\n" + | ||
97 | + " int64 ts = 1;\n" + | ||
98 | + " Values values = 2;\n" + | ||
99 | + " \n" + | ||
100 | + " message Values {\n" + | ||
101 | + " string key1 = 3;\n" + | ||
102 | + " bool key2 = 4;\n" + | ||
103 | + " double key3 = 5;\n" + | ||
104 | + " int32 key4 = 6;\n" + | ||
105 | + " JsonObject key5 = 7;\n" + | ||
106 | + " }\n" + | ||
107 | + " \n" + | ||
108 | + " message JsonObject {\n" + | ||
109 | + " int32 someNumber = 8;\n" + | ||
110 | + " repeated int32 someArray = 9;\n" + | ||
111 | + " NestedJsonObject someNestedObject = 10;\n" + | ||
112 | + " message NestedJsonObject {\n" + | ||
113 | + " string key = 11;\n" + | ||
114 | + " }\n" + | ||
115 | + " }\n" + | ||
116 | + "}"; | ||
117 | + super.processBeforeTest("Test Post Telemetry device proto payload", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, schemaStr, null, DeviceProfileProvisionType.DISABLED, null, null); | ||
118 | + DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); | ||
119 | + assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration); | ||
120 | + CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration; | ||
121 | + CoapDeviceTypeConfiguration coapDeviceTypeConfiguration = coapDeviceProfileTransportConfiguration.getCoapDeviceTypeConfiguration(); | ||
122 | + assertTrue(coapDeviceTypeConfiguration instanceof DefaultCoapDeviceTypeConfiguration); | ||
123 | + DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = (DefaultCoapDeviceTypeConfiguration) coapDeviceTypeConfiguration; | ||
124 | + TransportPayloadTypeConfiguration transportPayloadTypeConfiguration = defaultCoapDeviceTypeConfiguration.getTransportPayloadTypeConfiguration(); | ||
125 | + assertTrue(transportPayloadTypeConfiguration instanceof ProtoTransportPayloadConfiguration); | ||
126 | + ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = (ProtoTransportPayloadConfiguration) transportPayloadTypeConfiguration; | ||
127 | + ProtoFileElement transportProtoSchema = protoTransportPayloadConfiguration.getTransportProtoSchema(schemaStr); | ||
128 | + DynamicSchema telemetrySchema = protoTransportPayloadConfiguration.getDynamicSchema(transportProtoSchema, "telemetrySchema"); | ||
129 | + | ||
130 | + DynamicMessage.Builder nestedJsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject.NestedJsonObject"); | ||
131 | + Descriptors.Descriptor nestedJsonObjectBuilderDescriptor = nestedJsonObjectBuilder.getDescriptorForType(); | ||
132 | + assertNotNull(nestedJsonObjectBuilderDescriptor); | ||
133 | + DynamicMessage nestedJsonObject = nestedJsonObjectBuilder.setField(nestedJsonObjectBuilderDescriptor.findFieldByName("key"), "value").build(); | ||
134 | + | ||
135 | + DynamicMessage.Builder jsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject"); | ||
136 | + Descriptors.Descriptor jsonObjectBuilderDescriptor = jsonObjectBuilder.getDescriptorForType(); | ||
137 | + assertNotNull(jsonObjectBuilderDescriptor); | ||
138 | + DynamicMessage jsonObject = jsonObjectBuilder | ||
139 | + .setField(jsonObjectBuilderDescriptor.findFieldByName("someNumber"), 42) | ||
140 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 1) | ||
141 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 2) | ||
142 | + .addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 3) | ||
143 | + .setField(jsonObjectBuilderDescriptor.findFieldByName("someNestedObject"), nestedJsonObject) | ||
144 | + .build(); | ||
145 | + | ||
146 | + | ||
147 | + DynamicMessage.Builder valuesBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.Values"); | ||
148 | + Descriptors.Descriptor valuesDescriptor = valuesBuilder.getDescriptorForType(); | ||
149 | + assertNotNull(valuesDescriptor); | ||
150 | + | ||
151 | + DynamicMessage valuesMsg = valuesBuilder | ||
152 | + .setField(valuesDescriptor.findFieldByName("key1"), "value1") | ||
153 | + .setField(valuesDescriptor.findFieldByName("key2"), true) | ||
154 | + .setField(valuesDescriptor.findFieldByName("key3"), 3.0) | ||
155 | + .setField(valuesDescriptor.findFieldByName("key4"), 4) | ||
156 | + .setField(valuesDescriptor.findFieldByName("key5"), jsonObject) | ||
157 | + .build(); | ||
158 | + | ||
159 | + DynamicMessage.Builder postTelemetryBuilder = telemetrySchema.newMessageBuilder("PostTelemetry"); | ||
160 | + Descriptors.Descriptor postTelemetryMsgDescriptor = postTelemetryBuilder.getDescriptorForType(); | ||
161 | + assertNotNull(postTelemetryMsgDescriptor); | ||
162 | + DynamicMessage postTelemetryMsg = postTelemetryBuilder | ||
163 | + .setField(postTelemetryMsgDescriptor.findFieldByName("ts"), 10000L) | ||
164 | + .setField(postTelemetryMsgDescriptor.findFieldByName("values"), valuesMsg) | ||
165 | + .build(); | ||
166 | + | ||
167 | + processTestPostTelemetry(postTelemetryMsg.toByteArray(), true); | ||
168 | + } | ||
169 | + | ||
170 | +} |
application/src/test/java/org/thingsboard/server/transport/coap/telemetry/timeseries/nosql/CoapTimeseriesNoSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/nosql/MqttAttributesNoSqlIntegrationTest.java
@@ -13,11 +13,11 @@ | @@ -13,11 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes.nosql; | 16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries.nosql; |
17 | 17 | ||
18 | +import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesIntegrationTest; | ||
18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; | 19 | import org.thingsboard.server.dao.service.DaoNoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.attributes.AbstractMqttAttributesIntegrationTest; | ||
20 | 20 | ||
21 | @DaoNoSqlTest | 21 | @DaoNoSqlTest |
22 | -public class MqttAttributesNoSqlIntegrationTest extends AbstractMqttAttributesIntegrationTest { | 22 | +public class CoapTimeseriesNoSqlIntegrationTest extends AbstractCoapTimeseriesIntegrationTest { |
23 | } | 23 | } |
application/src/test/java/org/thingsboard/server/transport/coap/telemetry/timeseries/nosql/CoapTimeseriesNoSqlJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/nosql/MqttAttributesNoSqlJsonIntegrationTest.java
@@ -13,11 +13,11 @@ | @@ -13,11 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes.nosql; | 16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries.nosql; |
17 | 17 | ||
18 | +import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesJsonIntegrationTest; | ||
18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; | 19 | import org.thingsboard.server.dao.service.DaoNoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.attributes.AbstractMqttAttributesJsonIntegrationTest; | ||
20 | 20 | ||
21 | @DaoNoSqlTest | 21 | @DaoNoSqlTest |
22 | -public class MqttAttributesNoSqlJsonIntegrationTest extends AbstractMqttAttributesJsonIntegrationTest { | 22 | +public class CoapTimeseriesNoSqlJsonIntegrationTest extends AbstractCoapTimeseriesJsonIntegrationTest { |
23 | } | 23 | } |
application/src/test/java/org/thingsboard/server/transport/coap/telemetry/timeseries/nosql/CoapTimeseriesNoSqlProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/claim/nosql/MqttClaimDeviceNoSqlTest.java
@@ -13,12 +13,11 @@ | @@ -13,12 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.claim.nosql; | 16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries.nosql; |
17 | 17 | ||
18 | +import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesProtoIntegrationTest; | ||
18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; | 19 | import org.thingsboard.server.dao.service.DaoNoSqlTest; |
19 | -import org.thingsboard.server.mqtt.claim.AbstractMqttClaimDeviceTest; | ||
20 | - | ||
21 | 20 | ||
22 | @DaoNoSqlTest | 21 | @DaoNoSqlTest |
23 | -public class MqttClaimDeviceNoSqlTest extends AbstractMqttClaimDeviceTest { | 22 | +public class CoapTimeseriesNoSqlProtoIntegrationTest extends AbstractCoapTimeseriesProtoIntegrationTest { |
24 | } | 23 | } |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +/** | ||
22 | + * Created by Valerii Sosliuk on 8/22/2017. | ||
23 | + */ | ||
24 | +@DaoSqlTest | ||
25 | +public class CoapTimeseriesSqlIntegrationTest extends AbstractCoapTimeseriesIntegrationTest { | ||
26 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesJsonIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +/** | ||
22 | + * Created by Valerii Sosliuk on 8/22/2017. | ||
23 | + */ | ||
24 | +@DaoSqlTest | ||
25 | +public class CoapTimeseriesSqlJsonIntegrationTest extends AbstractCoapTimeseriesJsonIntegrationTest { | ||
26 | +} |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.coap.telemetry.timeseries.sql; | ||
17 | + | ||
18 | +import org.thingsboard.server.transport.coap.telemetry.timeseries.AbstractCoapTimeseriesProtoIntegrationTest; | ||
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | ||
20 | + | ||
21 | +/** | ||
22 | + * Created by Valerii Sosliuk on 8/22/2017. | ||
23 | + */ | ||
24 | +@DaoSqlTest | ||
25 | +public class CoapTimeseriesSqlProtoIntegrationTest extends AbstractCoapTimeseriesProtoIntegrationTest { | ||
26 | +} |
application/src/test/java/org/thingsboard/server/transport/mqtt/AbstractMqttIntegrationTest.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.transport.mqtt; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.eclipse.paho.client.mqttv3.MqttAsyncClient; | ||
21 | +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; | ||
22 | +import org.eclipse.paho.client.mqttv3.MqttException; | ||
23 | +import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
24 | +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | ||
25 | +import org.junit.Assert; | ||
26 | +import org.springframework.util.StringUtils; | ||
27 | +import org.thingsboard.server.common.data.Device; | ||
28 | +import org.thingsboard.server.common.data.DeviceProfile; | ||
29 | +import org.thingsboard.server.common.data.DeviceProfileProvisionType; | ||
30 | +import org.thingsboard.server.common.data.DeviceProfileType; | ||
31 | +import org.thingsboard.server.common.data.DeviceTransportType; | ||
32 | +import org.thingsboard.server.common.data.Tenant; | ||
33 | +import org.thingsboard.server.common.data.TransportPayloadType; | ||
34 | +import org.thingsboard.server.common.data.User; | ||
35 | +import org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration; | ||
36 | +import org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration; | ||
37 | +import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration; | ||
38 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileData; | ||
39 | +import org.thingsboard.server.common.data.device.profile.DeviceProfileProvisionConfiguration; | ||
40 | +import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration; | ||
41 | +import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; | ||
42 | +import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; | ||
43 | +import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; | ||
44 | +import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; | ||
45 | +import org.thingsboard.server.common.data.security.Authority; | ||
46 | +import org.thingsboard.server.common.data.security.DeviceCredentials; | ||
47 | +import org.thingsboard.server.gen.transport.TransportProtos; | ||
48 | +import org.thingsboard.server.transport.AbstractTransportIntegrationTest; | ||
49 | + | ||
50 | +import java.util.List; | ||
51 | + | ||
52 | +import static org.junit.Assert.assertEquals; | ||
53 | +import static org.junit.Assert.assertNotNull; | ||
54 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
55 | + | ||
56 | +@Slf4j | ||
57 | +public abstract class AbstractMqttIntegrationTest extends AbstractTransportIntegrationTest { | ||
58 | + | ||
59 | + protected Device savedGateway; | ||
60 | + protected String gatewayAccessToken; | ||
61 | + | ||
62 | + protected DeviceProfile deviceProfile; | ||
63 | + | ||
64 | + protected void processBeforeTest (String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic) throws Exception { | ||
65 | + this.processBeforeTest(deviceName, gatewayName, payloadType, telemetryTopic, attributesTopic, null, null, DeviceProfileProvisionType.DISABLED, null, null); | ||
66 | + } | ||
67 | + | ||
68 | + protected void processBeforeTest(String deviceName, | ||
69 | + String gatewayName, | ||
70 | + TransportPayloadType payloadType, | ||
71 | + String telemetryTopic, | ||
72 | + String attributesTopic, | ||
73 | + String telemetryProtoSchema, | ||
74 | + String attributesProtoSchema, | ||
75 | + DeviceProfileProvisionType provisionType, | ||
76 | + String provisionKey, String provisionSecret | ||
77 | + ) throws Exception { | ||
78 | + loginSysAdmin(); | ||
79 | + | ||
80 | + Tenant tenant = new Tenant(); | ||
81 | + tenant.setTitle("My tenant"); | ||
82 | + savedTenant = doPost("/api/tenant", tenant, Tenant.class); | ||
83 | + Assert.assertNotNull(savedTenant); | ||
84 | + | ||
85 | + tenantAdmin = new User(); | ||
86 | + tenantAdmin.setAuthority(Authority.TENANT_ADMIN); | ||
87 | + tenantAdmin.setTenantId(savedTenant.getId()); | ||
88 | + tenantAdmin.setEmail("tenant" + atomicInteger.getAndIncrement() + "@thingsboard.org"); | ||
89 | + tenantAdmin.setFirstName("Joe"); | ||
90 | + tenantAdmin.setLastName("Downs"); | ||
91 | + | ||
92 | + tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); | ||
93 | + | ||
94 | + Device device = new Device(); | ||
95 | + device.setName(deviceName); | ||
96 | + device.setType("default"); | ||
97 | + | ||
98 | + Device gateway = new Device(); | ||
99 | + gateway.setName(gatewayName); | ||
100 | + gateway.setType("default"); | ||
101 | + ObjectNode additionalInfo = mapper.createObjectNode(); | ||
102 | + additionalInfo.put("gateway", true); | ||
103 | + gateway.setAdditionalInfo(additionalInfo); | ||
104 | + | ||
105 | + if (payloadType != null) { | ||
106 | + DeviceProfile mqttDeviceProfile = createMqttDeviceProfile(payloadType, telemetryTopic, attributesTopic, telemetryProtoSchema, attributesProtoSchema, provisionType, provisionKey, provisionSecret); | ||
107 | + deviceProfile = doPost("/api/deviceProfile", mqttDeviceProfile, DeviceProfile.class); | ||
108 | + device.setType(deviceProfile.getName()); | ||
109 | + device.setDeviceProfileId(deviceProfile.getId()); | ||
110 | + gateway.setType(deviceProfile.getName()); | ||
111 | + gateway.setDeviceProfileId(deviceProfile.getId()); | ||
112 | + } | ||
113 | + | ||
114 | + savedDevice = doPost("/api/device", device, Device.class); | ||
115 | + | ||
116 | + DeviceCredentials deviceCredentials = | ||
117 | + doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class); | ||
118 | + | ||
119 | + savedGateway = doPost("/api/device", gateway, Device.class); | ||
120 | + | ||
121 | + DeviceCredentials gatewayCredentials = | ||
122 | + doGet("/api/device/" + savedGateway.getId().getId().toString() + "/credentials", DeviceCredentials.class); | ||
123 | + | ||
124 | + assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId()); | ||
125 | + accessToken = deviceCredentials.getCredentialsId(); | ||
126 | + assertNotNull(accessToken); | ||
127 | + | ||
128 | + assertEquals(savedGateway.getId(), gatewayCredentials.getDeviceId()); | ||
129 | + gatewayAccessToken = gatewayCredentials.getCredentialsId(); | ||
130 | + assertNotNull(gatewayAccessToken); | ||
131 | + | ||
132 | + } | ||
133 | + | ||
134 | + protected void processAfterTest() throws Exception { | ||
135 | + loginSysAdmin(); | ||
136 | + if (savedTenant != null) { | ||
137 | + doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk()); | ||
138 | + } | ||
139 | + } | ||
140 | + | ||
141 | + protected MqttAsyncClient getMqttAsyncClient(String accessToken) throws MqttException { | ||
142 | + String clientId = MqttAsyncClient.generateClientId(); | ||
143 | + MqttAsyncClient client = new MqttAsyncClient(MQTT_URL, clientId, new MemoryPersistence()); | ||
144 | + | ||
145 | + MqttConnectOptions options = new MqttConnectOptions(); | ||
146 | + options.setUserName(accessToken); | ||
147 | + client.connect(options).waitForCompletion(); | ||
148 | + return client; | ||
149 | + } | ||
150 | + | ||
151 | + protected void publishMqttMsg(MqttAsyncClient client, byte[] payload, String topic) throws MqttException { | ||
152 | + MqttMessage message = new MqttMessage(); | ||
153 | + message.setPayload(payload); | ||
154 | + client.publish(topic, message); | ||
155 | + } | ||
156 | + | ||
157 | + protected DeviceProfile createMqttDeviceProfile(TransportPayloadType transportPayloadType, | ||
158 | + String telemetryTopic, String attributesTopic, | ||
159 | + String telemetryProtoSchema, String attributesProtoSchema, | ||
160 | + DeviceProfileProvisionType provisionType, | ||
161 | + String provisionKey, String provisionSecret) { | ||
162 | + DeviceProfile deviceProfile = new DeviceProfile(); | ||
163 | + deviceProfile.setName(transportPayloadType.name()); | ||
164 | + deviceProfile.setType(DeviceProfileType.DEFAULT); | ||
165 | + deviceProfile.setTransportType(DeviceTransportType.MQTT); | ||
166 | + deviceProfile.setProvisionType(provisionType); | ||
167 | + deviceProfile.setProvisionDeviceKey(provisionKey); | ||
168 | + deviceProfile.setDescription(transportPayloadType.name() + " Test"); | ||
169 | + DeviceProfileData deviceProfileData = new DeviceProfileData(); | ||
170 | + DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration(); | ||
171 | + MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = new MqttDeviceProfileTransportConfiguration(); | ||
172 | + if (!StringUtils.isEmpty(telemetryTopic)) { | ||
173 | + mqttDeviceProfileTransportConfiguration.setDeviceTelemetryTopic(telemetryTopic); | ||
174 | + } | ||
175 | + if (!StringUtils.isEmpty(attributesTopic)) { | ||
176 | + mqttDeviceProfileTransportConfiguration.setDeviceAttributesTopic(attributesTopic); | ||
177 | + } | ||
178 | + TransportPayloadTypeConfiguration transportPayloadTypeConfiguration; | ||
179 | + if (TransportPayloadType.JSON.equals(transportPayloadType)) { | ||
180 | + transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration(); | ||
181 | + } else { | ||
182 | + ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration(); | ||
183 | + if (StringUtils.isEmpty(telemetryProtoSchema)) { | ||
184 | + telemetryProtoSchema = DEVICE_TELEMETRY_PROTO_SCHEMA; | ||
185 | + } | ||
186 | + if (StringUtils.isEmpty(attributesProtoSchema)) { | ||
187 | + attributesProtoSchema = DEVICE_ATTRIBUTES_PROTO_SCHEMA; | ||
188 | + } | ||
189 | + protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema); | ||
190 | + protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema); | ||
191 | + transportPayloadTypeConfiguration = protoTransportPayloadConfiguration; | ||
192 | + } | ||
193 | + mqttDeviceProfileTransportConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration); | ||
194 | + deviceProfileData.setTransportConfiguration(mqttDeviceProfileTransportConfiguration); | ||
195 | + DeviceProfileProvisionConfiguration provisionConfiguration; | ||
196 | + switch (provisionType) { | ||
197 | + case ALLOW_CREATE_NEW_DEVICES: | ||
198 | + provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(provisionSecret); | ||
199 | + break; | ||
200 | + case CHECK_PRE_PROVISIONED_DEVICES: | ||
201 | + provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(provisionSecret); | ||
202 | + break; | ||
203 | + case DISABLED: | ||
204 | + default: | ||
205 | + provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(provisionSecret); | ||
206 | + break; | ||
207 | + } | ||
208 | + deviceProfileData.setProvisionConfiguration(provisionConfiguration); | ||
209 | + deviceProfileData.setConfiguration(configuration); | ||
210 | + deviceProfile.setProfileData(deviceProfileData); | ||
211 | + deviceProfile.setDefault(false); | ||
212 | + deviceProfile.setDefaultRuleChainId(null); | ||
213 | + return deviceProfile; | ||
214 | + } | ||
215 | + | ||
216 | + protected TransportProtos.PostAttributeMsg getPostAttributeMsg(List<String> expectedKeys) { | ||
217 | + List<TransportProtos.KeyValueProto> kvProtos = getKvProtos(expectedKeys); | ||
218 | + TransportProtos.PostAttributeMsg.Builder builder = TransportProtos.PostAttributeMsg.newBuilder(); | ||
219 | + builder.addAllKv(kvProtos); | ||
220 | + return builder.build(); | ||
221 | + } | ||
222 | +} |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/AbstractMqttAttributesIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/AbstractMqttAttributesIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes; | 16 | +package org.thingsboard.server.transport.mqtt.attributes; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; | 19 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; |
@@ -21,7 +21,7 @@ import org.eclipse.paho.client.mqttv3.MqttCallback; | @@ -21,7 +21,7 @@ import org.eclipse.paho.client.mqttv3.MqttCallback; | ||
21 | import org.eclipse.paho.client.mqttv3.MqttMessage; | 21 | import org.eclipse.paho.client.mqttv3.MqttMessage; |
22 | import org.thingsboard.server.common.data.TransportPayloadType; | 22 | import org.thingsboard.server.common.data.TransportPayloadType; |
23 | import org.thingsboard.server.gen.transport.TransportProtos; | 23 | import org.thingsboard.server.gen.transport.TransportProtos; |
24 | -import org.thingsboard.server.mqtt.AbstractMqttIntegrationTest; | 24 | +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; |
25 | 25 | ||
26 | import java.util.ArrayList; | 26 | import java.util.ArrayList; |
27 | import java.util.List; | 27 | import java.util.List; |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/AbstractMqttAttributesRequestIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/request/AbstractMqttAttributesRequestIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.request; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.request; |
17 | 17 | ||
18 | import com.google.protobuf.InvalidProtocolBufferException; | 18 | import com.google.protobuf.InvalidProtocolBufferException; |
19 | import io.netty.handler.codec.mqtt.MqttQoS; | 19 | import io.netty.handler.codec.mqtt.MqttQoS; |
@@ -27,7 +27,7 @@ import org.junit.Test; | @@ -27,7 +27,7 @@ import org.junit.Test; | ||
27 | import org.thingsboard.server.common.data.Device; | 27 | import org.thingsboard.server.common.data.Device; |
28 | import org.thingsboard.server.common.data.device.profile.MqttTopics; | 28 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
29 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; | 29 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
30 | -import org.thingsboard.server.mqtt.attributes.AbstractMqttAttributesIntegrationTest; | 30 | +import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; |
31 | 31 | ||
32 | import java.nio.charset.StandardCharsets; | 32 | import java.nio.charset.StandardCharsets; |
33 | import java.util.concurrent.CountDownLatch; | 33 | import java.util.concurrent.CountDownLatch; |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/AbstractMqttAttributesRequestJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/request/AbstractMqttAttributesRequestJsonIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.request; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.request; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.junit.After; | 19 | import org.junit.After; |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/AbstractMqttAttributesRequestProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/request/AbstractMqttAttributesRequestProtoIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.request; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.request; |
17 | 17 | ||
18 | import com.github.os72.protobuf.dynamic.DynamicSchema; | 18 | import com.github.os72.protobuf.dynamic.DynamicSchema; |
19 | import com.google.protobuf.Descriptors; | 19 | import com.google.protobuf.Descriptors; |
@@ -37,6 +37,7 @@ import org.thingsboard.server.common.data.device.profile.MqttTopics; | @@ -37,6 +37,7 @@ import org.thingsboard.server.common.data.device.profile.MqttTopics; | ||
37 | import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; | 37 | import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; |
38 | import org.thingsboard.server.gen.transport.TransportApiProtos; | 38 | import org.thingsboard.server.gen.transport.TransportApiProtos; |
39 | import org.thingsboard.server.gen.transport.TransportProtos; | 39 | import org.thingsboard.server.gen.transport.TransportProtos; |
40 | +import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; | ||
40 | 41 | ||
41 | import java.util.ArrayList; | 42 | import java.util.ArrayList; |
42 | import java.util.Arrays; | 43 | import java.util.Arrays; |
@@ -93,7 +94,7 @@ public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends | @@ -93,7 +94,7 @@ public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends | ||
93 | } | 94 | } |
94 | 95 | ||
95 | protected void postAttributesAndSubscribeToTopic(Device savedDevice, MqttAsyncClient client) throws Exception { | 96 | protected void postAttributesAndSubscribeToTopic(Device savedDevice, MqttAsyncClient client) throws Exception { |
96 | - doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD, String.class, status().isOk()); | 97 | + doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", AbstractMqttAttributesIntegrationTest.POST_ATTRIBUTES_PAYLOAD, String.class, status().isOk()); |
97 | DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); | 98 | DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration(); |
98 | assertTrue(transportConfiguration instanceof MqttDeviceProfileTransportConfiguration); | 99 | assertTrue(transportConfiguration instanceof MqttDeviceProfileTransportConfiguration); |
99 | MqttDeviceProfileTransportConfiguration mqttTransportConfiguration = (MqttDeviceProfileTransportConfiguration) transportConfiguration; | 100 | MqttDeviceProfileTransportConfiguration mqttTransportConfiguration = (MqttDeviceProfileTransportConfiguration) transportConfiguration; |
@@ -148,7 +149,7 @@ public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends | @@ -148,7 +149,7 @@ public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends | ||
148 | client.publish(MqttTopics.GATEWAY_ATTRIBUTES_TOPIC, new MqttMessage(bytes)); | 149 | client.publish(MqttTopics.GATEWAY_ATTRIBUTES_TOPIC, new MqttMessage(bytes)); |
149 | } | 150 | } |
150 | 151 | ||
151 | - protected void validateResponse(MqttAsyncClient client, CountDownLatch latch, TestMqttCallback callback) throws MqttException, InterruptedException, InvalidProtocolBufferException { | 152 | + protected void validateResponse(MqttAsyncClient client, CountDownLatch latch, AbstractMqttAttributesIntegrationTest.TestMqttCallback callback) throws MqttException, InterruptedException, InvalidProtocolBufferException { |
152 | String keys = "attribute1,attribute2,attribute3,attribute4,attribute5"; | 153 | String keys = "attribute1,attribute2,attribute3,attribute4,attribute5"; |
153 | TransportApiProtos.AttributesRequest.Builder attributesRequestBuilder = TransportApiProtos.AttributesRequest.newBuilder(); | 154 | TransportApiProtos.AttributesRequest.Builder attributesRequestBuilder = TransportApiProtos.AttributesRequest.newBuilder(); |
154 | attributesRequestBuilder.setClientKeys(keys); | 155 | attributesRequestBuilder.setClientKeys(keys); |
@@ -170,7 +171,7 @@ public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends | @@ -170,7 +171,7 @@ public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends | ||
170 | assertTrue(actualSharedKeyValueProtos.containsAll(expectedSharedKeyValueProtos)); | 171 | assertTrue(actualSharedKeyValueProtos.containsAll(expectedSharedKeyValueProtos)); |
171 | } | 172 | } |
172 | 173 | ||
173 | - protected void validateClientResponseGateway(MqttAsyncClient client, TestMqttCallback callback) throws MqttException, InterruptedException, InvalidProtocolBufferException { | 174 | + protected void validateClientResponseGateway(MqttAsyncClient client, AbstractMqttAttributesIntegrationTest.TestMqttCallback callback) throws MqttException, InterruptedException, InvalidProtocolBufferException { |
174 | String keys = "attribute1,attribute2,attribute3,attribute4,attribute5"; | 175 | String keys = "attribute1,attribute2,attribute3,attribute4,attribute5"; |
175 | TransportApiProtos.GatewayAttributesRequestMsg gatewayAttributesRequestMsg = getGatewayAttributesRequestMsg(keys, true); | 176 | TransportApiProtos.GatewayAttributesRequestMsg gatewayAttributesRequestMsg = getGatewayAttributesRequestMsg(keys, true); |
176 | client.publish(MqttTopics.GATEWAY_ATTRIBUTES_REQUEST_TOPIC, new MqttMessage(gatewayAttributesRequestMsg.toByteArray())); | 177 | client.publish(MqttTopics.GATEWAY_ATTRIBUTES_REQUEST_TOPIC, new MqttMessage(gatewayAttributesRequestMsg.toByteArray())); |
@@ -189,7 +190,7 @@ public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends | @@ -189,7 +190,7 @@ public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends | ||
189 | assertTrue(actualClientKeyValueProtos.containsAll(expectedClientKeyValueProtos)); | 190 | assertTrue(actualClientKeyValueProtos.containsAll(expectedClientKeyValueProtos)); |
190 | } | 191 | } |
191 | 192 | ||
192 | - protected void validateSharedResponseGateway(MqttAsyncClient client, TestMqttCallback callback) throws MqttException, InterruptedException, InvalidProtocolBufferException { | 193 | + protected void validateSharedResponseGateway(MqttAsyncClient client, AbstractMqttAttributesIntegrationTest.TestMqttCallback callback) throws MqttException, InterruptedException, InvalidProtocolBufferException { |
193 | String keys = "attribute1,attribute2,attribute3,attribute4,attribute5"; | 194 | String keys = "attribute1,attribute2,attribute3,attribute4,attribute5"; |
194 | TransportApiProtos.GatewayAttributesRequestMsg gatewayAttributesRequestMsg = getGatewayAttributesRequestMsg(keys, false); | 195 | TransportApiProtos.GatewayAttributesRequestMsg gatewayAttributesRequestMsg = getGatewayAttributesRequestMsg(keys, false); |
195 | client.publish(MqttTopics.GATEWAY_ATTRIBUTES_REQUEST_TOPIC, new MqttMessage(gatewayAttributesRequestMsg.toByteArray())); | 196 | client.publish(MqttTopics.GATEWAY_ATTRIBUTES_REQUEST_TOPIC, new MqttMessage(gatewayAttributesRequestMsg.toByteArray())); |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/sql/MqttAttributesRequestJsonSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/request/sql/MqttAttributesRequestJsonSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.request.sql; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.request.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.attributes.request.AbstractMqttAttributesRequestJsonIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.attributes.request.AbstractMqttAttributesRequestJsonIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesRequestJsonSqlIntegrationTest extends AbstractMqttAttributesRequestJsonIntegrationTest { | 22 | public class MqttAttributesRequestJsonSqlIntegrationTest extends AbstractMqttAttributesRequestJsonIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/sql/MqttAttributesRequestProtoSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/request/sql/MqttAttributesRequestProtoSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.request.sql; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.request.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.attributes.request.AbstractMqttAttributesRequestProtoIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.attributes.request.AbstractMqttAttributesRequestProtoIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesRequestProtoSqlIntegrationTest extends AbstractMqttAttributesRequestProtoIntegrationTest { | 22 | public class MqttAttributesRequestProtoSqlIntegrationTest extends AbstractMqttAttributesRequestProtoIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/sql/MqttAttributesRequestSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/request/sql/MqttAttributesRequestSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.request.sql; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.request.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.attributes.request.AbstractMqttAttributesRequestIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.attributes.request.AbstractMqttAttributesRequestIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesRequestSqlIntegrationTest extends AbstractMqttAttributesRequestIntegrationTest { | 22 | public class MqttAttributesRequestSqlIntegrationTest extends AbstractMqttAttributesRequestIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/AbstractMqttAttributesUpdatesIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/updates/AbstractMqttAttributesUpdatesIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.updates; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.updates; |
17 | 17 | ||
18 | import com.google.protobuf.InvalidProtocolBufferException; | 18 | import com.google.protobuf.InvalidProtocolBufferException; |
19 | import io.netty.handler.codec.mqtt.MqttQoS; | 19 | import io.netty.handler.codec.mqtt.MqttQoS; |
@@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.Device; | @@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.Device; | ||
26 | import org.thingsboard.server.common.data.TransportPayloadType; | 26 | import org.thingsboard.server.common.data.TransportPayloadType; |
27 | import org.thingsboard.server.common.data.device.profile.MqttTopics; | 27 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
28 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; | 28 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
29 | -import org.thingsboard.server.mqtt.attributes.AbstractMqttAttributesIntegrationTest; | 29 | +import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; |
30 | 30 | ||
31 | import java.nio.charset.StandardCharsets; | 31 | import java.nio.charset.StandardCharsets; |
32 | import java.util.concurrent.TimeUnit; | 32 | import java.util.concurrent.TimeUnit; |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/AbstractMqttAttributesUpdatesJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/updates/AbstractMqttAttributesUpdatesJsonIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.updates; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.updates; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.junit.After; | 19 | import org.junit.After; |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/AbstractMqttAttributesUpdatesProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/updates/AbstractMqttAttributesUpdatesProtoIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.updates; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.updates; |
17 | 17 | ||
18 | import com.google.protobuf.InvalidProtocolBufferException; | 18 | import com.google.protobuf.InvalidProtocolBufferException; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/sql/MqttAttributesUpdatesSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/updates/sql/MqttAttributesUpdatesSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.updates.sql; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.updates.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.attributes.updates.AbstractMqttAttributesUpdatesIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.attributes.updates.AbstractMqttAttributesUpdatesIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesUpdatesSqlIntegrationTest extends AbstractMqttAttributesUpdatesIntegrationTest { | 22 | public class MqttAttributesUpdatesSqlIntegrationTest extends AbstractMqttAttributesUpdatesIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/sql/MqttAttributesUpdatesSqlJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/updates/sql/MqttAttributesUpdatesSqlJsonIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.updates.sql; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.updates.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.attributes.updates.AbstractMqttAttributesUpdatesJsonIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.attributes.updates.AbstractMqttAttributesUpdatesJsonIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesUpdatesSqlJsonIntegrationTest extends AbstractMqttAttributesUpdatesJsonIntegrationTest { | 22 | public class MqttAttributesUpdatesSqlJsonIntegrationTest extends AbstractMqttAttributesUpdatesJsonIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/sql/MqttAttributesUpdatesSqlProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/updates/sql/MqttAttributesUpdatesSqlProtoIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.updates.sql; | 16 | +package org.thingsboard.server.transport.mqtt.attributes.updates.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.attributes.updates.AbstractMqttAttributesUpdatesProtoIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.attributes.updates.AbstractMqttAttributesUpdatesProtoIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesUpdatesSqlProtoIntegrationTest extends AbstractMqttAttributesUpdatesProtoIntegrationTest { | 22 | public class MqttAttributesUpdatesSqlProtoIntegrationTest extends AbstractMqttAttributesUpdatesProtoIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/claim/AbstractMqttClaimDeviceTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/claim/AbstractMqttClaimDeviceTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.claim; | 16 | +package org.thingsboard.server.transport.mqtt.claim; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; | 19 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; |
@@ -29,7 +29,7 @@ import org.thingsboard.server.common.data.device.profile.MqttTopics; | @@ -29,7 +29,7 @@ import org.thingsboard.server.common.data.device.profile.MqttTopics; | ||
29 | import org.thingsboard.server.common.data.security.Authority; | 29 | import org.thingsboard.server.common.data.security.Authority; |
30 | import org.thingsboard.server.dao.device.claim.ClaimResponse; | 30 | import org.thingsboard.server.dao.device.claim.ClaimResponse; |
31 | import org.thingsboard.server.dao.device.claim.ClaimResult; | 31 | import org.thingsboard.server.dao.device.claim.ClaimResult; |
32 | -import org.thingsboard.server.mqtt.AbstractMqttIntegrationTest; | 32 | +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; |
33 | 33 | ||
34 | import static org.junit.Assert.assertEquals; | 34 | import static org.junit.Assert.assertEquals; |
35 | import static org.junit.Assert.assertNotNull; | 35 | import static org.junit.Assert.assertNotNull; |
application/src/test/java/org/thingsboard/server/transport/mqtt/claim/AbstractMqttClaimJsonDeviceTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/claim/AbstractMqttClaimJsonDeviceTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.claim; | 16 | +package org.thingsboard.server.transport.mqtt.claim; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.junit.After; | 19 | import org.junit.After; |
application/src/test/java/org/thingsboard/server/transport/mqtt/claim/AbstractMqttClaimProtoDeviceTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/claim/AbstractMqttClaimProtoDeviceTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.claim; | 16 | +package org.thingsboard.server.transport.mqtt.claim; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; | 19 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; |
application/src/test/java/org/thingsboard/server/transport/mqtt/claim/sql/MqttClaimDeviceJsonSqlTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/claim/sql/MqttClaimDeviceJsonSqlTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.claim.sql; | 16 | +package org.thingsboard.server.transport.mqtt.claim.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.claim.AbstractMqttClaimJsonDeviceTest; | 19 | +import org.thingsboard.server.transport.mqtt.claim.AbstractMqttClaimJsonDeviceTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttClaimDeviceJsonSqlTest extends AbstractMqttClaimJsonDeviceTest { | 22 | public class MqttClaimDeviceJsonSqlTest extends AbstractMqttClaimJsonDeviceTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/claim/sql/MqttClaimDeviceProtoSqlTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/claim/sql/MqttClaimDeviceProtoSqlTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.claim.sql; | 16 | +package org.thingsboard.server.transport.mqtt.claim.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.claim.AbstractMqttClaimProtoDeviceTest; | 19 | +import org.thingsboard.server.transport.mqtt.claim.AbstractMqttClaimProtoDeviceTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttClaimDeviceProtoSqlTest extends AbstractMqttClaimProtoDeviceTest { | 22 | public class MqttClaimDeviceProtoSqlTest extends AbstractMqttClaimProtoDeviceTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/claim/sql/MqttClaimDeviceSqlTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/claim/sql/MqttClaimDeviceSqlTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.claim.sql; | 16 | +package org.thingsboard.server.transport.mqtt.claim.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.claim.AbstractMqttClaimDeviceTest; | 19 | +import org.thingsboard.server.transport.mqtt.claim.AbstractMqttClaimDeviceTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttClaimDeviceSqlTest extends AbstractMqttClaimDeviceTest { | 22 | public class MqttClaimDeviceSqlTest extends AbstractMqttClaimDeviceTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/provision/AbstractMqttProvisionJsonDeviceTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/provision/AbstractMqttProvisionJsonDeviceTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.provision; | 16 | +package org.thingsboard.server.transport.mqtt.provision; |
17 | 17 | ||
18 | import com.google.gson.JsonObject; | 18 | import com.google.gson.JsonObject; |
19 | import io.netty.handler.codec.mqtt.MqttQoS; | 19 | import io.netty.handler.codec.mqtt.MqttQoS; |
@@ -38,7 +38,7 @@ import org.thingsboard.server.dao.device.DeviceCredentialsService; | @@ -38,7 +38,7 @@ import org.thingsboard.server.dao.device.DeviceCredentialsService; | ||
38 | import org.thingsboard.server.dao.device.DeviceService; | 38 | import org.thingsboard.server.dao.device.DeviceService; |
39 | import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; | 39 | import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; |
40 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; | 40 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
41 | -import org.thingsboard.server.mqtt.AbstractMqttIntegrationTest; | 41 | +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; |
42 | 42 | ||
43 | import java.util.concurrent.CountDownLatch; | 43 | import java.util.concurrent.CountDownLatch; |
44 | import java.util.concurrent.TimeUnit; | 44 | import java.util.concurrent.TimeUnit; |
application/src/test/java/org/thingsboard/server/transport/mqtt/provision/AbstractMqttProvisionProtoDeviceTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/provision/AbstractMqttProvisionProtoDeviceTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.provision; | 16 | +package org.thingsboard.server.transport.mqtt.provision; |
17 | 17 | ||
18 | import io.netty.handler.codec.mqtt.MqttQoS; | 18 | import io.netty.handler.codec.mqtt.MqttQoS; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
@@ -45,9 +45,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceRespo | @@ -45,9 +45,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceRespo | ||
45 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateBasicMqttCredRequestMsg; | 45 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateBasicMqttCredRequestMsg; |
46 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg; | 46 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg; |
47 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg; | 47 | import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg; |
48 | -import org.thingsboard.server.mqtt.AbstractMqttIntegrationTest; | 48 | +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; |
49 | 49 | ||
50 | -import java.util.UUID; | ||
51 | import java.util.concurrent.CountDownLatch; | 50 | import java.util.concurrent.CountDownLatch; |
52 | import java.util.concurrent.TimeUnit; | 51 | import java.util.concurrent.TimeUnit; |
53 | 52 |
application/src/test/java/org/thingsboard/server/transport/mqtt/provision/sql/MqttProvisionDeviceJsonSqlTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/provision/sql/MqttProvisionDeviceJsonSqlTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.provision.sql; | 16 | +package org.thingsboard.server.transport.mqtt.provision.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.provision.AbstractMqttProvisionJsonDeviceTest; | 19 | +import org.thingsboard.server.transport.mqtt.provision.AbstractMqttProvisionJsonDeviceTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttProvisionDeviceJsonSqlTest extends AbstractMqttProvisionJsonDeviceTest { | 22 | public class MqttProvisionDeviceJsonSqlTest extends AbstractMqttProvisionJsonDeviceTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/provision/sql/MqttProvisionDeviceProtoSqlTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/provision/sql/MqttProvisionDeviceProtoSqlTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.provision.sql; | 16 | +package org.thingsboard.server.transport.mqtt.provision.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.provision.AbstractMqttProvisionProtoDeviceTest; | 19 | +import org.thingsboard.server.transport.mqtt.provision.AbstractMqttProvisionProtoDeviceTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttProvisionDeviceProtoSqlTest extends AbstractMqttProvisionProtoDeviceTest { | 22 | public class MqttProvisionDeviceProtoSqlTest extends AbstractMqttProvisionProtoDeviceTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/AbstractMqttServerSideRpcDefaultIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/rpc/AbstractMqttServerSideRpcDefaultIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.rpc; | 16 | +package org.thingsboard.server.transport.mqtt.rpc; |
17 | 17 | ||
18 | import com.datastax.oss.driver.api.core.uuid.Uuids; | 18 | import com.datastax.oss.driver.api.core.uuid.Uuids; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/AbstractMqttServerSideRpcIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/rpc/AbstractMqttServerSideRpcIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.rpc; | 16 | +package org.thingsboard.server.transport.mqtt.rpc; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.google.protobuf.InvalidProtocolBufferException; | 19 | import com.google.protobuf.InvalidProtocolBufferException; |
@@ -31,7 +31,7 @@ import org.thingsboard.server.common.data.Device; | @@ -31,7 +31,7 @@ import org.thingsboard.server.common.data.Device; | ||
31 | import org.thingsboard.server.common.data.TransportPayloadType; | 31 | import org.thingsboard.server.common.data.TransportPayloadType; |
32 | import org.thingsboard.server.common.data.device.profile.MqttTopics; | 32 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
33 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; | 33 | import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
34 | -import org.thingsboard.server.mqtt.AbstractMqttIntegrationTest; | 34 | +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; |
35 | 35 | ||
36 | import java.util.Arrays; | 36 | import java.util.Arrays; |
37 | import java.util.concurrent.CountDownLatch; | 37 | import java.util.concurrent.CountDownLatch; |
application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/AbstractMqttServerSideRpcJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/rpc/AbstractMqttServerSideRpcJsonIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.rpc; | 16 | +package org.thingsboard.server.transport.mqtt.rpc; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; | 19 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; |
application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/AbstractMqttServerSideRpcProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/rpc/AbstractMqttServerSideRpcProtoIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.rpc; | 16 | +package org.thingsboard.server.transport.mqtt.rpc; |
17 | 17 | ||
18 | import com.google.protobuf.InvalidProtocolBufferException; | 18 | import com.google.protobuf.InvalidProtocolBufferException; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/sql/MqttServerSideRpcJsonSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/rpc/sql/MqttServerSideRpcJsonSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.rpc.sql; | 16 | +package org.thingsboard.server.transport.mqtt.rpc.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.rpc.AbstractMqttServerSideRpcJsonIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.rpc.AbstractMqttServerSideRpcJsonIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttServerSideRpcJsonSqlIntegrationTest extends AbstractMqttServerSideRpcJsonIntegrationTest { | 22 | public class MqttServerSideRpcJsonSqlIntegrationTest extends AbstractMqttServerSideRpcJsonIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/sql/MqttServerSideRpcProtoSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/rpc/sql/MqttServerSideRpcProtoSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.rpc.sql; | 16 | +package org.thingsboard.server.transport.mqtt.rpc.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.rpc.AbstractMqttServerSideRpcProtoIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.rpc.AbstractMqttServerSideRpcProtoIntegrationTest; |
20 | 20 | ||
21 | 21 | ||
22 | @DaoSqlTest | 22 | @DaoSqlTest |
application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/sql/MqttServerSideRpcSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/rpc/sql/MqttServerSideRpcSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.rpc.sql; | 16 | +package org.thingsboard.server.transport.mqtt.rpc.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.rpc.AbstractMqttServerSideRpcDefaultIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.rpc.AbstractMqttServerSideRpcDefaultIntegrationTest; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Created by Valerii Sosliuk on 8/22/2017. | 22 | * Created by Valerii Sosliuk on 8/22/2017. |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/AbstractMqttAttributesIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.attributes; |
17 | 17 | ||
18 | import com.fasterxml.jackson.core.JsonProcessingException; | 18 | import com.fasterxml.jackson.core.JsonProcessingException; |
19 | import com.fasterxml.jackson.core.type.TypeReference; | 19 | import com.fasterxml.jackson.core.type.TypeReference; |
@@ -25,7 +25,7 @@ import org.junit.Test; | @@ -25,7 +25,7 @@ import org.junit.Test; | ||
25 | import org.thingsboard.server.common.data.Device; | 25 | import org.thingsboard.server.common.data.Device; |
26 | import org.thingsboard.server.common.data.device.profile.MqttTopics; | 26 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
27 | import org.thingsboard.server.common.data.id.DeviceId; | 27 | import org.thingsboard.server.common.data.id.DeviceId; |
28 | -import org.thingsboard.server.mqtt.AbstractMqttIntegrationTest; | 28 | +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; |
29 | 29 | ||
30 | import java.util.Arrays; | 30 | import java.util.Arrays; |
31 | import java.util.HashSet; | 31 | import java.util.HashSet; |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/AbstractMqttAttributesJsonIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.attributes; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.junit.After; | 19 | import org.junit.After; |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/AbstractMqttAttributesProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/AbstractMqttAttributesProtoIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.attributes; |
17 | 17 | ||
18 | import com.github.os72.protobuf.dynamic.DynamicSchema; | 18 | import com.github.os72.protobuf.dynamic.DynamicSchema; |
19 | import com.google.protobuf.Descriptors; | 19 | import com.google.protobuf.Descriptors; |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/sql/MqttAttributesSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/sql/MqttAttributesSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes.sql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.attributes.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.attributes.AbstractMqttAttributesIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.attributes.AbstractMqttAttributesIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesSqlIntegrationTest extends AbstractMqttAttributesIntegrationTest { | 22 | public class MqttAttributesSqlIntegrationTest extends AbstractMqttAttributesIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/sql/MqttAttributesSqlJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/sql/MqttAttributesSqlJsonIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes.sql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.attributes.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.attributes.AbstractMqttAttributesJsonIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.attributes.AbstractMqttAttributesJsonIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesSqlJsonIntegrationTest extends AbstractMqttAttributesJsonIntegrationTest { | 22 | public class MqttAttributesSqlJsonIntegrationTest extends AbstractMqttAttributesJsonIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/sql/MqttAttributesSqlProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/attributes/sql/MqttAttributesSqlProtoIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.attributes.sql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.attributes.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.attributes.AbstractMqttAttributesProtoIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.attributes.AbstractMqttAttributesProtoIntegrationTest; |
20 | 20 | ||
21 | @DaoSqlTest | 21 | @DaoSqlTest |
22 | public class MqttAttributesSqlProtoIntegrationTest extends AbstractMqttAttributesProtoIntegrationTest { | 22 | public class MqttAttributesSqlProtoIntegrationTest extends AbstractMqttAttributesProtoIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries; |
17 | 17 | ||
18 | import com.fasterxml.jackson.core.type.TypeReference; | 18 | import com.fasterxml.jackson.core.type.TypeReference; |
19 | import io.netty.handler.codec.mqtt.MqttQoS; | 19 | import io.netty.handler.codec.mqtt.MqttQoS; |
@@ -26,12 +26,11 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; | @@ -26,12 +26,11 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
26 | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | 26 | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
27 | import org.junit.After; | 27 | import org.junit.After; |
28 | import org.junit.Before; | 28 | import org.junit.Before; |
29 | -import org.junit.Ignore; | ||
30 | import org.junit.Test; | 29 | import org.junit.Test; |
31 | import org.thingsboard.server.common.data.Device; | 30 | import org.thingsboard.server.common.data.Device; |
32 | import org.thingsboard.server.common.data.device.profile.MqttTopics; | 31 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
33 | import org.thingsboard.server.common.data.id.DeviceId; | 32 | import org.thingsboard.server.common.data.id.DeviceId; |
34 | -import org.thingsboard.server.mqtt.AbstractMqttIntegrationTest; | 33 | +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; |
35 | 34 | ||
36 | import java.util.Arrays; | 35 | import java.util.Arrays; |
37 | import java.util.HashSet; | 36 | import java.util.HashSet; |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; | 19 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries; |
17 | 17 | ||
18 | import com.github.os72.protobuf.dynamic.DynamicSchema; | 18 | import com.github.os72.protobuf.dynamic.DynamicSchema; |
19 | import com.google.protobuf.Descriptors; | 19 | import com.google.protobuf.Descriptors; |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries.nosql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries.nosql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Created by Valerii Sosliuk on 8/22/2017. | 22 | * Created by Valerii Sosliuk on 8/22/2017. |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries.nosql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries.nosql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest; |
20 | 20 | ||
21 | @DaoNoSqlTest | 21 | @DaoNoSqlTest |
22 | public class MqttTimeseriesNoSqlJsonIntegrationTest extends AbstractMqttTimeseriesJsonIntegrationTest { | 22 | public class MqttTimeseriesNoSqlJsonIntegrationTest extends AbstractMqttTimeseriesJsonIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries.nosql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries.nosql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoNoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest; |
20 | 20 | ||
21 | @DaoNoSqlTest | 21 | @DaoNoSqlTest |
22 | public class MqttTimeseriesNoSqlProtoIntegrationTest extends AbstractMqttTimeseriesProtoIntegrationTest { | 22 | public class MqttTimeseriesNoSqlProtoIntegrationTest extends AbstractMqttTimeseriesProtoIntegrationTest { |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries.sql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Created by Valerii Sosliuk on 8/22/2017. | 22 | * Created by Valerii Sosliuk on 8/22/2017. |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries.sql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Created by Valerii Sosliuk on 8/22/2017. | 22 | * Created by Valerii Sosliuk on 8/22/2017. |
application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java
@@ -13,10 +13,10 @@ | @@ -13,10 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.telemetry.timeseries.sql; | 16 | +package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql; |
17 | 17 | ||
18 | import org.thingsboard.server.dao.service.DaoSqlTest; | 18 | import org.thingsboard.server.dao.service.DaoSqlTest; |
19 | -import org.thingsboard.server.mqtt.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest; | 19 | +import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Created by Valerii Sosliuk on 8/22/2017. | 22 | * Created by Valerii Sosliuk on 8/22/2017. |
common/data/src/main/java/org/thingsboard/server/common/data/CoapDeviceType.java
renamed from
application/src/test/java/org/thingsboard/server/mqtt/attributes/request/nosql/MqttAttributesRequestNoSqlIntegrationTest.java
@@ -13,12 +13,9 @@ | @@ -13,12 +13,9 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.mqtt.attributes.request.nosql; | 16 | +package org.thingsboard.server.common.data; |
17 | 17 | ||
18 | -import org.thingsboard.server.dao.service.DaoNoSqlTest; | ||
19 | -import org.thingsboard.server.mqtt.attributes.request.AbstractMqttAttributesRequestIntegrationTest; | ||
20 | - | ||
21 | - | ||
22 | -@DaoNoSqlTest | ||
23 | -public class MqttAttributesRequestNoSqlIntegrationTest extends AbstractMqttAttributesRequestIntegrationTest { | 18 | +public enum CoapDeviceType { |
19 | + DEFAULT, | ||
20 | + EFENTO | ||
24 | } | 21 | } |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.common.data.device.data; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
19 | +import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
20 | +import com.fasterxml.jackson.annotation.JsonIgnore; | ||
21 | +import lombok.Data; | ||
22 | +import org.thingsboard.server.common.data.DeviceTransportType; | ||
23 | + | ||
24 | +import java.util.HashMap; | ||
25 | +import java.util.Map; | ||
26 | + | ||
27 | +@Data | ||
28 | +public class CoapDeviceTransportConfiguration implements DeviceTransportConfiguration { | ||
29 | + | ||
30 | + @JsonIgnore | ||
31 | + private Map<String, Object> properties = new HashMap<>(); | ||
32 | + | ||
33 | + @JsonAnyGetter | ||
34 | + public Map<String, Object> properties() { | ||
35 | + return this.properties; | ||
36 | + } | ||
37 | + | ||
38 | + @JsonAnySetter | ||
39 | + public void put(String name, Object value) { | ||
40 | + this.properties.put(name, value); | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public DeviceTransportType getType() { | ||
45 | + return DeviceTransportType.COAP; | ||
46 | + } | ||
47 | + | ||
48 | +} |
@@ -29,7 +29,8 @@ import org.thingsboard.server.common.data.DeviceTransportType; | @@ -29,7 +29,8 @@ import org.thingsboard.server.common.data.DeviceTransportType; | ||
29 | @JsonSubTypes({ | 29 | @JsonSubTypes({ |
30 | @JsonSubTypes.Type(value = DefaultDeviceTransportConfiguration.class, name = "DEFAULT"), | 30 | @JsonSubTypes.Type(value = DefaultDeviceTransportConfiguration.class, name = "DEFAULT"), |
31 | @JsonSubTypes.Type(value = MqttDeviceTransportConfiguration.class, name = "MQTT"), | 31 | @JsonSubTypes.Type(value = MqttDeviceTransportConfiguration.class, name = "MQTT"), |
32 | - @JsonSubTypes.Type(value = Lwm2mDeviceTransportConfiguration.class, name = "LWM2M")}) | 32 | + @JsonSubTypes.Type(value = Lwm2mDeviceTransportConfiguration.class, name = "LWM2M"), |
33 | + @JsonSubTypes.Type(value = CoapDeviceTransportConfiguration.class, name = "COAP")}) | ||
33 | public interface DeviceTransportConfiguration { | 34 | public interface DeviceTransportConfiguration { |
34 | 35 | ||
35 | @JsonIgnore | 36 | @JsonIgnore |
1 | +/** | ||
2 | + * Copyright © 2016-2021 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.common.data.device.profile; | ||
17 | + | ||
18 | +import lombok.Data; | ||
19 | +import org.thingsboard.server.common.data.DeviceTransportType; | ||
20 | + | ||
21 | +@Data | ||
22 | +public class CoapDeviceProfileTransportConfiguration implements DeviceProfileTransportConfiguration { | ||
23 | + | ||
24 | + private CoapDeviceTypeConfiguration coapDeviceTypeConfiguration; | ||
25 | + | ||
26 | + @Override | ||
27 | + public DeviceTransportType getType() { | ||
28 | + return DeviceTransportType.COAP; | ||
29 | + } | ||
30 | + | ||
31 | + public CoapDeviceTypeConfiguration getCoapDeviceTypeConfiguration() { | ||
32 | + if (coapDeviceTypeConfiguration != null) { | ||
33 | + return coapDeviceTypeConfiguration; | ||
34 | + } else { | ||
35 | + return new DefaultCoapDeviceTypeConfiguration(); | ||
36 | + } | ||
37 | + } | ||
38 | +} |