fixed mqtt basic connectivity command
This commit is contained in:
parent
a8dee2643b
commit
b72c08d988
@ -462,8 +462,7 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
basicMqttCredentials.setUserName(userName);
|
||||
basicMqttCredentials.setPassword(password);
|
||||
credentials.setCredentialsValue(JacksonUtil.toString(basicMqttCredentials));
|
||||
doPost("/api/device/credentials", credentials)
|
||||
.andExpect(status().isOk());
|
||||
credentials = doPost("/api/device/credentials", credentials, DeviceCredentials.class);
|
||||
|
||||
JsonNode commands =
|
||||
doGetTyped("/api/device-connectivity/" + savedDevice.getId().getId(), new TypeReference<>() {
|
||||
@ -485,6 +484,33 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
"/bin/sh -c \"curl -f -S -o " + CA_ROOT_CERT_PEM + " http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile " + CA_ROOT_CERT_PEM + " -h host.docker.internal -p 8883 -t %s -i \"%s\" -u \"%s\" -P \"%s\" -m \"{temperature:25}\"\"",
|
||||
DEVICE_TELEMETRY_TOPIC, clientId, userName, password));
|
||||
|
||||
basicMqttCredentials.setClientId("");
|
||||
credentials.setCredentialsValue(JacksonUtil.toString(basicMqttCredentials));
|
||||
|
||||
doPost("/api/device/credentials", credentials)
|
||||
.andExpect(status().isOk());
|
||||
|
||||
commands =
|
||||
doGetTyped("/api/device-connectivity/" + savedDevice.getId().getId(), new TypeReference<>() {
|
||||
});
|
||||
assertThat(commands).hasSize(1);
|
||||
|
||||
mqttCommands = commands.get(MQTT);
|
||||
assertThat(mqttCommands.get(MQTT).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 -h localhost -p 1883 -t %s " +
|
||||
"-u \"%s\" -P \"%s\" -m \"{temperature:25}\"", DEVICE_TELEMETRY_TOPIC, userName, password));
|
||||
assertThat(mqttCommands.get(MQTTS).get(0).asText()).isEqualTo("curl -f -S -o " + CA_ROOT_CERT_PEM + " http://localhost:80/api/device-connectivity/mqtts/certificate/download");
|
||||
assertThat(mqttCommands.get(MQTTS).get(1).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 --cafile " + CA_ROOT_CERT_PEM + " -h localhost -p 8883 " +
|
||||
"-t %s -u \"%s\" -P \"%s\" -m \"{temperature:25}\"", DEVICE_TELEMETRY_TOPIC, userName, password));
|
||||
|
||||
dockerMqttCommands = commands.get(MQTT).get(DOCKER);
|
||||
assertThat(dockerMqttCommands.get(MQTT).asText()).isEqualTo(String.format("docker run --rm -it --add-host=host.docker.internal:host-gateway thingsboard/mosquitto-clients mosquitto_pub -d -q 1 -h host.docker.internal" +
|
||||
" -p 1883 -t %s -u \"%s\" -P \"%s\" -m \"{temperature:25}\"",
|
||||
DEVICE_TELEMETRY_TOPIC, userName, password));
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it --add-host=host.docker.internal:host-gateway thingsboard/mosquitto-clients " +
|
||||
"/bin/sh -c \"curl -f -S -o " + CA_ROOT_CERT_PEM + " http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile " + CA_ROOT_CERT_PEM + " -h host.docker.internal -p 8883 -t %s -u \"%s\" -P \"%s\" -m \"{temperature:25}\"\"",
|
||||
DEVICE_TELEMETRY_TOPIC, userName, password));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -72,13 +72,13 @@ public class DeviceConnectivityUtil {
|
||||
BasicMqttCredentials credentials = JacksonUtil.fromString(deviceCredentials.getCredentialsValue(),
|
||||
BasicMqttCredentials.class);
|
||||
if (credentials != null) {
|
||||
if (credentials.getClientId() != null) {
|
||||
if (StringUtils.isNotEmpty(credentials.getClientId())) {
|
||||
command.append(" -i \"").append(credentials.getClientId()).append("\"");
|
||||
}
|
||||
if (credentials.getUserName() != null) {
|
||||
if (StringUtils.isNotEmpty(credentials.getUserName())) {
|
||||
command.append(" -u \"").append(credentials.getUserName()).append("\"");
|
||||
}
|
||||
if (credentials.getPassword() != null) {
|
||||
if (StringUtils.isNotEmpty(credentials.getPassword())) {
|
||||
command.append(" -P \"").append(credentials.getPassword()).append("\"");
|
||||
}
|
||||
} else {
|
||||
@ -129,13 +129,13 @@ public class DeviceConnectivityUtil {
|
||||
BasicMqttCredentials credentials = JacksonUtil.fromString(deviceCredentials.getCredentialsValue(),
|
||||
BasicMqttCredentials.class);
|
||||
if (credentials != null) {
|
||||
if (credentials.getClientId() != null) {
|
||||
if (StringUtils.isNotEmpty(credentials.getClientId())) {
|
||||
dockerComposeBuilder.append(" - clientId=").append(credentials.getClientId()).append("\n");
|
||||
}
|
||||
if (credentials.getUserName() != null) {
|
||||
if (StringUtils.isNotEmpty(credentials.getUserName())) {
|
||||
dockerComposeBuilder.append(" - username=").append(credentials.getUserName()).append("\n");
|
||||
}
|
||||
if (credentials.getPassword() != null) {
|
||||
if (StringUtils.isNotEmpty(credentials.getPassword())) {
|
||||
dockerComposeBuilder.append(" - password=").append(credentials.getPassword()).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user