|
|
|
@ -21,6 +21,7 @@ import org.testng.annotations.AfterMethod; |
|
|
|
import org.testng.annotations.BeforeMethod; |
|
|
|
import org.testng.annotations.Test; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.AttributeScope; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
|
import org.thingsboard.server.common.data.DeviceProfileProvisionType; |
|
|
|
@ -28,6 +29,8 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; |
|
|
|
import org.thingsboard.server.msa.AbstractCoapClientTest; |
|
|
|
import org.thingsboard.server.msa.DisableUIListeners; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.thingsboard.server.msa.prototypes.DevicePrototypes.defaultDevicePrototype; |
|
|
|
|
|
|
|
@ -52,18 +55,27 @@ public class CoapClientTest extends AbstractCoapClientTest{ |
|
|
|
DeviceProfile deviceProfile = testRestClient.getDeviceProfileById(device.getDeviceProfileId()); |
|
|
|
deviceProfile = updateDeviceProfileWithProvisioningStrategy(deviceProfile, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES); |
|
|
|
|
|
|
|
DeviceCredentials expectedDeviceCredentials = testRestClient.getDeviceCredentialsByDeviceId(device.getId()); |
|
|
|
DeviceCredentials deviceCreds = testRestClient.getDeviceCredentialsByDeviceId(device.getId()); |
|
|
|
|
|
|
|
JsonNode provisionResponse = JacksonUtil.fromBytes(createCoapClientAndPublish(device.getName())); |
|
|
|
|
|
|
|
assertThat(provisionResponse.get("credentialsType").asText()).isEqualTo(expectedDeviceCredentials.getCredentialsType().name()); |
|
|
|
assertThat(provisionResponse.get("credentialsValue").asText()).isEqualTo(expectedDeviceCredentials.getCredentialsId()); |
|
|
|
assertThat(provisionResponse.get("credentialsType").asText()).isEqualTo(deviceCreds.getCredentialsType().name()); |
|
|
|
assertThat(provisionResponse.get("credentialsValue").asText()).isEqualTo(deviceCreds.getCredentialsId()); |
|
|
|
assertThat(provisionResponse.get("status").asText()).isEqualTo("SUCCESS"); |
|
|
|
|
|
|
|
JsonNode attributes = testRestClient.getAttributes(device.getId(), AttributeScope.SERVER_SCOPE, "provisionState"); |
|
|
|
assertThat(attributes.get(0).get("value").asText()).isEqualTo("provisioned"); |
|
|
|
|
|
|
|
// provision second time should fail
|
|
|
|
JsonNode provisionResponse2 = JacksonUtil.fromBytes(createCoapClientAndPublish(device.getName())); |
|
|
|
assertThat(provisionResponse2.get("status").asText()).isEqualTo("FAILURE"); |
|
|
|
|
|
|
|
// update provision attribute to non-valid value
|
|
|
|
testRestClient.postTelemetryAttribute(device.getId(), AttributeScope.SERVER_SCOPE.name(), JacksonUtil.valueToTree(Map.of("provisionState", "non-valid"))); |
|
|
|
|
|
|
|
JsonNode provisionResponse3 = JacksonUtil.fromBytes(createCoapClientAndPublish(device.getName())); |
|
|
|
assertThat(provisionResponse3.get("status").asText()).isEqualTo("FAILURE"); |
|
|
|
|
|
|
|
updateDeviceProfileWithProvisioningStrategy(deviceProfile, DeviceProfileProvisionType.DISABLED); |
|
|
|
} |
|
|
|
|
|
|
|
|