Merge remote-tracking branch 'ce/develop/3.4' into test-sql-suite-refactoring
# Conflicts: # application/src/test/java/org/thingsboard/server/transport/TransportSqlTestSuite.java
This commit is contained in:
commit
23c774610a
@ -18,8 +18,6 @@ package org.thingsboard.server.transport;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.controller.AbstractControllerTest;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
|
||||
@ -27,8 +25,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractTransportIntegrationTest extends AbstractControllerTest {
|
||||
|
||||
@ -95,21 +91,11 @@ public abstract class AbstractTransportIntegrationTest extends AbstractControlle
|
||||
" optional string params = 3;\n" +
|
||||
"}";
|
||||
|
||||
protected Tenant savedTenant;
|
||||
protected User tenantAdmin;
|
||||
|
||||
protected Device savedDevice;
|
||||
protected String accessToken;
|
||||
|
||||
protected DeviceProfile deviceProfile;
|
||||
|
||||
protected void processAfterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
if (savedTenant != null) {
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
|
||||
protected List<TransportProtos.KeyValueProto> getKvProtos(List<String> expectedKeys) {
|
||||
List<TransportProtos.KeyValueProto> keyValueProtos = new ArrayList<>();
|
||||
TransportProtos.KeyValueProto strKeyValueProto = getKeyValueProto(expectedKeys.get(0), "value1", TransportProtos.KeyValueType.STRING_V);
|
||||
|
||||
@ -17,18 +17,16 @@ package org.thingsboard.server.transport.coap;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.californium.core.CoapClient;
|
||||
import org.junit.Assert;
|
||||
import org.junit.After;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.DeviceProfileType;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration;
|
||||
@ -42,7 +40,6 @@ import org.thingsboard.server.common.data.device.profile.EfentoCoapDeviceTypeCon
|
||||
import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.common.data.security.Authority;
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.transport.AbstractTransportIntegrationTest;
|
||||
@ -60,133 +57,104 @@ public abstract class AbstractCoapIntegrationTest extends AbstractTransportInteg
|
||||
|
||||
protected CoapClient client;
|
||||
|
||||
@Override
|
||||
protected void processAfterTest() throws Exception {
|
||||
if (client != null) {
|
||||
client.shutdown();
|
||||
}
|
||||
super.processAfterTest();
|
||||
}
|
||||
|
||||
protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception {
|
||||
this.processBeforeTest(deviceName, coapDeviceType, payloadType, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED);
|
||||
}
|
||||
|
||||
protected void processBeforeTest(String deviceName,
|
||||
CoapDeviceType coapDeviceType,
|
||||
TransportPayloadType payloadType,
|
||||
String telemetryProtoSchema,
|
||||
String attributesProtoSchema,
|
||||
String rpcResponseProtoSchema,
|
||||
String rpcRequestProtoSchema,
|
||||
String provisionKey,
|
||||
String provisionSecret,
|
||||
DeviceProfileProvisionType provisionType
|
||||
) throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
Tenant tenant = new Tenant();
|
||||
tenant.setTitle("My tenant");
|
||||
savedTenant = doPost("/api/tenant", tenant, Tenant.class);
|
||||
Assert.assertNotNull(savedTenant);
|
||||
|
||||
tenantAdmin = new User();
|
||||
tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
|
||||
tenantAdmin.setTenantId(savedTenant.getId());
|
||||
tenantAdmin.setEmail("tenant" + atomicInteger.getAndIncrement() + "@thingsboard.org");
|
||||
tenantAdmin.setFirstName("Joe");
|
||||
tenantAdmin.setLastName("Downs");
|
||||
|
||||
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
|
||||
|
||||
Device device = new Device();
|
||||
device.setName(deviceName);
|
||||
device.setType("default");
|
||||
|
||||
if (coapDeviceType != null) {
|
||||
DeviceProfile coapDeviceProfile = createCoapDeviceProfile(payloadType, coapDeviceType, provisionSecret, provisionType, provisionKey, attributesProtoSchema, telemetryProtoSchema, rpcResponseProtoSchema, rpcRequestProtoSchema);
|
||||
deviceProfile = doPost("/api/deviceProfile", coapDeviceProfile, DeviceProfile.class);
|
||||
device.setType(deviceProfile.getName());
|
||||
device.setDeviceProfileId(deviceProfile.getId());
|
||||
}
|
||||
|
||||
savedDevice = doPost("/api/device", device, Device.class);
|
||||
|
||||
protected void processBeforeTest(CoapTestConfigProperties config) throws Exception {
|
||||
loginTenantAdmin();
|
||||
deviceProfile = createCoapDeviceProfile(config);
|
||||
assertNotNull(deviceProfile);
|
||||
savedDevice = createDevice(config.getDeviceName(), deviceProfile.getName());
|
||||
DeviceCredentials deviceCredentials =
|
||||
doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
||||
|
||||
assertNotNull(deviceCredentials);
|
||||
assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
|
||||
accessToken = deviceCredentials.getCredentialsId();
|
||||
assertNotNull(accessToken);
|
||||
|
||||
}
|
||||
|
||||
protected DeviceProfile createCoapDeviceProfile(TransportPayloadType transportPayloadType, CoapDeviceType coapDeviceType,
|
||||
String provisionSecret, DeviceProfileProvisionType provisionType,
|
||||
String provisionKey, String attributesProtoSchema,
|
||||
String telemetryProtoSchema, String rpcResponseProtoSchema, String rpcRequestProtoSchema) {
|
||||
DeviceProfile deviceProfile = new DeviceProfile();
|
||||
deviceProfile.setName(transportPayloadType.name());
|
||||
deviceProfile.setType(DeviceProfileType.DEFAULT);
|
||||
deviceProfile.setProvisionType(provisionType);
|
||||
deviceProfile.setProvisionDeviceKey(provisionKey);
|
||||
deviceProfile.setDescription(transportPayloadType.name() + " Test");
|
||||
DeviceProfileData deviceProfileData = new DeviceProfileData();
|
||||
DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
|
||||
deviceProfile.setTransportType(DeviceTransportType.COAP);
|
||||
CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = new CoapDeviceProfileTransportConfiguration();
|
||||
CoapDeviceTypeConfiguration coapDeviceTypeConfiguration;
|
||||
if (CoapDeviceType.DEFAULT.equals(coapDeviceType)) {
|
||||
DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = new DefaultCoapDeviceTypeConfiguration();
|
||||
TransportPayloadTypeConfiguration transportPayloadTypeConfiguration;
|
||||
if (TransportPayloadType.PROTOBUF.equals(transportPayloadType)) {
|
||||
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
|
||||
if (StringUtils.isEmpty(telemetryProtoSchema)) {
|
||||
telemetryProtoSchema = DEVICE_TELEMETRY_PROTO_SCHEMA;
|
||||
}
|
||||
if (StringUtils.isEmpty(attributesProtoSchema)) {
|
||||
attributesProtoSchema = DEVICE_ATTRIBUTES_PROTO_SCHEMA;
|
||||
}
|
||||
if (StringUtils.isEmpty(rpcResponseProtoSchema)) {
|
||||
rpcResponseProtoSchema = DEVICE_RPC_RESPONSE_PROTO_SCHEMA;
|
||||
}
|
||||
if (StringUtils.isEmpty(rpcRequestProtoSchema)) {
|
||||
rpcRequestProtoSchema = DEVICE_RPC_REQUEST_PROTO_SCHEMA;
|
||||
}
|
||||
protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema);
|
||||
protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema);
|
||||
protoTransportPayloadConfiguration.setDeviceRpcResponseProtoSchema(rpcResponseProtoSchema);
|
||||
protoTransportPayloadConfiguration.setDeviceRpcRequestProtoSchema(rpcRequestProtoSchema);
|
||||
transportPayloadTypeConfiguration = protoTransportPayloadConfiguration;
|
||||
} else {
|
||||
transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration();
|
||||
}
|
||||
defaultCoapDeviceTypeConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration);
|
||||
coapDeviceTypeConfiguration = defaultCoapDeviceTypeConfiguration;
|
||||
protected DeviceProfile createCoapDeviceProfile(CoapTestConfigProperties config) throws Exception {
|
||||
CoapDeviceType coapDeviceType = config.getCoapDeviceType();
|
||||
if (coapDeviceType == null) {
|
||||
DeviceProfileInfo defaultDeviceProfileInfo = doGet("/api/deviceProfileInfo/default", DeviceProfileInfo.class);
|
||||
return doGet("/api/deviceProfile/" + defaultDeviceProfileInfo.getId().getId(), DeviceProfile.class);
|
||||
} else {
|
||||
coapDeviceTypeConfiguration = new EfentoCoapDeviceTypeConfiguration();
|
||||
TransportPayloadType transportPayloadType = config.getTransportPayloadType();
|
||||
DeviceProfile deviceProfile = new DeviceProfile();
|
||||
deviceProfile.setName(transportPayloadType.name());
|
||||
deviceProfile.setType(DeviceProfileType.DEFAULT);
|
||||
DeviceProfileProvisionType provisionType = config.getProvisionType() != null ?
|
||||
config.getProvisionType() : DeviceProfileProvisionType.DISABLED;
|
||||
deviceProfile.setProvisionType(provisionType);
|
||||
deviceProfile.setProvisionDeviceKey(config.getProvisionKey());
|
||||
deviceProfile.setDescription(transportPayloadType.name() + " Test");
|
||||
DeviceProfileData deviceProfileData = new DeviceProfileData();
|
||||
DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
|
||||
deviceProfile.setTransportType(DeviceTransportType.COAP);
|
||||
CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = new CoapDeviceProfileTransportConfiguration();
|
||||
CoapDeviceTypeConfiguration coapDeviceTypeConfiguration;
|
||||
if (CoapDeviceType.DEFAULT.equals(coapDeviceType)) {
|
||||
DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = new DefaultCoapDeviceTypeConfiguration();
|
||||
TransportPayloadTypeConfiguration transportPayloadTypeConfiguration;
|
||||
if (TransportPayloadType.PROTOBUF.equals(transportPayloadType)) {
|
||||
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
|
||||
String telemetryProtoSchema = config.getTelemetryProtoSchema();
|
||||
String attributesProtoSchema = config.getAttributesProtoSchema();
|
||||
String rpcResponseProtoSchema = config.getRpcResponseProtoSchema();
|
||||
String rpcRequestProtoSchema = config.getRpcRequestProtoSchema();
|
||||
protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(
|
||||
telemetryProtoSchema != null ? telemetryProtoSchema : DEVICE_TELEMETRY_PROTO_SCHEMA
|
||||
);
|
||||
protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(
|
||||
attributesProtoSchema != null ? attributesProtoSchema : DEVICE_ATTRIBUTES_PROTO_SCHEMA
|
||||
);
|
||||
protoTransportPayloadConfiguration.setDeviceRpcResponseProtoSchema(
|
||||
rpcResponseProtoSchema != null ? rpcResponseProtoSchema : DEVICE_RPC_RESPONSE_PROTO_SCHEMA
|
||||
);
|
||||
protoTransportPayloadConfiguration.setDeviceRpcRequestProtoSchema(
|
||||
rpcRequestProtoSchema != null ? rpcRequestProtoSchema : DEVICE_RPC_REQUEST_PROTO_SCHEMA
|
||||
);
|
||||
transportPayloadTypeConfiguration = protoTransportPayloadConfiguration;
|
||||
} else {
|
||||
transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration();
|
||||
}
|
||||
defaultCoapDeviceTypeConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration);
|
||||
coapDeviceTypeConfiguration = defaultCoapDeviceTypeConfiguration;
|
||||
} else {
|
||||
coapDeviceTypeConfiguration = new EfentoCoapDeviceTypeConfiguration();
|
||||
}
|
||||
coapDeviceProfileTransportConfiguration.setCoapDeviceTypeConfiguration(coapDeviceTypeConfiguration);
|
||||
deviceProfileData.setTransportConfiguration(coapDeviceProfileTransportConfiguration);
|
||||
DeviceProfileProvisionConfiguration provisionConfiguration;
|
||||
switch (provisionType) {
|
||||
case ALLOW_CREATE_NEW_DEVICES:
|
||||
provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(config.getProvisionSecret());
|
||||
break;
|
||||
case CHECK_PRE_PROVISIONED_DEVICES:
|
||||
provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(config.getProvisionSecret());
|
||||
break;
|
||||
case DISABLED:
|
||||
default:
|
||||
provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(config.getProvisionSecret());
|
||||
break;
|
||||
}
|
||||
deviceProfileData.setProvisionConfiguration(provisionConfiguration);
|
||||
deviceProfileData.setConfiguration(configuration);
|
||||
deviceProfile.setProfileData(deviceProfileData);
|
||||
deviceProfile.setDefault(false);
|
||||
deviceProfile.setDefaultRuleChainId(null);
|
||||
return doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
|
||||
}
|
||||
coapDeviceProfileTransportConfiguration.setCoapDeviceTypeConfiguration(coapDeviceTypeConfiguration);
|
||||
deviceProfileData.setTransportConfiguration(coapDeviceProfileTransportConfiguration);
|
||||
DeviceProfileProvisionConfiguration provisionConfiguration;
|
||||
switch (provisionType) {
|
||||
case ALLOW_CREATE_NEW_DEVICES:
|
||||
provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(provisionSecret);
|
||||
break;
|
||||
case CHECK_PRE_PROVISIONED_DEVICES:
|
||||
provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(provisionSecret);
|
||||
break;
|
||||
case DISABLED:
|
||||
default:
|
||||
provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(provisionSecret);
|
||||
break;
|
||||
}
|
||||
deviceProfileData.setProvisionConfiguration(provisionConfiguration);
|
||||
deviceProfileData.setConfiguration(configuration);
|
||||
deviceProfile.setProfileData(deviceProfileData);
|
||||
deviceProfile.setDefault(false);
|
||||
deviceProfile.setDefaultRuleChainId(null);
|
||||
return deviceProfile;
|
||||
}
|
||||
|
||||
protected Device createDevice(String name, String type) throws Exception {
|
||||
Device device = new Device();
|
||||
device.setName(name);
|
||||
device.setType(type);
|
||||
return doPost("/api/device", device, Device.class);
|
||||
}
|
||||
|
||||
protected CoapClient getCoapClient(FeatureType featureType) {
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class CoapTestConfigProperties {
|
||||
|
||||
String deviceName;
|
||||
|
||||
CoapDeviceType coapDeviceType;
|
||||
|
||||
TransportPayloadType transportPayloadType;
|
||||
|
||||
String telemetryTopicFilter;
|
||||
String attributesTopicFilter;
|
||||
|
||||
String telemetryProtoSchema;
|
||||
String attributesProtoSchema;
|
||||
String rpcResponseProtoSchema;
|
||||
String rpcRequestProtoSchema;
|
||||
|
||||
DeviceProfileProvisionType provisionType;
|
||||
String provisionKey;
|
||||
String provisionSecret;
|
||||
|
||||
}
|
||||
@ -16,10 +16,8 @@
|
||||
package org.thingsboard.server.transport.coap.attributes;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -30,14 +28,6 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap
|
||||
protected static final String POST_ATTRIBUTES_PAYLOAD = "{\"attribute1\":\"value1\",\"attribute2\":true,\"attribute3\":42.0,\"attribute4\":73," +
|
||||
"\"attribute5\":{\"someNumber\":42,\"someArray\":[1,2,3],\"someNestedObject\":{\"key\":\"value\"}}}";
|
||||
|
||||
protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception {
|
||||
super.processBeforeTest(deviceName, coapDeviceType, payloadType);
|
||||
}
|
||||
|
||||
protected void processAfterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
}
|
||||
|
||||
protected List<TransportProtos.TsKvProto> getTsKvProtoList() {
|
||||
TransportProtos.TsKvProto tsKvProtoAttribute1 = getTsKvProto("attribute1", "value1", TransportProtos.KeyValueType.STRING_V);
|
||||
TransportProtos.TsKvProto tsKvProtoAttribute2 = getTsKvProto("attribute2", "true", TransportProtos.KeyValueType.BOOLEAN_V);
|
||||
|
||||
@ -18,7 +18,6 @@ package org.thingsboard.server.transport.coap.attributes.request;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.californium.core.CoapClient;
|
||||
import org.eclipse.californium.core.CoapResponse;
|
||||
import org.eclipse.californium.core.coap.CoAP;
|
||||
import org.eclipse.californium.core.coap.MediaTypeRegistry;
|
||||
@ -26,6 +25,8 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
import org.thingsboard.server.transport.coap.attributes.AbstractCoapAttributesIntegrationTest;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
|
||||
@ -37,13 +38,17 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesRequestIntegrationTest extends AbstractCoapAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesRequestIntegrationTest extends AbstractCoapAttributesIntegrationTest {
|
||||
|
||||
protected static final long CLIENT_REQUEST_TIMEOUT = 60000L;
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Request attribute values from the server", null, null);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
@ -21,13 +21,21 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesRequestJsonIntegrationTest extends AbstractCoapAttributesRequestIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesRequestJsonIntegrationTest extends CoapAttributesRequestIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Request attribute values from the server json", CoapDeviceType.DEFAULT, TransportPayloadType.JSON);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server json")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
@ -36,7 +36,9 @@ import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportC
|
||||
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -47,7 +49,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesRequestProtoIntegrationTest extends AbstractCoapAttributesRequestIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesRequestProtoIntegrationTest extends CoapAttributesRequestIntegrationTest {
|
||||
|
||||
public static final String ATTRIBUTES_SCHEMA_STR = "syntax =\"proto3\";\n" +
|
||||
"\n" +
|
||||
@ -73,8 +76,13 @@ public abstract class AbstractCoapAttributesRequestProtoIntegrationTest extends
|
||||
@Before
|
||||
@Override
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Request attribute values from the server proto", CoapDeviceType.DEFAULT,
|
||||
TransportPayloadType.PROTOBUF, null, ATTRIBUTES_SCHEMA_STR, null, null, null, null, DeviceProfileProvisionType.DISABLED);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesProtoSchema(ATTRIBUTES_SCHEMA_STR)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.attributes.request.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.attributes.request.AbstractCoapAttributesRequestJsonIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesRequestJsonSqlIntegrationTest extends AbstractCoapAttributesRequestJsonIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.attributes.request.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.attributes.request.AbstractCoapAttributesRequestProtoIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesRequestProtoSqlIntegrationTest extends AbstractCoapAttributesRequestProtoIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.attributes.request.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.attributes.request.AbstractCoapAttributesRequestIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesRequestSqlIntegrationTest extends AbstractCoapAttributesRequestIntegrationTest {
|
||||
}
|
||||
@ -30,10 +30,13 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.coapserver.DefaultCoapServerService;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.common.transport.service.DefaultTransportService;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
import org.thingsboard.server.transport.coap.CoapTransportResource;
|
||||
import org.thingsboard.server.transport.coap.attributes.AbstractCoapAttributesIntegrationTest;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -45,7 +48,8 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesUpdatesIntegrationTest extends AbstractCoapAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesUpdatesIntegrationTest extends AbstractCoapAttributesIntegrationTest {
|
||||
|
||||
private static final String RESPONSE_ATTRIBUTES_PAYLOAD_DELETED = "{\"deleted\":[\"attribute5\"]}";
|
||||
|
||||
@ -66,7 +70,10 @@ public abstract class AbstractCoapAttributesUpdatesIntegrationTest extends Abstr
|
||||
coapTransportResource = spy( (CoapTransportResource) api.getChild("v1") );
|
||||
api.delete(api.getChild("v1") );
|
||||
api.add(coapTransportResource);
|
||||
processBeforeTest("Test Subscribe to attribute updates", null, null);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
@ -21,13 +21,21 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesUpdatesJsonIntegrationTest extends AbstractCoapAttributesUpdatesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesUpdatesJsonIntegrationTest extends CoapAttributesUpdatesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Subscribe to attribute updates", CoapDeviceType.DEFAULT, TransportPayloadType.JSON);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
@ -23,7 +23,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -35,11 +37,17 @@ import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesUpdatesProtoIntegrationTest extends AbstractCoapAttributesUpdatesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesUpdatesProtoIntegrationTest extends CoapAttributesUpdatesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Subscribe to attribute updates", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.attributes.updates.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.attributes.updates.AbstractCoapAttributesUpdatesIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesUpdatesSqlIntegrationTest extends AbstractCoapAttributesUpdatesIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.attributes.updates.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.attributes.updates.AbstractCoapAttributesUpdatesJsonIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesUpdatesSqlJsonIntegrationTest extends AbstractCoapAttributesUpdatesJsonIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.attributes.updates.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.attributes.updates.AbstractCoapAttributesUpdatesProtoIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesUpdatesSqlProtoIntegrationTest extends AbstractCoapAttributesUpdatesProtoIntegrationTest {
|
||||
}
|
||||
@ -24,7 +24,6 @@ import org.eclipse.californium.elements.exception.ConnectorException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
import org.thingsboard.server.common.data.ClaimRequest;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -33,6 +32,9 @@ import org.thingsboard.server.common.data.security.Authority;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.dao.device.claim.ClaimResponse;
|
||||
import org.thingsboard.server.dao.device.claim.ClaimResult;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -41,7 +43,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapClaimDeviceTest extends AbstractCoapIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapClaimDeviceTest extends AbstractCoapIntegrationTest {
|
||||
|
||||
protected static final String CUSTOMER_USER_PASSWORD = "customerUser123!";
|
||||
|
||||
@ -50,21 +53,24 @@ public abstract class AbstractCoapClaimDeviceTest extends AbstractCoapIntegratio
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
super.processBeforeTest("Test Claim device", null, null);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Claim device")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
createCustomerAndUser();
|
||||
}
|
||||
|
||||
protected void createCustomerAndUser() throws Exception {
|
||||
Customer customer = new Customer();
|
||||
customer.setTenantId(savedTenant.getId());
|
||||
customer.setTenantId(tenantId);
|
||||
customer.setTitle("Test Claiming Customer");
|
||||
savedCustomer = doPost("/api/customer", customer, Customer.class);
|
||||
assertNotNull(savedCustomer);
|
||||
assertEquals(savedTenant.getId(), savedCustomer.getTenantId());
|
||||
assertEquals(tenantId, savedCustomer.getTenantId());
|
||||
|
||||
User user = new User();
|
||||
user.setAuthority(Authority.CUSTOMER_USER);
|
||||
user.setTenantId(savedTenant.getId());
|
||||
user.setTenantId(tenantId);
|
||||
user.setCustomerId(savedCustomer.getId());
|
||||
user.setEmail("customer@thingsboard.org");
|
||||
|
||||
@ -75,7 +81,7 @@ public abstract class AbstractCoapClaimDeviceTest extends AbstractCoapIntegratio
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -21,13 +21,21 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapClaimJsonDeviceTest extends AbstractCoapClaimDeviceTest {
|
||||
@DaoSqlTest
|
||||
public class CoapClaimJsonDeviceTest extends CoapClaimDeviceTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
super.processBeforeTest("Test Claim device Json", CoapDeviceType.DEFAULT, TransportPayloadType.JSON);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Claim device Json")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
createCustomerAndUser();
|
||||
}
|
||||
|
||||
@ -16,21 +16,28 @@
|
||||
package org.thingsboard.server.transport.coap.claim;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.californium.core.CoapClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportApiProtos;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapClaimProtoDeviceTest extends AbstractCoapClaimDeviceTest {
|
||||
@DaoSqlTest
|
||||
public class CoapClaimProtoDeviceTest extends CoapClaimDeviceTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Claim device Proto", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Claim device Proto")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
createCustomerAndUser();
|
||||
}
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.claim.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.claim.AbstractCoapClaimJsonDeviceTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapClaimDeviceJsonSqlTest extends AbstractCoapClaimJsonDeviceTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.claim.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.claim.AbstractCoapClaimProtoDeviceTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapClaimDeviceProtoSqlTest extends AbstractCoapClaimProtoDeviceTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.claim.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.claim.AbstractCoapClaimDeviceTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapClaimDeviceSqlTest extends AbstractCoapClaimDeviceTest {
|
||||
}
|
||||
@ -25,6 +25,7 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -37,13 +38,13 @@ import org.thingsboard.server.common.transport.util.JsonUtils;
|
||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
||||
import org.thingsboard.server.dao.device.DeviceService;
|
||||
import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapProvisionJsonDeviceTest extends AbstractCoapIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
DeviceCredentialsService deviceCredentialsService;
|
||||
@ -53,7 +54,7 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -88,7 +89,12 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn
|
||||
|
||||
|
||||
private void processTestProvisioningDisabledDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
byte[] result = createCoapClientAndPublish().getPayload();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
Assert.assertEquals("Provision data was not found!", response.get("errorMsg").getAsString());
|
||||
@ -97,15 +103,23 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn
|
||||
|
||||
|
||||
private void processTestProvisioningCreateNewDeviceWithoutCredentials() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
byte[] result = createCoapClientAndPublish().getPayload();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString());
|
||||
@ -113,16 +127,24 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn
|
||||
|
||||
|
||||
private void processTestProvisioningCreateNewDeviceWithAccessToken() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
String requestCredentials = ",\"credentialsType\": \"ACCESS_TOKEN\",\"token\": \"test_token\"";
|
||||
byte[] result = createCoapClientAndPublish(requestCredentials).getPayload();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "ACCESS_TOKEN");
|
||||
@ -132,16 +154,24 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn
|
||||
|
||||
|
||||
private void processTestProvisioningCreateNewDeviceWithCert() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
String requestCredentials = ",\"credentialsType\": \"X509_CERTIFICATE\",\"hash\": \"testHash\"";
|
||||
byte[] result = createCoapClientAndPublish(requestCredentials).getPayload();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "X509_CERTIFICATE");
|
||||
@ -156,18 +186,34 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn
|
||||
}
|
||||
|
||||
private void processTestProvisioningCheckPreProvisionedDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
byte[] result = createCoapClientAndPublish().getPayload();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), savedDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, savedDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString());
|
||||
}
|
||||
|
||||
private void processTestProvisioningWithBadKeyDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.JSON, null, null, null, null, "testProvisionKeyOrig", "testProvisionSecret", DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)
|
||||
.provisionKey("testProvisionKeyOrig")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
byte[] result = createCoapClientAndPublish().getPayload();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
Assert.assertEquals("Provision data was not found!", response.get("errorMsg").getAsString());
|
||||
@ -24,6 +24,7 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
@ -43,11 +44,13 @@ import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceReque
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceResponseMsg;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapProvisionProtoDeviceTest extends AbstractCoapIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
DeviceCredentialsService deviceCredentialsService;
|
||||
@ -57,7 +60,7 @@ public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapI
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -92,37 +95,58 @@ public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapI
|
||||
|
||||
|
||||
private void processTestProvisioningDisabledDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
ProvisionDeviceResponseMsg result = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish().getPayload());
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), result.getStatus().toString());
|
||||
}
|
||||
|
||||
private void processTestProvisioningCreateNewDeviceWithoutCredentials() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish().getPayload());
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString());
|
||||
}
|
||||
|
||||
private void processTestProvisioningCreateNewDeviceWithAccessToken() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CredentialsDataProto requestCredentials = CredentialsDataProto.newBuilder().setValidateDeviceTokenRequestMsg(ValidateDeviceTokenRequestMsg.newBuilder().setToken("test_token").build()).build();
|
||||
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish(createTestsProvisionMessage(CredentialsType.ACCESS_TOKEN, requestCredentials)).getPayload());
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.ACCESS_TOKEN);
|
||||
@ -131,16 +155,24 @@ public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapI
|
||||
}
|
||||
|
||||
private void processTestProvisioningCreateNewDeviceWithCert() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CredentialsDataProto requestCredentials = CredentialsDataProto.newBuilder().setValidateDeviceX509CertRequestMsg(ValidateDeviceX509CertRequestMsg.newBuilder().setHash("testHash").build()).build();
|
||||
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish(createTestsProvisionMessage(CredentialsType.X509_CERTIFICATE, requestCredentials)).getPayload());
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.X509_CERTIFICATE);
|
||||
@ -155,17 +187,33 @@ public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapI
|
||||
}
|
||||
|
||||
private void processTestProvisioningCheckPreProvisionedDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish().getPayload());
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), savedDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, savedDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString());
|
||||
}
|
||||
|
||||
private void processTestProvisioningWithBadKeyDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, null, null, "testProvisionKeyOrig", "testProvisionSecret", DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)
|
||||
.provisionKey("testProvisionKeyOrig")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createCoapClientAndPublish().getPayload());
|
||||
Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.getStatus().toString());
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.provision.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.provision.AbstractCoapProvisionJsonDeviceTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapProvisionDeviceJsonSqlTest extends AbstractCoapProvisionJsonDeviceTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.provision.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.provision.AbstractCoapProvisionProtoDeviceTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapProvisionDeviceProtoSqlTest extends AbstractCoapProvisionProtoDeviceTest {
|
||||
}
|
||||
@ -26,8 +26,6 @@ import org.eclipse.californium.core.coap.CoAP;
|
||||
import org.eclipse.californium.core.coap.MediaTypeRegistry;
|
||||
import org.eclipse.californium.core.coap.Request;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
|
||||
@ -45,12 +43,7 @@ public abstract class AbstractCoapServerSideRpcIntegrationTest extends AbstractC
|
||||
|
||||
protected static final String DEVICE_RESPONSE = "{\"value1\":\"A\",\"value2\":\"B\"}";
|
||||
|
||||
protected Long asyncContextTimeoutToUseRpcPlugin;
|
||||
|
||||
protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception {
|
||||
super.processBeforeTest(deviceName, coapDeviceType, payloadType);
|
||||
asyncContextTimeoutToUseRpcPlugin = 10000L;
|
||||
}
|
||||
protected static final Long asyncContextTimeoutToUseRpcPlugin = 10000L;
|
||||
|
||||
protected void processOneWayRpcTest() throws Exception {
|
||||
client = getCoapClient(FeatureType.RPC);
|
||||
|
||||
@ -21,21 +21,30 @@ import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.service.security.AccessValidator;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapServerSideRpcDefaultIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapServerSideRpcDefaultIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("RPC test device", null, null);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -21,18 +21,26 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapServerSideRpcJsonIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapServerSideRpcJsonIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("RPC test device", CoapDeviceType.DEFAULT, TransportPayloadType.JSON);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -23,16 +23,12 @@ import com.squareup.wire.schema.internal.parser.ProtoFileElement;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.californium.core.CoapClient;
|
||||
import org.eclipse.californium.core.CoapHandler;
|
||||
import org.eclipse.californium.core.CoapObserveRelation;
|
||||
import org.eclipse.californium.core.CoapResponse;
|
||||
import org.eclipse.californium.core.coap.CoAP;
|
||||
import org.eclipse.californium.core.coap.MediaTypeRegistry;
|
||||
import org.eclipse.californium.core.coap.Request;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration;
|
||||
@ -40,19 +36,16 @@ import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeCo
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapServerSideRpcProtoIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapServerSideRpcProtoIntegrationTest extends AbstractCoapServerSideRpcIntegrationTest {
|
||||
|
||||
private static final String RPC_REQUEST_PROTO_SCHEMA = "syntax =\"proto3\";\n" +
|
||||
"package rpc;\n" +
|
||||
@ -70,12 +63,18 @@ public abstract class AbstractCoapServerSideRpcProtoIntegrationTest extends Abst
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("RPC test device", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.rpc.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.rpc.AbstractCoapServerSideRpcJsonIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapServerSideRpcJsonSqlIntegrationTest extends AbstractCoapServerSideRpcJsonIntegrationTest {
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.rpc.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.rpc.AbstractCoapServerSideRpcProtoIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapServerSideRpcProtoSqlIntegrationTest extends AbstractCoapServerSideRpcProtoIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.rpc.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.rpc.AbstractCoapServerSideRpcDefaultIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class CoapServerSideRpcSqlIntegrationTest extends AbstractCoapServerSideRpcDefaultIntegrationTest {
|
||||
}
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.telemetry.attributes;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.californium.core.CoapClient;
|
||||
@ -26,9 +25,11 @@ import org.eclipse.californium.elements.exception.ConnectorException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@ -43,14 +44,18 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoapIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesIntegrationTest extends AbstractCoapIntegrationTest {
|
||||
|
||||
private static final String PAYLOAD_VALUES_STR = "{\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4," +
|
||||
" \"key5\": {\"someNumber\": 42, \"someArray\": [1,2,3], \"someNestedObject\": {\"key\": \"value\"}}}";
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", null, null);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
@ -21,13 +21,21 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesJsonIntegrationTest extends AbstractCoapAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesJsonIntegrationTest extends CoapAttributesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device Json", CoapDeviceType.DEFAULT, TransportPayloadType.JSON);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device Json")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
@ -30,6 +30,8 @@ import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeCo
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -37,12 +39,18 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapAttributesProtoIntegrationTest extends AbstractCoapAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesProtoIntegrationTest extends CoapAttributesIntegrationTest {
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device Proto", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device Proto")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.telemetry.attributes.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.telemetry.attributes.AbstractCoapAttributesIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 8/22/2017.
|
||||
*/
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesSqlIntegrationTest extends AbstractCoapAttributesIntegrationTest {
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.telemetry.attributes.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.telemetry.attributes.AbstractCoapAttributesJsonIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 8/22/2017.
|
||||
*/
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesSqlJsonIntegrationTest extends AbstractCoapAttributesJsonIntegrationTest {
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.coap.telemetry.attributes.sql;
|
||||
|
||||
import org.thingsboard.server.transport.coap.telemetry.attributes.AbstractCoapAttributesProtoIntegrationTest;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 8/22/2017.
|
||||
*/
|
||||
@DaoSqlTest
|
||||
public class CoapAttributesSqlProtoIntegrationTest extends AbstractCoapAttributesProtoIntegrationTest {
|
||||
}
|
||||
@ -25,8 +25,9 @@ import org.eclipse.californium.elements.exception.ConnectorException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
import org.thingsboard.server.common.msg.session.FeatureType;
|
||||
import org.thingsboard.server.transport.coap.AbstractCoapIntegrationTest;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@ -46,7 +47,10 @@ public abstract class AbstractCoapTimeseriesIntegrationTest extends AbstractCoap
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device", null, null);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@ -21,13 +21,19 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.CoapDeviceType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapTimeseriesJsonIntegrationTest extends AbstractCoapTimeseriesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", CoapDeviceType.DEFAULT, TransportPayloadType.JSON);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@ -31,6 +31,7 @@ import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeCo
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.transport.coap.CoapTestConfigProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -48,7 +49,12 @@ public abstract class AbstractCoapTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetry() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration();
|
||||
assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration);
|
||||
CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration;
|
||||
@ -117,7 +123,13 @@ public abstract class AbstractCoapTimeseriesProtoIntegrationTest extends Abstrac
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
processBeforeTest("Test Post Telemetry device proto payload", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, schemaStr, null, null, null, null, null, DeviceProfileProvisionType.DISABLED);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryProtoSchema(schemaStr)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration();
|
||||
assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration);
|
||||
CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration;
|
||||
@ -172,7 +184,12 @@ public abstract class AbstractCoapTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithExplicitPresenceProtoKeys() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration();
|
||||
assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration);
|
||||
CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration;
|
||||
@ -239,7 +256,13 @@ public abstract class AbstractCoapTimeseriesProtoIntegrationTest extends Abstrac
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
processBeforeTest("Test Post Telemetry device proto payload", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF, schemaStr, null, null, null, null, null, DeviceProfileProvisionType.DISABLED);
|
||||
CoapTestConfigProperties configProperties = CoapTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.coapDeviceType(CoapDeviceType.DEFAULT)
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryProtoSchema(schemaStr)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration();
|
||||
assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration);
|
||||
CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration;
|
||||
|
||||
@ -22,17 +22,15 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.DeviceProfileType;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
|
||||
@ -43,7 +41,6 @@ import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadCon
|
||||
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.common.data.security.Authority;
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.transport.AbstractTransportIntegrationTest;
|
||||
@ -52,7 +49,6 @@ import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@TestPropertySource(properties = {
|
||||
"transport.mqtt.enabled=true",
|
||||
@ -63,102 +59,27 @@ public abstract class AbstractMqttIntegrationTest extends AbstractTransportInteg
|
||||
protected Device savedGateway;
|
||||
protected String gatewayAccessToken;
|
||||
|
||||
protected DeviceProfile deviceProfile;
|
||||
|
||||
protected void processBeforeTest(String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic) throws Exception {
|
||||
this.processBeforeTest(deviceName, gatewayName, payloadType, telemetryTopic, attributesTopic, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
}
|
||||
|
||||
protected void processBeforeTest(String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic, boolean enableCompatibilityWithJsonPayloadFormat, boolean useJsonPayloadFormatForDefaultDownlinkTopics) throws Exception {
|
||||
this.processBeforeTest(deviceName, gatewayName, payloadType, telemetryTopic, attributesTopic, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, enableCompatibilityWithJsonPayloadFormat, useJsonPayloadFormatForDefaultDownlinkTopics, false);
|
||||
}
|
||||
|
||||
protected void processBeforeTest(String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic, boolean enableCompatibilityWithJsonPayloadFormat, boolean useJsonPayloadFormatForDefaultDownlinkTopics, boolean sendAckOnValidationException) throws Exception {
|
||||
this.processBeforeTest(deviceName, gatewayName, payloadType, telemetryTopic, attributesTopic, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, enableCompatibilityWithJsonPayloadFormat, useJsonPayloadFormatForDefaultDownlinkTopics, sendAckOnValidationException);
|
||||
}
|
||||
|
||||
protected void processBeforeTest(String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic, boolean sendAckOnValidationException) throws Exception {
|
||||
this.processBeforeTest(deviceName, gatewayName, payloadType, telemetryTopic, attributesTopic, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, sendAckOnValidationException);
|
||||
}
|
||||
|
||||
protected void processBeforeTest(String deviceName,
|
||||
String gatewayName,
|
||||
TransportPayloadType payloadType,
|
||||
String telemetryTopic,
|
||||
String attributesTopic,
|
||||
String telemetryProtoSchema,
|
||||
String attributesProtoSchema,
|
||||
String rpcResponseProtoSchema,
|
||||
String rpcRequestProtoSchema,
|
||||
String provisionKey,
|
||||
String provisionSecret,
|
||||
DeviceProfileProvisionType provisionType,
|
||||
boolean enableCompatibilityWithJsonPayloadFormat,
|
||||
boolean useJsonPayloadFormatForDefaultDownlinkTopics,
|
||||
boolean sendAckOnValidationException) throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
Tenant tenant = new Tenant();
|
||||
tenant.setTitle("My tenant");
|
||||
savedTenant = doPost("/api/tenant", tenant, Tenant.class);
|
||||
Assert.assertNotNull(savedTenant);
|
||||
|
||||
tenantAdmin = new User();
|
||||
tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
|
||||
tenantAdmin.setTenantId(savedTenant.getId());
|
||||
tenantAdmin.setEmail("tenant" + atomicInteger.getAndIncrement() + "@thingsboard.org");
|
||||
tenantAdmin.setFirstName("Joe");
|
||||
tenantAdmin.setLastName("Downs");
|
||||
|
||||
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
|
||||
|
||||
Device device = new Device();
|
||||
device.setName(deviceName);
|
||||
device.setType("default");
|
||||
|
||||
Device gateway = new Device();
|
||||
gateway.setName(gatewayName);
|
||||
gateway.setType("default");
|
||||
ObjectNode additionalInfo = mapper.createObjectNode();
|
||||
additionalInfo.put("gateway", true);
|
||||
gateway.setAdditionalInfo(additionalInfo);
|
||||
|
||||
if (payloadType != null) {
|
||||
DeviceProfile mqttDeviceProfile = createMqttDeviceProfile(payloadType, telemetryTopic, attributesTopic,
|
||||
telemetryProtoSchema, attributesProtoSchema, rpcResponseProtoSchema, rpcRequestProtoSchema,
|
||||
provisionKey, provisionSecret, provisionType, enableCompatibilityWithJsonPayloadFormat,
|
||||
useJsonPayloadFormatForDefaultDownlinkTopics, sendAckOnValidationException);
|
||||
deviceProfile = doPost("/api/deviceProfile", mqttDeviceProfile, DeviceProfile.class);
|
||||
device.setType(deviceProfile.getName());
|
||||
device.setDeviceProfileId(deviceProfile.getId());
|
||||
gateway.setType(deviceProfile.getName());
|
||||
gateway.setDeviceProfileId(deviceProfile.getId());
|
||||
protected void processBeforeTest(MqttTestConfigProperties config) throws Exception {
|
||||
loginTenantAdmin();
|
||||
deviceProfile = createMqttDeviceProfile(config);
|
||||
assertNotNull(deviceProfile);
|
||||
if (config.getDeviceName() != null) {
|
||||
savedDevice = createDevice(config.getDeviceName(), deviceProfile.getName(), false);
|
||||
DeviceCredentials deviceCredentials =
|
||||
doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
||||
assertNotNull(deviceCredentials);
|
||||
assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
|
||||
accessToken = deviceCredentials.getCredentialsId();
|
||||
assertNotNull(accessToken);
|
||||
}
|
||||
|
||||
savedDevice = doPost("/api/device", device, Device.class);
|
||||
|
||||
DeviceCredentials deviceCredentials =
|
||||
doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
||||
|
||||
savedGateway = doPost("/api/device", gateway, Device.class);
|
||||
|
||||
DeviceCredentials gatewayCredentials =
|
||||
doGet("/api/device/" + savedGateway.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
||||
|
||||
assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
|
||||
accessToken = deviceCredentials.getCredentialsId();
|
||||
assertNotNull(accessToken);
|
||||
|
||||
assertEquals(savedGateway.getId(), gatewayCredentials.getDeviceId());
|
||||
gatewayAccessToken = gatewayCredentials.getCredentialsId();
|
||||
assertNotNull(gatewayAccessToken);
|
||||
|
||||
}
|
||||
|
||||
protected void processAfterTest() throws Exception {
|
||||
loginSysAdmin();
|
||||
if (savedTenant != null) {
|
||||
doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk());
|
||||
if (config.getGatewayName() != null) {
|
||||
savedGateway = createDevice(config.getGatewayName(), deviceProfile.getName(), true);
|
||||
DeviceCredentials gatewayCredentials =
|
||||
doGet("/api/device/" + savedGateway.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
||||
assertNotNull(gatewayCredentials);
|
||||
assertEquals(savedGateway.getId(), gatewayCredentials.getDeviceId());
|
||||
gatewayAccessToken = gatewayCredentials.getCredentialsId();
|
||||
assertNotNull(gatewayAccessToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,78 +99,95 @@ public abstract class AbstractMqttIntegrationTest extends AbstractTransportInteg
|
||||
client.publish(topic, message);
|
||||
}
|
||||
|
||||
protected DeviceProfile createMqttDeviceProfile(TransportPayloadType transportPayloadType,
|
||||
String telemetryTopic, String attributesTopic,
|
||||
String telemetryProtoSchema, String attributesProtoSchema,
|
||||
String rpcResponseProtoSchema, String rpcRequestProtoSchema,
|
||||
String provisionKey, String provisionSecret,
|
||||
DeviceProfileProvisionType provisionType,
|
||||
boolean enableCompatibilityWithJsonPayloadFormat,
|
||||
boolean useJsonPayloadFormatForDefaultDownlinkTopics,
|
||||
boolean sendAckOnValidationException) {
|
||||
DeviceProfile deviceProfile = new DeviceProfile();
|
||||
deviceProfile.setName(transportPayloadType.name());
|
||||
deviceProfile.setType(DeviceProfileType.DEFAULT);
|
||||
deviceProfile.setTransportType(DeviceTransportType.MQTT);
|
||||
deviceProfile.setProvisionType(provisionType);
|
||||
deviceProfile.setProvisionDeviceKey(provisionKey);
|
||||
deviceProfile.setDescription(transportPayloadType.name() + " Test");
|
||||
DeviceProfileData deviceProfileData = new DeviceProfileData();
|
||||
DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
|
||||
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = new MqttDeviceProfileTransportConfiguration();
|
||||
if (!StringUtils.isEmpty(telemetryTopic)) {
|
||||
mqttDeviceProfileTransportConfiguration.setDeviceTelemetryTopic(telemetryTopic);
|
||||
}
|
||||
if (!StringUtils.isEmpty(attributesTopic)) {
|
||||
mqttDeviceProfileTransportConfiguration.setDeviceAttributesTopic(attributesTopic);
|
||||
}
|
||||
mqttDeviceProfileTransportConfiguration.setSendAckOnValidationException(sendAckOnValidationException);
|
||||
TransportPayloadTypeConfiguration transportPayloadTypeConfiguration;
|
||||
if (TransportPayloadType.JSON.equals(transportPayloadType)) {
|
||||
transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration();
|
||||
protected DeviceProfile createMqttDeviceProfile(MqttTestConfigProperties config) throws Exception {
|
||||
TransportPayloadType transportPayloadType = config.getTransportPayloadType();
|
||||
if (transportPayloadType == null) {
|
||||
DeviceProfileInfo defaultDeviceProfileInfo = doGet("/api/deviceProfileInfo/default", DeviceProfileInfo.class);
|
||||
return doGet("/api/deviceProfile/" + defaultDeviceProfileInfo.getId().getId(), DeviceProfile.class);
|
||||
} else {
|
||||
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
|
||||
if (StringUtils.isEmpty(telemetryProtoSchema)) {
|
||||
telemetryProtoSchema = DEVICE_TELEMETRY_PROTO_SCHEMA;
|
||||
DeviceProfile deviceProfile = new DeviceProfile();
|
||||
deviceProfile.setName(transportPayloadType.name());
|
||||
deviceProfile.setType(DeviceProfileType.DEFAULT);
|
||||
deviceProfile.setTransportType(DeviceTransportType.MQTT);
|
||||
DeviceProfileProvisionType provisionType = config.getProvisionType() != null ?
|
||||
config.getProvisionType() : DeviceProfileProvisionType.DISABLED;
|
||||
deviceProfile.setProvisionType(provisionType);
|
||||
deviceProfile.setProvisionDeviceKey(config.getProvisionKey());
|
||||
deviceProfile.setDescription(transportPayloadType.name() + " Test");
|
||||
DeviceProfileData deviceProfileData = new DeviceProfileData();
|
||||
DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
|
||||
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = new MqttDeviceProfileTransportConfiguration();
|
||||
if (StringUtils.hasLength(config.getTelemetryTopicFilter())) {
|
||||
mqttDeviceProfileTransportConfiguration.setDeviceTelemetryTopic(config.getTelemetryTopicFilter());
|
||||
}
|
||||
if (StringUtils.isEmpty(attributesProtoSchema)) {
|
||||
attributesProtoSchema = DEVICE_ATTRIBUTES_PROTO_SCHEMA;
|
||||
if (StringUtils.hasLength(config.getAttributesTopicFilter())) {
|
||||
mqttDeviceProfileTransportConfiguration.setDeviceAttributesTopic(config.getAttributesTopicFilter());
|
||||
}
|
||||
if (StringUtils.isEmpty(rpcResponseProtoSchema)) {
|
||||
rpcResponseProtoSchema = DEVICE_RPC_RESPONSE_PROTO_SCHEMA;
|
||||
mqttDeviceProfileTransportConfiguration.setSendAckOnValidationException(config.isSendAckOnValidationException());
|
||||
TransportPayloadTypeConfiguration transportPayloadTypeConfiguration;
|
||||
if (TransportPayloadType.JSON.equals(transportPayloadType)) {
|
||||
transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration();
|
||||
} else {
|
||||
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
|
||||
String telemetryProtoSchema = config.getTelemetryProtoSchema();
|
||||
String attributesProtoSchema = config.getAttributesProtoSchema();
|
||||
String rpcResponseProtoSchema = config.getRpcResponseProtoSchema();
|
||||
String rpcRequestProtoSchema = config.getRpcRequestProtoSchema();
|
||||
protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(
|
||||
telemetryProtoSchema != null ? telemetryProtoSchema : DEVICE_TELEMETRY_PROTO_SCHEMA
|
||||
);
|
||||
protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(
|
||||
attributesProtoSchema != null ? attributesProtoSchema : DEVICE_ATTRIBUTES_PROTO_SCHEMA
|
||||
);
|
||||
protoTransportPayloadConfiguration.setDeviceRpcResponseProtoSchema(
|
||||
rpcResponseProtoSchema != null ? rpcResponseProtoSchema : DEVICE_RPC_RESPONSE_PROTO_SCHEMA
|
||||
);
|
||||
protoTransportPayloadConfiguration.setDeviceRpcRequestProtoSchema(
|
||||
rpcRequestProtoSchema != null ? rpcRequestProtoSchema : DEVICE_RPC_REQUEST_PROTO_SCHEMA
|
||||
);
|
||||
protoTransportPayloadConfiguration.setEnableCompatibilityWithJsonPayloadFormat(
|
||||
config.isEnableCompatibilityWithJsonPayloadFormat()
|
||||
);
|
||||
protoTransportPayloadConfiguration.setUseJsonPayloadFormatForDefaultDownlinkTopics(
|
||||
config.isEnableCompatibilityWithJsonPayloadFormat() &&
|
||||
config.isUseJsonPayloadFormatForDefaultDownlinkTopics()
|
||||
);
|
||||
transportPayloadTypeConfiguration = protoTransportPayloadConfiguration;
|
||||
}
|
||||
if (StringUtils.isEmpty(rpcRequestProtoSchema)) {
|
||||
rpcRequestProtoSchema = DEVICE_RPC_REQUEST_PROTO_SCHEMA;
|
||||
mqttDeviceProfileTransportConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration);
|
||||
deviceProfileData.setTransportConfiguration(mqttDeviceProfileTransportConfiguration);
|
||||
DeviceProfileProvisionConfiguration provisionConfiguration;
|
||||
switch (provisionType) {
|
||||
case ALLOW_CREATE_NEW_DEVICES:
|
||||
provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(config.getProvisionSecret());
|
||||
break;
|
||||
case CHECK_PRE_PROVISIONED_DEVICES:
|
||||
provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(config.getProvisionSecret());
|
||||
break;
|
||||
case DISABLED:
|
||||
default:
|
||||
provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(config.getProvisionSecret());
|
||||
break;
|
||||
}
|
||||
protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema);
|
||||
protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema);
|
||||
protoTransportPayloadConfiguration.setDeviceRpcResponseProtoSchema(rpcResponseProtoSchema);
|
||||
protoTransportPayloadConfiguration.setDeviceRpcRequestProtoSchema(rpcRequestProtoSchema);
|
||||
protoTransportPayloadConfiguration.setEnableCompatibilityWithJsonPayloadFormat(enableCompatibilityWithJsonPayloadFormat);
|
||||
protoTransportPayloadConfiguration.setUseJsonPayloadFormatForDefaultDownlinkTopics(enableCompatibilityWithJsonPayloadFormat && useJsonPayloadFormatForDefaultDownlinkTopics);
|
||||
transportPayloadTypeConfiguration = protoTransportPayloadConfiguration;
|
||||
deviceProfileData.setProvisionConfiguration(provisionConfiguration);
|
||||
deviceProfileData.setConfiguration(configuration);
|
||||
deviceProfile.setProfileData(deviceProfileData);
|
||||
deviceProfile.setDefault(false);
|
||||
deviceProfile.setDefaultRuleChainId(null);
|
||||
return doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
|
||||
}
|
||||
mqttDeviceProfileTransportConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration);
|
||||
deviceProfileData.setTransportConfiguration(mqttDeviceProfileTransportConfiguration);
|
||||
DeviceProfileProvisionConfiguration provisionConfiguration;
|
||||
switch (provisionType) {
|
||||
case ALLOW_CREATE_NEW_DEVICES:
|
||||
provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(provisionSecret);
|
||||
break;
|
||||
case CHECK_PRE_PROVISIONED_DEVICES:
|
||||
provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(provisionSecret);
|
||||
break;
|
||||
case DISABLED:
|
||||
default:
|
||||
provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(provisionSecret);
|
||||
break;
|
||||
}
|
||||
|
||||
protected Device createDevice(String name, String type, boolean gateway) throws Exception {
|
||||
Device device = new Device();
|
||||
device.setName(name);
|
||||
device.setType(type);
|
||||
if (gateway) {
|
||||
ObjectNode additionalInfo = mapper.createObjectNode();
|
||||
additionalInfo.put("gateway", true);
|
||||
device.setAdditionalInfo(additionalInfo);
|
||||
}
|
||||
deviceProfileData.setProvisionConfiguration(provisionConfiguration);
|
||||
deviceProfileData.setConfiguration(configuration);
|
||||
deviceProfile.setProfileData(deviceProfileData);
|
||||
deviceProfile.setDefault(false);
|
||||
deviceProfile.setDefaultRuleChainId(null);
|
||||
return deviceProfile;
|
||||
return doPost("/api/device", device, Device.class);
|
||||
}
|
||||
|
||||
protected TransportProtos.PostAttributeMsg getPostAttributeMsg(List<String> expectedKeys) {
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class MqttTestConfigProperties {
|
||||
|
||||
String deviceName;
|
||||
String gatewayName;
|
||||
|
||||
TransportPayloadType transportPayloadType;
|
||||
|
||||
String telemetryTopicFilter;
|
||||
String attributesTopicFilter;
|
||||
|
||||
String telemetryProtoSchema;
|
||||
String attributesProtoSchema;
|
||||
String rpcResponseProtoSchema;
|
||||
String rpcRequestProtoSchema;
|
||||
|
||||
boolean enableCompatibilityWithJsonPayloadFormat;
|
||||
boolean useJsonPayloadFormatForDefaultDownlinkTopics;
|
||||
boolean sendAckOnValidationException;
|
||||
|
||||
DeviceProfileProvisionType provisionType;
|
||||
String provisionKey;
|
||||
String provisionSecret;
|
||||
|
||||
}
|
||||
@ -81,14 +81,6 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt
|
||||
|
||||
private static final String RESPONSE_ATTRIBUTES_PAYLOAD_DELETED = "{\"deleted\":[\"attribute5\"]}";
|
||||
|
||||
protected void processBeforeTest(String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic) throws Exception {
|
||||
super.processBeforeTest(deviceName, gatewayName, payloadType, telemetryTopic, attributesTopic);
|
||||
}
|
||||
|
||||
protected void processAfterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
}
|
||||
|
||||
protected List<TransportProtos.TsKvProto> getTsKvProtoList() {
|
||||
TransportProtos.TsKvProto tsKvProtoAttribute1 = getTsKvProto("attribute1", "value1", TransportProtos.KeyValueType.STRING_V);
|
||||
TransportProtos.TsKvProto tsKvProtoAttribute2 = getTsKvProto("attribute2", "true", TransportProtos.KeyValueType.BOOLEAN_V);
|
||||
|
||||
@ -16,62 +16,95 @@
|
||||
package org.thingsboard.server.transport.mqtt.attributes.request;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesRequestBackwardCompatibilityIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
}
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesRequestBackwardCompatibilityIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerWithEnabledJsonCompatibility() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto",
|
||||
TransportPayloadType.PROTOBUF, null, null, null, ATTRIBUTES_SCHEMA_STR, null, null, null, null, DeviceProfileProvisionType.DISABLED, true, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesProtoSchema(ATTRIBUTES_SCHEMA_STR)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto",
|
||||
TransportPayloadType.PROTOBUF, null, null, null, ATTRIBUTES_SCHEMA_STR, null, null, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesProtoSchema(ATTRIBUTES_SCHEMA_STR)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processJsonTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerOnShortTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto",
|
||||
TransportPayloadType.PROTOBUF, null, null, null, ATTRIBUTES_SCHEMA_STR, null, null, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesProtoSchema(ATTRIBUTES_SCHEMA_STR)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_SHORT_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerOnShortProtoTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto",
|
||||
TransportPayloadType.PROTOBUF, null, null, null, ATTRIBUTES_SCHEMA_STR, null, null, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesProtoSchema(ATTRIBUTES_SCHEMA_STR)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_PROTO_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_SHORT_PROTO_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerGatewayWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto", TransportPayloadType.PROTOBUF, null, null, true, true);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.gatewayName("Gateway Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestGatewayRequestAttributesValuesFromTheServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerOnShortJsonTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto", TransportPayloadType.PROTOBUF, null, null, true, true);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.gatewayName("Gateway Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processJsonTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_JSON_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_SHORT_JSON_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@ -16,24 +16,24 @@
|
||||
package org.thingsboard.server.transport.mqtt.attributes.request;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesRequestJsonIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesRequestIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Request attribute values from the server json", "Gateway Test Request attribute values from the server json", TransportPayloadType.JSON, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server")
|
||||
.gatewayName("Gateway Test Request attribute values from the server")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -15,53 +15,27 @@
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.request;
|
||||
|
||||
import com.github.os72.protobuf.dynamic.DynamicSchema;
|
||||
import com.google.protobuf.Descriptors;
|
||||
import com.google.protobuf.DynamicMessage;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.squareup.wire.schema.internal.parser.ProtoFileElement;
|
||||
import io.netty.handler.codec.mqtt.MqttQoS;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.gen.transport.TransportApiProtos;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesRequestIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesRequestJsonIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Request attribute values from the server", "Gateway Test Request attribute values from the server", null, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server json")
|
||||
.gatewayName("Gateway Test Request attribute values from the server json")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -16,55 +16,72 @@
|
||||
package org.thingsboard.server.transport.mqtt.attributes.request;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesRequestProtoIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
}
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesRequestProtoIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServer() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto",
|
||||
TransportPayloadType.PROTOBUF, null, null, null, ATTRIBUTES_SCHEMA_STR, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesProtoSchema(ATTRIBUTES_SCHEMA_STR)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerOnShortTopic() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto",
|
||||
TransportPayloadType.PROTOBUF, null, null, null, ATTRIBUTES_SCHEMA_STR, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesProtoSchema(ATTRIBUTES_SCHEMA_STR)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_SHORT_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerOnShortProtoTopic() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto",
|
||||
TransportPayloadType.PROTOBUF, null, null, null, ATTRIBUTES_SCHEMA_STR, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesProtoSchema(ATTRIBUTES_SCHEMA_STR)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_PROTO_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_SHORT_PROTO_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerGateway() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto", TransportPayloadType.PROTOBUF, null, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.gatewayName("Gateway Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestGatewayRequestAttributesValuesFromTheServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestAttributesValuesFromTheServerOnShortJsonTopic() throws Exception {
|
||||
super.processBeforeTest("Test Request attribute values from the server proto", "Gateway Test Request attribute values from the server proto", TransportPayloadType.PROTOBUF, null, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Request attribute values from the server proto")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processJsonTestRequestAttributesValuesFromTheServer(MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_JSON_TOPIC, MqttTopics.DEVICE_ATTRIBUTES_REQUEST_SHORT_JSON_TOPIC_PREFIX);
|
||||
}
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.request.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.request.AbstractMqttAttributesRequestBackwardCompatibilityIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesRequestBackwardCompatibilityIntegrationTest extends AbstractMqttAttributesRequestBackwardCompatibilityIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.request.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.request.AbstractMqttAttributesRequestIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesRequestIntegrationTest extends AbstractMqttAttributesRequestIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.request.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.request.AbstractMqttAttributesRequestJsonIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesRequestJsonIntegrationTest extends AbstractMqttAttributesRequestJsonIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.request.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.request.AbstractMqttAttributesRequestProtoIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesRequestProtoIntegrationTest extends AbstractMqttAttributesRequestProtoIntegrationTest {
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesUpdatesBackwardCompatibilityIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubscribeToAttributesUpdatesFromServerWithEnabledJsonCompatibility() throws Exception {
|
||||
super.processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.PROTOBUF, null, null, true, false);
|
||||
processProtoTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubscribeToAttributesUpdatesFromServerWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.PROTOBUF, null, null, true, true);
|
||||
processJsonTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtoSubscribeToAttributesUpdatesFromTheServerOnShortTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.PROTOBUF, null, null, true, true);
|
||||
processProtoTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtoSubscribeToAttributesUpdatesFromTheServerOnShortJsonTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.PROTOBUF, null, null, true, true);
|
||||
processJsonTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtoSubscribeToAttributesUpdatesFromTheServerOnShortProtoTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.PROTOBUF, null, null, true, true);
|
||||
processProtoTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtoSubscribeToAttributesUpdatesFromTheServerGatewayWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.PROTOBUF, null, null, true, false);
|
||||
processProtoGatewayTestSubscribeToAttributesUpdates();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
@Slf4j
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesUpdatesBackwardCompatibilityIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testSubscribeToAttributesUpdatesFromServerWithEnabledJsonCompatibility() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processProtoTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubscribeToAttributesUpdatesFromServerWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processJsonTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtoSubscribeToAttributesUpdatesFromTheServerOnShortTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processProtoTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtoSubscribeToAttributesUpdatesFromTheServerOnShortJsonTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processJsonTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtoSubscribeToAttributesUpdatesFromTheServerOnShortProtoTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processProtoTestSubscribeToAttributesUpdates(MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtoSubscribeToAttributesUpdatesFromTheServerGatewayWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.gatewayName("Gateway Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processProtoGatewayTestSubscribeToAttributesUpdates();
|
||||
}
|
||||
|
||||
}
|
||||
@ -16,24 +16,26 @@
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesUpdatesIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesUpdatesIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.JSON, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.gatewayName("Gateway Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -16,24 +16,26 @@
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesUpdatesJsonIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesUpdatesJsonIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.JSON, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.gatewayName("Gateway Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -15,35 +15,27 @@
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.gen.transport.TransportApiProtos;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesUpdatesProtoIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesUpdatesProtoIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Subscribe to attribute updates", "Gateway Test Subscribe to attribute updates", TransportPayloadType.PROTOBUF, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Subscribe to attribute updates")
|
||||
.gatewayName("Gateway Test Subscribe to attribute updates")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.updates.AbstractMqttAttributesUpdatesBackwardCompatibilityIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesUpdatesBackwardCompatibilityIntegrationTest extends AbstractMqttAttributesUpdatesBackwardCompatibilityIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.updates.AbstractMqttAttributesUpdatesIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesUpdatesIntegrationTest extends AbstractMqttAttributesUpdatesIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.updates.AbstractMqttAttributesUpdatesJsonIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesUpdatesJsonIntegrationTest extends AbstractMqttAttributesUpdatesJsonIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.attributes.updates.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.attributes.updates.AbstractMqttAttributesUpdatesProtoIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesUpdatesProtoIntegrationTest extends AbstractMqttAttributesUpdatesProtoIntegrationTest {
|
||||
}
|
||||
@ -16,23 +16,29 @@
|
||||
package org.thingsboard.server.transport.mqtt.claim;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttClaimBackwardCompatibilityDeviceTest extends AbstractMqttClaimDeviceTest {
|
||||
@DaoSqlTest
|
||||
public class MqttClaimBackwardCompatibilityDeviceTest extends MqttClaimDeviceTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Claim device", "Test Claim gateway", TransportPayloadType.PROTOBUF, null, null, true, true);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Claim device")
|
||||
.gatewayName("Test Claim gateway")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
createCustomerAndUser();
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception { super.afterTest(); }
|
||||
|
||||
@Test
|
||||
public void testGatewayClaimingDevice() throws Exception {
|
||||
processTestGatewayClaimingDevice("Test claiming gateway device Proto", false);
|
||||
@ -24,20 +24,24 @@ import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.ClaimRequest;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.common.data.security.Authority;
|
||||
import org.thingsboard.server.dao.device.claim.ClaimResponse;
|
||||
import org.thingsboard.server.dao.device.claim.ClaimResult;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportApiProtos;
|
||||
import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttClaimDeviceTest extends AbstractMqttIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttClaimDeviceTest extends AbstractMqttIntegrationTest {
|
||||
|
||||
protected static final String CUSTOMER_USER_PASSWORD = "customerUser123!";
|
||||
|
||||
@ -46,21 +50,25 @@ public abstract class AbstractMqttClaimDeviceTest extends AbstractMqttIntegratio
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
super.processBeforeTest("Test Claim device", "Test Claim gateway", null, null, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Claim device")
|
||||
.gatewayName("Test Claim gateway")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
createCustomerAndUser();
|
||||
}
|
||||
|
||||
protected void createCustomerAndUser() throws Exception {
|
||||
Customer customer = new Customer();
|
||||
customer.setTenantId(savedTenant.getId());
|
||||
customer.setTenantId(tenantId);
|
||||
customer.setTitle("Test Claiming Customer");
|
||||
savedCustomer = doPost("/api/customer", customer, Customer.class);
|
||||
assertNotNull(savedCustomer);
|
||||
assertEquals(savedTenant.getId(), savedCustomer.getTenantId());
|
||||
assertEquals(tenantId, savedCustomer.getTenantId());
|
||||
|
||||
User user = new User();
|
||||
user.setAuthority(Authority.CUSTOMER_USER);
|
||||
user.setTenantId(savedTenant.getId());
|
||||
user.setTenantId(tenantId);
|
||||
user.setCustomerId(savedCustomer.getId());
|
||||
user.setEmail("customer@thingsboard.org");
|
||||
|
||||
@ -69,11 +77,6 @@ public abstract class AbstractMqttClaimDeviceTest extends AbstractMqttIntegratio
|
||||
assertEquals(customerAdmin.getCustomerId(), savedCustomer.getId());
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClaimingDevice() throws Exception {
|
||||
processTestClaimingDevice(false);
|
||||
@ -16,25 +16,27 @@
|
||||
package org.thingsboard.server.transport.mqtt.claim;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttClaimJsonDeviceTest extends AbstractMqttClaimDeviceTest {
|
||||
@DaoSqlTest
|
||||
public class MqttClaimJsonDeviceTest extends MqttClaimDeviceTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
super.processBeforeTest("Test Claim device", "Test Claim gateway", TransportPayloadType.JSON, null, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Claim device")
|
||||
.gatewayName("Test Claim gateway")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
createCustomerAndUser();
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.afterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClaimingDevice() throws Exception {
|
||||
processTestClaimingDevice(false);
|
||||
@ -17,24 +17,28 @@ package org.thingsboard.server.transport.mqtt.claim;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportApiProtos;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttClaimProtoDeviceTest extends AbstractMqttClaimDeviceTest {
|
||||
@DaoSqlTest
|
||||
public class MqttClaimProtoDeviceTest extends MqttClaimDeviceTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Claim device", "Test Claim gateway", TransportPayloadType.PROTOBUF, null, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Claim device")
|
||||
.gatewayName("Test Claim gateway")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
createCustomerAndUser();
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception { super.afterTest(); }
|
||||
|
||||
@Test
|
||||
public void testClaimingDevice() throws Exception {
|
||||
processTestClaimingDevice(false);
|
||||
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.claim.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.claim.AbstractMqttClaimBackwardCompatibilityDeviceTest;
|
||||
import org.thingsboard.server.transport.mqtt.claim.AbstractMqttClaimDeviceTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttClaimDeviceBackwardCompatibilityTest extends AbstractMqttClaimBackwardCompatibilityDeviceTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.claim.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.claim.AbstractMqttClaimJsonDeviceTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttClaimDeviceJsonTest extends AbstractMqttClaimJsonDeviceTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.claim.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.claim.AbstractMqttClaimProtoDeviceTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttClaimDeviceProtoTest extends AbstractMqttClaimProtoDeviceTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.claim.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.claim.AbstractMqttClaimDeviceTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttClaimDeviceTest extends AbstractMqttClaimDeviceTest {
|
||||
}
|
||||
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.credentials.sql;
|
||||
package org.thingsboard.server.transport.mqtt.credentials;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
@ -22,18 +22,13 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.common.data.security.Authority;
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentialsType;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
@ -68,21 +63,7 @@ public class BasicMqttCredentialsTest extends AbstractMqttIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
loginSysAdmin();
|
||||
|
||||
Tenant tenant = new Tenant();
|
||||
tenant.setTitle("My tenant");
|
||||
savedTenant = doPost("/api/tenant", tenant, Tenant.class);
|
||||
Assert.assertNotNull(savedTenant);
|
||||
|
||||
tenantAdmin = new User();
|
||||
tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
|
||||
tenantAdmin.setTenantId(savedTenant.getId());
|
||||
tenantAdmin.setEmail("tenant" + atomicInteger.getAndIncrement() + "@thingsboard.org");
|
||||
tenantAdmin.setFirstName("Joe");
|
||||
tenantAdmin.setLastName("Downs");
|
||||
|
||||
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
|
||||
loginTenantAdmin();
|
||||
|
||||
BasicMqttCredentials credValue = new BasicMqttCredentials();
|
||||
credValue.setClientId(CLIENT_ID);
|
||||
@ -168,11 +149,6 @@ public class BasicMqttCredentialsTest extends AbstractMqttIntegrationTest {
|
||||
client.disconnect().waitForCompletion();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
protected MqttAsyncClient getMqttAsyncClient(String clientId, String username, String password) throws MqttException {
|
||||
if (StringUtils.isEmpty(clientId)) {
|
||||
clientId = MqttAsyncClient.generateClientId();
|
||||
@ -22,10 +22,10 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallback;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
@ -37,14 +37,16 @@ import org.thingsboard.server.common.transport.util.JsonUtils;
|
||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
||||
import org.thingsboard.server.dao.device.DeviceService;
|
||||
import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttProvisionJsonDeviceTest extends AbstractMqttIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
DeviceCredentialsService deviceCredentialsService;
|
||||
@ -52,11 +54,6 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProvisioningDisabledDevice() throws Exception {
|
||||
processTestProvisioningDisabledDevice();
|
||||
@ -94,7 +91,12 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn
|
||||
|
||||
|
||||
protected void processTestProvisioningDisabledDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.JSON, null, null, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.DISABLED)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
byte[] result = createMqttClientAndPublish().getPayloadBytes();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
Assert.assertEquals("Provision data was not found!", response.get("errorMsg").getAsString());
|
||||
@ -103,15 +105,22 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn
|
||||
|
||||
|
||||
protected void processTestProvisioningCreateNewDeviceWithoutCredentials() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", "Test Provision gateway", TransportPayloadType.JSON, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
byte[] result = createMqttClientAndPublish().getPayloadBytes();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString());
|
||||
@ -119,16 +128,23 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn
|
||||
|
||||
|
||||
protected void processTestProvisioningCreateNewDeviceWithAccessToken() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", "Test Provision gateway", TransportPayloadType.JSON, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
String requestCredentials = ",\"credentialsType\": \"ACCESS_TOKEN\",\"token\": \"test_token\"";
|
||||
byte[] result = createMqttClientAndPublish(requestCredentials).getPayloadBytes();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "ACCESS_TOKEN");
|
||||
@ -138,16 +154,23 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn
|
||||
|
||||
|
||||
protected void processTestProvisioningCreateNewDeviceWithCert() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", "Test Provision gateway", TransportPayloadType.JSON, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
String requestCredentials = ",\"credentialsType\": \"X509_CERTIFICATE\",\"hash\": \"testHash\"";
|
||||
byte[] result = createMqttClientAndPublish(requestCredentials).getPayloadBytes();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "X509_CERTIFICATE");
|
||||
@ -163,16 +186,23 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn
|
||||
|
||||
|
||||
protected void processTestProvisioningCreateNewDeviceWithMqttBasic() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", "Test Provision gateway", TransportPayloadType.JSON, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
String requestCredentials = ",\"credentialsType\": \"MQTT_BASIC\",\"clientId\": \"test_clientId\",\"username\": \"test_username\",\"password\": \"test_password\"";
|
||||
byte[] result = createMqttClientAndPublish(requestCredentials).getPayloadBytes();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), "MQTT_BASIC");
|
||||
@ -188,18 +218,32 @@ public abstract class AbstractMqttProvisionJsonDeviceTest extends AbstractMqttIn
|
||||
}
|
||||
|
||||
protected void processTestProvisioningCheckPreProvisionedDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.JSON, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
byte[] result = createMqttClientAndPublish().getPayloadBytes();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), savedDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, savedDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").getAsString());
|
||||
Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").getAsString());
|
||||
}
|
||||
|
||||
protected void processTestProvisioningWithBadKeyDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.JSON, null, null, null, null, null, null, "testProvisionKeyOrig", "testProvisionSecret", DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.provisionType(DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)
|
||||
.provisionKey("testProvisionKeyOrig")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
byte[] result = createMqttClientAndPublish().getPayloadBytes();
|
||||
JsonObject response = JsonUtils.parse(new String(result)).getAsJsonObject();
|
||||
Assert.assertEquals("Provision data was not found!", response.get("errorMsg").getAsString());
|
||||
@ -21,10 +21,10 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallback;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
@ -36,7 +36,7 @@ import org.thingsboard.server.common.msg.EncryptionUtil;
|
||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
||||
import org.thingsboard.server.dao.device.DeviceService;
|
||||
import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.CredentialsDataProto;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.CredentialsType;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.ProvisionDeviceCredentialsMsg;
|
||||
@ -46,12 +46,14 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateBasicMqttCre
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
|
||||
import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttProvisionProtoDeviceTest extends AbstractMqttIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
DeviceCredentialsService deviceCredentialsService;
|
||||
@ -59,11 +61,6 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProvisioningDisabledDevice() throws Exception {
|
||||
processTestProvisioningDisabledDevice();
|
||||
@ -101,37 +98,56 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI
|
||||
|
||||
|
||||
protected void processTestProvisioningDisabledDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.DISABLED)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
ProvisionDeviceResponseMsg result = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish().getPayloadBytes());
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), result.getStatus().toString());
|
||||
}
|
||||
|
||||
protected void processTestProvisioningCreateNewDeviceWithoutCredentials() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish().getPayloadBytes());
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString());
|
||||
}
|
||||
|
||||
protected void processTestProvisioningCreateNewDeviceWithAccessToken() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null,null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CredentialsDataProto requestCredentials = CredentialsDataProto.newBuilder().setValidateDeviceTokenRequestMsg(ValidateDeviceTokenRequestMsg.newBuilder().setToken("test_token").build()).build();
|
||||
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish(createTestsProvisionMessage(CredentialsType.ACCESS_TOKEN, requestCredentials)).getPayloadBytes());
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.ACCESS_TOKEN);
|
||||
@ -140,16 +156,23 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI
|
||||
}
|
||||
|
||||
protected void processTestProvisioningCreateNewDeviceWithCert() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CredentialsDataProto requestCredentials = CredentialsDataProto.newBuilder().setValidateDeviceX509CertRequestMsg(ValidateDeviceX509CertRequestMsg.newBuilder().setHash("testHash").build()).build();
|
||||
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish(createTestsProvisionMessage(CredentialsType.X509_CERTIFICATE, requestCredentials)).getPayloadBytes());
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.X509_CERTIFICATE);
|
||||
@ -164,7 +187,14 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI
|
||||
}
|
||||
|
||||
protected void processTestProvisioningCreateNewDeviceWithMqttBasic() throws Exception {
|
||||
super.processBeforeTest("Test Provision device3", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device3")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CredentialsDataProto requestCredentials = CredentialsDataProto.newBuilder().setValidateBasicMqttCredRequestMsg(
|
||||
ValidateBasicMqttCredRequestMsg.newBuilder()
|
||||
.setClientId("test_clientId")
|
||||
@ -175,11 +205,11 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI
|
||||
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish(createTestsProvisionMessage(CredentialsType.MQTT_BASIC, requestCredentials)).getPayloadBytes());
|
||||
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(savedTenant.getTenantId(), "Test Provision device");
|
||||
Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device");
|
||||
|
||||
Assert.assertNotNull(createdDevice);
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), createdDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType(), DeviceCredentialsType.MQTT_BASIC);
|
||||
@ -195,17 +225,31 @@ public abstract class AbstractMqttProvisionProtoDeviceTest extends AbstractMqttI
|
||||
}
|
||||
|
||||
protected void processTestProvisioningCheckPreProvisionedDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, null, "testProvisionKey", "testProvisionSecret", DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)
|
||||
.provisionKey("testProvisionKey")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish().getPayloadBytes());
|
||||
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedTenant.getTenantId(), savedDevice.getId());
|
||||
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, savedDevice.getId());
|
||||
|
||||
Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.getCredentialsType().toString());
|
||||
Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.getStatus().toString());
|
||||
}
|
||||
|
||||
protected void processTestProvisioningWithBadKeyDevice() throws Exception {
|
||||
super.processBeforeTest("Test Provision device", "Test Provision gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, null, "testProvisionKeyOrig", "testProvisionSecret", DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Provision device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.provisionType(DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES)
|
||||
.provisionKey("testProvisionKeyOrig")
|
||||
.provisionSecret("testProvisionSecret")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
ProvisionDeviceResponseMsg response = ProvisionDeviceResponseMsg.parseFrom(createMqttClientAndPublish().getPayloadBytes());
|
||||
Assert.assertEquals(ProvisionResponseStatus.NOT_FOUND.name(), response.getStatus().toString());
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.provision.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.provision.AbstractMqttProvisionJsonDeviceTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttProvisionDeviceJsonTest extends AbstractMqttProvisionJsonDeviceTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.provision.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.provision.AbstractMqttProvisionProtoDeviceTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttProvisionDeviceProtoTest extends AbstractMqttProvisionProtoDeviceTest {
|
||||
}
|
||||
@ -1,94 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.rpc;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttServerSideRpcBackwardCompatibilityIntegrationTest extends AbstractMqttServerSideRpcIntegrationTest {
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttOneWayRpcWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processOneWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttOneWayRpcOnShortTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processOneWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttOneWayRpcOnShortProtoTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processOneWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_PROTO_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcWithEnabledJsonCompatibility() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, false, false);
|
||||
processProtoTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processJsonTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcOnShortTopic() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processProtoTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcOnShortProtoTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processProtoTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_PROTO_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcOnShortJsonTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processJsonTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_JSON_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayServerMqttOneWayRpcWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processProtoOneWayRpcTestGateway("Gateway Device OneWay RPC Proto");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayServerMqttTwoWayRpcWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
super.processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, true, true, false);
|
||||
processProtoTwoWayRpcTestGateway("Gateway Device TwoWay RPC Proto");
|
||||
}
|
||||
|
||||
}
|
||||
@ -54,9 +54,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* @author Valerii Sosliuk
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractMqttIntegrationTest {
|
||||
|
||||
@ -76,12 +73,7 @@ public abstract class AbstractMqttServerSideRpcIntegrationTest extends AbstractM
|
||||
|
||||
private static final String DEVICE_RESPONSE = "{\"value1\":\"A\",\"value2\":\"B\"}";
|
||||
|
||||
protected Long asyncContextTimeoutToUseRpcPlugin;
|
||||
|
||||
protected void processBeforeTest(String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic) throws Exception {
|
||||
super.processBeforeTest(deviceName, gatewayName, payloadType, telemetryTopic, attributesTopic);
|
||||
asyncContextTimeoutToUseRpcPlugin = 10000L;
|
||||
}
|
||||
protected static final Long asyncContextTimeoutToUseRpcPlugin = 10000L;
|
||||
|
||||
protected void processOneWayRpcTest(String rpcSubTopic) throws Exception {
|
||||
MqttAsyncClient client = getMqttAsyncClient(accessToken);
|
||||
|
||||
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.rpc;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
@DaoSqlTest
|
||||
public class MqttServerSideRpcBackwardCompatibilityIntegrationTest extends AbstractMqttServerSideRpcIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testServerMqttOneWayRpcWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processOneWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttOneWayRpcOnShortTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processOneWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttOneWayRpcOnShortProtoTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processOneWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_PROTO_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcWithEnabledJsonCompatibility() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processProtoTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processJsonTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcOnShortTopic() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processProtoTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcOnShortProtoTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processProtoTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_PROTO_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerMqttTwoWayRpcOnShortJsonTopicWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processJsonTwoWayRpcTest(MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_JSON_TOPIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayServerMqttOneWayRpcWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.gatewayName("RPC test gateway")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processProtoOneWayRpcTestGateway("Gateway Device OneWay RPC Proto");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayServerMqttTwoWayRpcWithEnabledJsonCompatibilityAndJsonDownlinks() throws Exception {
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.gatewayName("RPC test gateway")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.useJsonPayloadFormatForDefaultDownlinkTopics(true)
|
||||
.build();
|
||||
super.processBeforeTest(configProperties);
|
||||
processProtoTwoWayRpcTestGateway("Gateway Device TwoWay RPC Proto");
|
||||
}
|
||||
|
||||
}
|
||||
@ -17,29 +17,27 @@ package org.thingsboard.server.transport.mqtt.rpc;
|
||||
|
||||
import com.datastax.oss.driver.api.core.uuid.Uuids;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.service.security.AccessValidator;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* @author Valerii Sosliuk
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttServerSideRpcDefaultIntegrationTest extends AbstractMqttServerSideRpcIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttServerSideRpcDefaultIntegrationTest extends AbstractMqttServerSideRpcIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("RPC test device", "RPC test gateway", null, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.gatewayName("RPC test gateway")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -17,23 +17,25 @@ package org.thingsboard.server.transport.mqtt.rpc;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttServerSideRpcJsonIntegrationTest extends AbstractMqttServerSideRpcIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttServerSideRpcJsonIntegrationTest extends AbstractMqttServerSideRpcIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.JSON, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.gatewayName("RPC test gateway")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -16,24 +16,26 @@
|
||||
package org.thingsboard.server.transport.mqtt.rpc;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttServerSideRpcProtoIntegrationTest extends AbstractMqttServerSideRpcIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttServerSideRpcProtoIntegrationTest extends AbstractMqttServerSideRpcIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("RPC test device", "RPC test gateway", TransportPayloadType.PROTOBUF, null, null, null, null, null, RPC_REQUEST_PROTO_SCHEMA, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
super.processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("RPC test device")
|
||||
.gatewayName("RPC test gateway")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.rpcRequestProtoSchema(RPC_REQUEST_PROTO_SCHEMA)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.rpc.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.rpc.AbstractMqttServerSideRpcBackwardCompatibilityIntegrationTest;
|
||||
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttServerSideRpcBackwardCompatibilityIntegrationTest extends AbstractMqttServerSideRpcBackwardCompatibilityIntegrationTest {
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.rpc.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.rpc.AbstractMqttServerSideRpcDefaultIntegrationTest;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 8/22/2017.
|
||||
*/
|
||||
@DaoSqlTest
|
||||
public class MqttServerSideRpcIntegrationTest extends AbstractMqttServerSideRpcDefaultIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.rpc.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.rpc.AbstractMqttServerSideRpcJsonIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttServerSideRpcJsonIntegrationTest extends AbstractMqttServerSideRpcJsonIntegrationTest {
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.rpc.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.rpc.AbstractMqttServerSideRpcProtoIntegrationTest;
|
||||
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttServerSideRpcProtoIntegrationTest extends AbstractMqttServerSideRpcProtoIntegrationTest {
|
||||
}
|
||||
@ -19,13 +19,14 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@ -39,19 +40,19 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqttIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesIntegrationTest extends AbstractMqttIntegrationTest {
|
||||
|
||||
protected static final String PAYLOAD_VALUES_STR = "{\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4," +
|
||||
" \"key5\": {\"someNumber\": 42, \"someArray\": [1,2,3], \"someNestedObject\": {\"key\": \"value\"}}}";
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", null, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.gatewayName("Test Post Attributes gateway")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -16,28 +16,30 @@
|
||||
package org.thingsboard.server.transport.mqtt.telemetry.attributes;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesJsonIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesJsonIntegrationTest extends MqttAttributesIntegrationTest {
|
||||
|
||||
private static final String POST_DATA_ATTRIBUTES_TOPIC = "data/attributes";
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", TransportPayloadType.JSON, null, POST_DATA_ATTRIBUTES_TOPIC);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.gatewayName("Test Post Attributes gateway")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.attributesTopicFilter(POST_DATA_ATTRIBUTES_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -28,8 +28,10 @@ import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransp
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.gen.transport.TransportApiProtos;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -38,7 +40,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractMqttAttributesProtoIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesProtoIntegrationTest extends MqttAttributesIntegrationTest {
|
||||
|
||||
private static final String POST_DATA_ATTRIBUTES_TOPIC = "proto/attributes";
|
||||
|
||||
@ -50,20 +53,36 @@ public abstract class AbstractMqttAttributesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushAttributes() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", TransportPayloadType.PROTOBUF, null, POST_DATA_ATTRIBUTES_TOPIC);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesTopicFilter(POST_DATA_ATTRIBUTES_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicMessage postAttributesMsg = getDefaultDynamicMessage();
|
||||
processAttributesTest(POST_DATA_ATTRIBUTES_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postAttributesMsg.toByteArray(), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushAttributesWithEnabledJsonBackwardCompatibility() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", TransportPayloadType.PROTOBUF, null, POST_DATA_ATTRIBUTES_TOPIC, true, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesTopicFilter(POST_DATA_ATTRIBUTES_TOPIC)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processJsonPayloadAttributesTest(POST_DATA_ATTRIBUTES_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), PAYLOAD_VALUES_STR.getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushAttributesWithExplicitPresenceProtoKeys() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", TransportPayloadType.PROTOBUF, null, POST_DATA_ATTRIBUTES_TOPIC);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesTopicFilter(POST_DATA_ATTRIBUTES_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicSchema attributesSchema = getDynamicSchema();
|
||||
|
||||
DynamicMessage.Builder nestedJsonObjectBuilder = attributesSchema.newMessageBuilder("PostAttributes.JsonObject.NestedJsonObject");
|
||||
@ -96,27 +115,47 @@ public abstract class AbstractMqttAttributesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushAttributesOnShortTopic() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", TransportPayloadType.PROTOBUF, null, POST_DATA_ATTRIBUTES_TOPIC);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesTopicFilter(POST_DATA_ATTRIBUTES_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicMessage postAttributesMsg = getDefaultDynamicMessage();
|
||||
processAttributesTest(MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postAttributesMsg.toByteArray(), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushAttributesOnShortJsonTopic() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", TransportPayloadType.PROTOBUF, null, POST_DATA_ATTRIBUTES_TOPIC);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesTopicFilter(POST_DATA_ATTRIBUTES_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processJsonPayloadAttributesTest(MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), PAYLOAD_VALUES_STR.getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushAttributesOnShortProtoTopic() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", TransportPayloadType.PROTOBUF, null, POST_DATA_ATTRIBUTES_TOPIC);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.attributesTopicFilter(POST_DATA_ATTRIBUTES_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicMessage postAttributesMsg = getDefaultDynamicMessage();
|
||||
processAttributesTest(MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postAttributesMsg.toByteArray(), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushAttributesGateway() throws Exception {
|
||||
processBeforeTest("Test Post Attributes device", "Test Post Attributes gateway", TransportPayloadType.PROTOBUF, null, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Attributes device")
|
||||
.gatewayName("Test Post Attributes gateway")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
TransportApiProtos.GatewayAttributesMsg.Builder gatewayAttributesMsgProtoBuilder = TransportApiProtos.GatewayAttributesMsg.newBuilder();
|
||||
List<String> expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5");
|
||||
String deviceName1 = "Device A";
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.telemetry.attributes.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.telemetry.attributes.AbstractMqttAttributesIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesIntegrationTest extends AbstractMqttAttributesIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.telemetry.attributes.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.telemetry.attributes.AbstractMqttAttributesJsonIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesJsonIntegrationTest extends AbstractMqttAttributesJsonIntegrationTest {
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.transport.mqtt.telemetry.attributes.sql;
|
||||
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.telemetry.attributes.AbstractMqttAttributesProtoIntegrationTest;
|
||||
|
||||
@DaoSqlTest
|
||||
public class MqttAttributesProtoIntegrationTest extends AbstractMqttAttributesProtoIntegrationTest {
|
||||
}
|
||||
@ -25,13 +25,13 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttTopics;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@ -56,12 +56,11 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device", "Test Post Telemetry gateway", null, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device")
|
||||
.gatewayName("Test Post Telemetry gateway")
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -17,10 +17,10 @@ package org.thingsboard.server.transport.mqtt.telemetry.timeseries;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -36,25 +36,31 @@ public abstract class AbstractMqttTimeseriesJsonIntegrationTest extends Abstract
|
||||
private static final String POST_DATA_TELEMETRY_TOPIC = "data/telemetry";
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void beforeTest() throws Exception {
|
||||
//do nothing, processBeforeTest will be invoked in particular test methods with different parameters
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() throws Exception {
|
||||
processAfterTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetry() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
List<String> expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5");
|
||||
processJsonPayloadTelemetryTest(POST_DATA_TELEMETRY_TOPIC, expectedKeys, PAYLOAD_VALUES_STR.getBytes(), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithTs() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
String payloadStr = "{\"ts\": 10000, \"values\": " + PAYLOAD_VALUES_STR + "}";
|
||||
List<String> expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5");
|
||||
processJsonPayloadTelemetryTest(POST_DATA_TELEMETRY_TOPIC, expectedKeys, payloadStr.getBytes(), true);
|
||||
@ -62,31 +68,59 @@ public abstract class AbstractMqttTimeseriesJsonIntegrationTest extends Abstract
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryOnShortTopic() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
super.testPushTelemetryOnShortTopic();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryOnShortJsonTopic() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
super.testPushTelemetryOnShortJsonTopic();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryGateway() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.gatewayName("Test Post Telemetry gateway json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
super.testPushTelemetryGateway();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayConnect() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.gatewayName("Test Post Telemetry gateway json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
super.testGatewayConnect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithMalformedPayloadAndSendAckOnErrorEnabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null, true);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.sendAckOnValidationException(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(accessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
@ -98,7 +132,12 @@ public abstract class AbstractMqttTimeseriesJsonIntegrationTest extends Abstract
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithMalformedPayloadAndSendAckOnErrorDisabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(accessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
@ -110,7 +149,14 @@ public abstract class AbstractMqttTimeseriesJsonIntegrationTest extends Abstract
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryGatewayWithMalformedPayloadAndSendAckOnErrorEnabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null, true);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.gatewayName("Test Post Telemetry gateway json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.sendAckOnValidationException(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(gatewayAccessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
@ -122,7 +168,13 @@ public abstract class AbstractMqttTimeseriesJsonIntegrationTest extends Abstract
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryGatewayWithMalformedPayloadAndSendAckOnErrorDisabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device json payload", "Test Post Telemetry gateway json payload", TransportPayloadType.JSON, POST_DATA_TELEMETRY_TOPIC, null, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device json payload")
|
||||
.gatewayName("Test Post Telemetry gateway json payload")
|
||||
.transportPayloadType(TransportPayloadType.JSON)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(gatewayAccessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
|
||||
@ -24,7 +24,6 @@ import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||
import org.thingsboard.server.common.data.TransportPayloadType;
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration;
|
||||
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration;
|
||||
@ -33,6 +32,7 @@ import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadCo
|
||||
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration;
|
||||
import org.thingsboard.server.gen.transport.TransportApiProtos;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -57,14 +57,25 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetry() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicMessage postTelemetryMsg = getDefaultDynamicMessage();
|
||||
processTelemetryTest(POST_DATA_TELEMETRY_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postTelemetryMsg.toByteArray(), false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithEnabledJsonBackwardCompatibility() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, true, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processJsonPayloadTelemetryTest(POST_DATA_TELEMETRY_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), PAYLOAD_VALUES_STR.getBytes(), false);
|
||||
}
|
||||
|
||||
@ -95,7 +106,13 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, schemaStr, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.telemetryProtoSchema(schemaStr)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicSchema telemetrySchema = getDynamicSchema(schemaStr);
|
||||
|
||||
DynamicMessage.Builder nestedJsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject.NestedJsonObject");
|
||||
@ -140,7 +157,12 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithExplicitPresenceProtoKeys() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicSchema telemetrySchema = getDynamicSchema(DEVICE_TELEMETRY_PROTO_SCHEMA);
|
||||
|
||||
DynamicMessage.Builder nestedJsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject.NestedJsonObject");
|
||||
@ -197,7 +219,13 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, schemaStr, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.telemetryProtoSchema(schemaStr)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicSchema telemetrySchema = getDynamicSchema(schemaStr);
|
||||
|
||||
DynamicMessage.Builder nestedJsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject.NestedJsonObject");
|
||||
@ -237,27 +265,48 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryOnShortTopic() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicMessage postTelemetryMsg = getDefaultDynamicMessage();
|
||||
processTelemetryTest(MqttTopics.DEVICE_TELEMETRY_SHORT_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postTelemetryMsg.toByteArray(), false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryOnShortJsonTopic() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
processJsonPayloadTelemetryTest(MqttTopics.DEVICE_TELEMETRY_SHORT_JSON_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), PAYLOAD_VALUES_STR.getBytes(), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryOnShortProtoTopic() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
DynamicMessage postTelemetryMsg = getDefaultDynamicMessage();
|
||||
processTelemetryTest(MqttTopics.DEVICE_TELEMETRY_SHORT_PROTO_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postTelemetryMsg.toByteArray(), false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryGateway() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, null, null, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.gatewayName("Test Post Telemetry gateway proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
TransportApiProtos.GatewayTelemetryMsg.Builder gatewayTelemetryMsgProtoBuilder = TransportApiProtos.GatewayTelemetryMsg.newBuilder();
|
||||
List<String> expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5");
|
||||
String deviceName1 = "Device A";
|
||||
@ -271,7 +320,13 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testGatewayConnect() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED, false, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.gatewayName("Test Post Telemetry gateway proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
String deviceName = "Device A";
|
||||
TransportApiProtos.ConnectMsg connectMsgProto = getConnectProto(deviceName);
|
||||
MqttAsyncClient client = getMqttAsyncClient(gatewayAccessToken);
|
||||
@ -287,7 +342,13 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithMalformedPayloadAndSendAckOnErrorEnabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, true);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.sendAckOnValidationException(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(accessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
@ -299,7 +360,12 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithMalformedPayloadAndSendAckOnErrorDisabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(accessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
@ -311,7 +377,14 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithMalformedPayloadAndSendAckOnErrorEnabledAndBackwardCompatibilityEnabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device", "Test Post Telemetry gateway", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, true, false, true);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.sendAckOnValidationException(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(accessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
@ -323,7 +396,13 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryWithMalformedPayloadAndSendAckOnErrorDisabledAndBackwardCompatibilityEnabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device", "Test Post Telemetry gateway", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, true, false, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.enableCompatibilityWithJsonPayloadFormat(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(accessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
@ -335,7 +414,14 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryGatewayWithMalformedPayloadAndSendAckOnErrorEnabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, true);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.gatewayName("Test Post Telemetry gateway proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.sendAckOnValidationException(true)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(gatewayAccessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
@ -347,7 +433,13 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac
|
||||
|
||||
@Test
|
||||
public void testPushTelemetryGatewayWithMalformedPayloadAndSendAckOnErrorDisabled() throws Exception {
|
||||
processBeforeTest("Test Post Telemetry device proto payload", "Test Post Telemetry gateway proto payload", TransportPayloadType.PROTOBUF, POST_DATA_TELEMETRY_TOPIC, null, false);
|
||||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder()
|
||||
.deviceName("Test Post Telemetry device proto payload")
|
||||
.gatewayName("Test Post Telemetry gateway proto payload")
|
||||
.transportPayloadType(TransportPayloadType.PROTOBUF)
|
||||
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC)
|
||||
.build();
|
||||
processBeforeTest(configProperties);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MqttAsyncClient client = getMqttAsyncClient(gatewayAccessToken);
|
||||
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch);
|
||||
|
||||
@ -18,9 +18,6 @@ package org.thingsboard.server.transport.mqtt.telemetry.timeseries.nosql;
|
||||
import org.thingsboard.server.dao.service.DaoNoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 8/22/2017.
|
||||
*/
|
||||
@DaoNoSqlTest
|
||||
public class MqttTimeseriesNoSqlIntegrationTest extends AbstractMqttTimeseriesIntegrationTest {
|
||||
}
|
||||
|
||||
@ -18,9 +18,6 @@ package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 8/22/2017.
|
||||
*/
|
||||
@DaoSqlTest
|
||||
public class MqttTimeseriesSqlIntegrationTest extends AbstractMqttTimeseriesIntegrationTest {
|
||||
}
|
||||
|
||||
@ -18,9 +18,6 @@ package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 8/22/2017.
|
||||
*/
|
||||
@DaoSqlTest
|
||||
public class MqttTimeseriesSqlJsonIntegrationTest extends AbstractMqttTimeseriesJsonIntegrationTest {
|
||||
}
|
||||
|
||||
@ -18,9 +18,6 @@ package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 8/22/2017.
|
||||
*/
|
||||
@DaoSqlTest
|
||||
public class MqttTimeseriesSqlProtoIntegrationTest extends AbstractMqttTimeseriesProtoIntegrationTest {
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user