|
|
|
@ -664,6 +664,101 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest { |
|
|
|
credentials.getCredentialsId())); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFetchPublishTelemetryCommandsForDefaultDeviceIfPortsAndHostsNull() throws Exception { |
|
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
ObjectNode config = JacksonUtil.newObjectNode(); |
|
|
|
|
|
|
|
ObjectNode http = JacksonUtil.newObjectNode(); |
|
|
|
http.put("enabled", true); |
|
|
|
http.set("host", null); |
|
|
|
http.set("port", null); |
|
|
|
config.set("http", http); |
|
|
|
|
|
|
|
ObjectNode https = JacksonUtil.newObjectNode(); |
|
|
|
https.put("enabled", true); |
|
|
|
https.set("host", null); |
|
|
|
https.set("port", null); |
|
|
|
config.set("https", https); |
|
|
|
|
|
|
|
ObjectNode mqtt = JacksonUtil.newObjectNode(); |
|
|
|
mqtt.put("enabled", true); |
|
|
|
mqtt.set("host", null); |
|
|
|
mqtt.set("port", null); |
|
|
|
config.set("mqtt", mqtt); |
|
|
|
|
|
|
|
ObjectNode mqtts = JacksonUtil.newObjectNode(); |
|
|
|
mqtts.put("enabled", true); |
|
|
|
mqtts.set("host", null); |
|
|
|
mqtts.set("port", null); |
|
|
|
config.set("mqtts", mqtts); |
|
|
|
|
|
|
|
ObjectNode coap = JacksonUtil.newObjectNode(); |
|
|
|
coap.put("enabled", true); |
|
|
|
coap.set("host", null); |
|
|
|
coap.set("port", null); |
|
|
|
config.set("coap", coap); |
|
|
|
|
|
|
|
ObjectNode coaps = JacksonUtil.newObjectNode(); |
|
|
|
coaps.put("enabled", true); |
|
|
|
coaps.set("host", null); |
|
|
|
coaps.set("port", null); |
|
|
|
config.set("coaps", coaps); |
|
|
|
|
|
|
|
AdminSettings adminSettings = doGet("/api/admin/settings/connectivity", AdminSettings.class); |
|
|
|
adminSettings.setJsonValue(config); |
|
|
|
doPost("/api/admin/settings", adminSettings).andExpect(status().isOk()); |
|
|
|
|
|
|
|
login("tenant2@thingsboard.org", "testPassword1"); |
|
|
|
|
|
|
|
Device device = new Device(); |
|
|
|
device.setName("My device"); |
|
|
|
device.setType("default"); |
|
|
|
Device savedDevice = doPost("/api/device", device, Device.class); |
|
|
|
JsonNode commands = |
|
|
|
doGetTyped("/api/device-connectivity/" + savedDevice.getId().getId(), new TypeReference<>() { |
|
|
|
}); |
|
|
|
|
|
|
|
DeviceCredentials credentials = |
|
|
|
doGet("/api/device/" + savedDevice.getId().getId() + "/credentials", DeviceCredentials.class); |
|
|
|
|
|
|
|
assertThat(commands).hasSize(3); |
|
|
|
JsonNode httpCommands = commands.get(HTTP); |
|
|
|
assertThat(httpCommands.get(HTTP).asText()).isEqualTo(String.format("curl -v -X POST http://localhost/api/v1/%s/telemetry " + |
|
|
|
"--header Content-Type:application/json --data \"{temperature:25}\"", |
|
|
|
credentials.getCredentialsId())); |
|
|
|
assertThat(httpCommands.get(HTTPS).asText()).isEqualTo(String.format("curl -v -X POST https://localhost/api/v1/%s/telemetry " + |
|
|
|
"--header Content-Type:application/json --data \"{temperature:25}\"", |
|
|
|
credentials.getCredentialsId())); |
|
|
|
|
|
|
|
JsonNode mqttCommands = commands.get(MQTT); |
|
|
|
assertThat(mqttCommands.get(MQTT).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 -h localhost -t v1/devices/me/telemetry " + |
|
|
|
"-u \"%s\" -m \"{temperature:25}\"", credentials.getCredentialsId())); |
|
|
|
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 " + |
|
|
|
"-t v1/devices/me/telemetry -u \"%s\" -m \"{temperature:25}\"", credentials.getCredentialsId())); |
|
|
|
|
|
|
|
JsonNode 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" + |
|
|
|
" -t v1/devices/me/telemetry -u \"%s\" -m \"{temperature:25}\"", credentials.getCredentialsId())); |
|
|
|
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 -t v1/devices/me/telemetry -u \"%s\" -m \"{temperature:25}\"\"", credentials.getCredentialsId())); |
|
|
|
|
|
|
|
JsonNode linuxCoapCommands = commands.get(COAP); |
|
|
|
assertThat(linuxCoapCommands.get(COAP).asText()).isEqualTo(String.format("coap-client -v 6 -m POST coap://localhost/api/v1/%s/telemetry " + |
|
|
|
"-t json -e \"{temperature:25}\"", credentials.getCredentialsId())); |
|
|
|
assertThat(linuxCoapCommands.get(COAPS).asText()).isEqualTo(String.format("coap-client-openssl -v 6 -m POST coaps://localhost/api/v1/%s/telemetry" + |
|
|
|
" -t json -e \"{temperature:25}\"", credentials.getCredentialsId())); |
|
|
|
|
|
|
|
JsonNode dockerCoapCommands = commands.get(COAP).get(DOCKER); |
|
|
|
assertThat(dockerCoapCommands.get(COAP).asText()).isEqualTo(String.format("docker run --rm -it --add-host=host.docker.internal:host-gateway" + |
|
|
|
" thingsboard/coap-clients coap-client -v 6 -m POST coap://host.docker.internal/api/v1/%s/telemetry -t json -e \"{temperature:25}\"", credentials.getCredentialsId())); |
|
|
|
assertThat(dockerCoapCommands.get(COAPS).asText()).isEqualTo(String.format("docker run --rm -it --add-host=host.docker.internal:host-gateway" + |
|
|
|
" thingsboard/coap-clients coap-client-openssl -v 6 -m POST coaps://host.docker.internal/api/v1/%s/telemetry -t json -e \"{temperature:25}\"", credentials.getCredentialsId())); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFetchPublishTelemetryCommandsForDefaultDeviceIfHostIsNotLocalhost() throws Exception { |
|
|
|
loginSysAdmin(); |
|
|
|
|