Browse Source

refactoring

pull/8803/head
dashevchenko 3 years ago
parent
commit
5acd5b3658
  1. 6
      application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java
  2. 14
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

6
application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java

@ -662,11 +662,11 @@ public class DeviceControllerTest extends AbstractControllerTest {
doGet("/api/device/" + savedDevice.getId().getId() + "/credentials", DeviceCredentials.class);
assertThat(commands).hasSize(3);
assertThat(commands).containsExactly(String.format("mosquitto_pub -d -q 1 -h localhost -t v1/devices/me/telemetry -u %s -m \"{temperature:15}\"",
assertThat(commands).containsExactly(String.format("mosquitto_pub -d -q 1 -h localhost -t v1/devices/me/telemetry -u %s -m \"{temperature:25}\"",
credentials.getCredentialsId()),
String.format("curl -v -X POST http://localhost:80/api/v1/%s/telemetry --header Content-Type:application/json --data \"{temperature:16}\"",
String.format("curl -v -X POST http://localhost:80/api/v1/%s/telemetry --header Content-Type:application/json --data \"{temperature:25}\"",
credentials.getCredentialsId()),
String.format("echo -n \"{temperature:17}\" | coap-client -m post coap://localhost:5683/api/v1/%s/telemetry -f-",
String.format("echo -n \"{temperature:25}\" | coap-client -m post coap://localhost:5683/api/v1/%s/telemetry -f-",
credentials.getCredentialsId()));
}

14
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -103,6 +103,8 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
public static final String INCORRECT_CUSTOMER_ID = "Incorrect customerId ";
public static final String INCORRECT_DEVICE_ID = "Incorrect deviceId ";
public static final String INCORRECT_EDGE_ID = "Incorrect edgeId ";
public static final String PAYLOAD = "\"{temperature:25}\"";
@Autowired
private DeviceDao deviceDao;
@ -146,15 +148,15 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
case DEFAULT:
switch (credentialsType) {
case ACCESS_TOKEN:
commands.add(getMqttAccessTokenCommand(hostname, deviceCredentials) + " -m \"{temperature:15}\"");
commands.add(getMqttAccessTokenCommand(hostname, deviceCredentials) + " -m " + PAYLOAD);
commands.add(getHttpAccessTokenCommand(baseUrl, deviceCredentials));
commands.add("echo -n \"{temperature:17}\" | " + getCoapAccessTokenCommand(hostname, deviceCredentials) + " -f-");
commands.add("echo -n " + PAYLOAD + " | " + getCoapAccessTokenCommand(hostname, deviceCredentials) + " -f-");
break;
case MQTT_BASIC:
commands.add(getMqttBasicPublishCommand(hostname, deviceCredentials) + " -m \"{temperature:18}\"");
commands.add(getMqttBasicPublishCommand(hostname, deviceCredentials) + " -m " + PAYLOAD);
break;
case X509_CERTIFICATE:
commands.add(getMqttX509Command(hostname) + " -m \"{temperature:19}\"");
commands.add(getMqttX509Command(hostname) + " -m " + PAYLOAD);
break;
}
break;
@ -162,7 +164,7 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
MqttDeviceProfileTransportConfiguration transportConfiguration =
(MqttDeviceProfileTransportConfiguration) deviceProfile.getProfileData().getTransportConfiguration();
TransportPayloadType payloadType = transportConfiguration.getTransportPayloadTypeConfiguration().getTransportPayloadType();
String payload = (payloadType == TransportPayloadType.PROTOBUF) ? " -f protobufFileName" : " -m \"{temperature:25}\"";
String payload = (payloadType == TransportPayloadType.PROTOBUF) ? " -f protobufFileName" : " -m " + PAYLOAD;
switch (credentialsType) {
case ACCESS_TOKEN:
commands.add(getMqttAccessTokenCommand(hostname, deviceCredentials) + payload);
@ -751,7 +753,7 @@ public class DeviceServiceImpl extends AbstractCachedEntityService<DeviceCacheKe
}
private String getHttpAccessTokenCommand(String baseurl, DeviceCredentials deviceCredentials) {
return String.format("curl -v -X POST %s/api/v1/%s/telemetry --header Content-Type:application/json --data \"{temperature:16}\"", baseurl, deviceCredentials.getCredentialsId());
return String.format("curl -v -X POST %s/api/v1/%s/telemetry --header Content-Type:application/json --data " + PAYLOAD, baseurl, deviceCredentials.getCredentialsId());
}
private String getMqttAccessTokenCommand(String hostname, DeviceCredentials deviceCredentials) {

Loading…
Cancel
Save