Added tests for provisioning for HTTP transport
This commit is contained in:
parent
a408da6d78
commit
344a45062a
@ -26,7 +26,14 @@ import org.apache.http.ssl.SSLContexts;
|
|||||||
import org.testng.annotations.AfterSuite;
|
import org.testng.annotations.AfterSuite;
|
||||||
import org.testng.annotations.BeforeSuite;
|
import org.testng.annotations.BeforeSuite;
|
||||||
import org.testng.annotations.Listeners;
|
import org.testng.annotations.Listeners;
|
||||||
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
|
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
|
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.DeviceProfileData;
|
||||||
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileProvisionConfiguration;
|
||||||
|
import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
|
||||||
import org.thingsboard.server.common.data.id.DeviceId;
|
import org.thingsboard.server.common.data.id.DeviceId;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@ -37,6 +44,9 @@ import java.util.Random;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Listeners(TestListener.class)
|
@Listeners(TestListener.class)
|
||||||
public abstract class AbstractContainerTest {
|
public abstract class AbstractContainerTest {
|
||||||
|
|
||||||
|
protected final static String TEST_PROVISION_DEVICE_KEY = "test_provision_key";
|
||||||
|
protected final static String TEST_PROVISION_DEVICE_SECRET = "test_provision_secret";
|
||||||
protected static long timeoutMultiplier = 1;
|
protected static long timeoutMultiplier = 1;
|
||||||
protected ObjectMapper mapper = new ObjectMapper();
|
protected ObjectMapper mapper = new ObjectMapper();
|
||||||
private static final ContainerTestSuite containerTestSuite = ContainerTestSuite.getInstance();
|
private static final ContainerTestSuite containerTestSuite = ContainerTestSuite.getInstance();
|
||||||
@ -150,4 +160,28 @@ public abstract class AbstractContainerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected DeviceProfile updateDeviceProfileWithProvisioningStrategy(DeviceProfile deviceProfile, DeviceProfileProvisionType provisionType) {
|
||||||
|
DeviceProfileProvisionConfiguration provisionConfiguration;
|
||||||
|
String testProvisionDeviceKey = TEST_PROVISION_DEVICE_KEY;
|
||||||
|
deviceProfile.setProvisionType(provisionType);
|
||||||
|
switch(provisionType) {
|
||||||
|
case ALLOW_CREATE_NEW_DEVICES:
|
||||||
|
provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(TEST_PROVISION_DEVICE_SECRET);
|
||||||
|
break;
|
||||||
|
case CHECK_PRE_PROVISIONED_DEVICES:
|
||||||
|
provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(TEST_PROVISION_DEVICE_SECRET);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case DISABLED:
|
||||||
|
testProvisionDeviceKey = null;
|
||||||
|
provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DeviceProfileData deviceProfileData = deviceProfile.getProfileData();
|
||||||
|
deviceProfileData.setProvisionConfiguration(provisionConfiguration);
|
||||||
|
deviceProfile.setProfileData(deviceProfileData);
|
||||||
|
deviceProfile.setProvisionDeviceKey(testProvisionDeviceKey);
|
||||||
|
return testRestClient.postDeviceProfile(deviceProfile);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -170,6 +170,14 @@ public class TestRestClient {
|
|||||||
.as(JsonNode.class);
|
.as(JsonNode.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JsonPath postProvisionRequest(String provisionRequest) {
|
||||||
|
return given().spec(requestSpec)
|
||||||
|
.body(provisionRequest)
|
||||||
|
.post("/api/v1/provision")
|
||||||
|
.getBody()
|
||||||
|
.jsonPath();
|
||||||
|
}
|
||||||
|
|
||||||
public PageData<RuleChain> getRuleChains(PageLink pageLink) {
|
public PageData<RuleChain> getRuleChains(PageLink pageLink) {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
addPageLinkToParam(params, pageLink);
|
addPageLinkToParam(params, pageLink);
|
||||||
|
|||||||
@ -16,10 +16,14 @@
|
|||||||
package org.thingsboard.server.msa.connectivity;
|
package org.thingsboard.server.msa.connectivity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import io.restassured.path.json.JsonPath;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.thingsboard.server.common.data.Device;
|
import org.thingsboard.server.common.data.Device;
|
||||||
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
|
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||||
import org.thingsboard.server.msa.AbstractContainerTest;
|
import org.thingsboard.server.msa.AbstractContainerTest;
|
||||||
import org.thingsboard.server.msa.WsClient;
|
import org.thingsboard.server.msa.WsClient;
|
||||||
@ -69,8 +73,8 @@ public class HttpClientTest extends AbstractContainerTest {
|
|||||||
String accessToken = testRestClient.getDeviceCredentialsByDeviceId(device.getId()).getCredentialsId();
|
String accessToken = testRestClient.getDeviceCredentialsByDeviceId(device.getId()).getCredentialsId();
|
||||||
assertThat(accessToken).isNotNull();
|
assertThat(accessToken).isNotNull();
|
||||||
|
|
||||||
JsonNode sharedAattribute = mapper.readTree(createPayload().toString());
|
JsonNode sharedAttribute = mapper.readTree(createPayload().toString());
|
||||||
testRestClient.postTelemetryAttribute(DEVICE, device.getId(), SHARED_SCOPE, sharedAattribute);
|
testRestClient.postTelemetryAttribute(DEVICE, device.getId(), SHARED_SCOPE, sharedAttribute);
|
||||||
|
|
||||||
JsonNode clientAttribute = mapper.readTree(createPayload().toString());
|
JsonNode clientAttribute = mapper.readTree(createPayload().toString());
|
||||||
testRestClient.postAttribute(accessToken, clientAttribute);
|
testRestClient.postAttribute(accessToken, clientAttribute);
|
||||||
@ -78,11 +82,11 @@ public class HttpClientTest extends AbstractContainerTest {
|
|||||||
TimeUnit.SECONDS.sleep(3 * timeoutMultiplier);
|
TimeUnit.SECONDS.sleep(3 * timeoutMultiplier);
|
||||||
|
|
||||||
JsonNode attributes = testRestClient.getAttributes(accessToken, null, null);
|
JsonNode attributes = testRestClient.getAttributes(accessToken, null, null);
|
||||||
assertThat(attributes.get("shared")).isEqualTo(sharedAattribute);
|
assertThat(attributes.get("shared")).isEqualTo(sharedAttribute);
|
||||||
assertThat(attributes.get("client")).isEqualTo(clientAttribute);
|
assertThat(attributes.get("client")).isEqualTo(clientAttribute);
|
||||||
|
|
||||||
JsonNode attributes2 = testRestClient.getAttributes(accessToken, null, "stringKey");
|
JsonNode attributes2 = testRestClient.getAttributes(accessToken, null, "stringKey");
|
||||||
assertThat(attributes2.get("shared").get("stringKey")).isEqualTo(sharedAattribute.get("stringKey"));
|
assertThat(attributes2.get("shared").get("stringKey")).isEqualTo(sharedAttribute.get("stringKey"));
|
||||||
assertThat(attributes2.has("client")).isFalse();
|
assertThat(attributes2.has("client")).isFalse();
|
||||||
|
|
||||||
JsonNode attributes3 = testRestClient.getAttributes(accessToken, "longKey,stringKey", null);
|
JsonNode attributes3 = testRestClient.getAttributes(accessToken, "longKey,stringKey", null);
|
||||||
@ -91,4 +95,78 @@ public class HttpClientTest extends AbstractContainerTest {
|
|||||||
assertThat(attributes3.get("client").get("longKey")).isEqualTo(clientAttribute.get("longKey"));
|
assertThat(attributes3.get("client").get("longKey")).isEqualTo(clientAttribute.get("longKey"));
|
||||||
assertThat(attributes3.get("client").get("stringKey")).isEqualTo(clientAttribute.get("stringKey"));
|
assertThat(attributes3.get("client").get("stringKey")).isEqualTo(clientAttribute.get("stringKey"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void provisionRequestForDeviceWithPreProvisionedStrategy() throws Exception {
|
||||||
|
|
||||||
|
DeviceProfile deviceProfile = testRestClient.getDeviceProfileById(device.getDeviceProfileId());
|
||||||
|
deviceProfile = updateDeviceProfileWithProvisioningStrategy(deviceProfile, DeviceProfileProvisionType.CHECK_PRE_PROVISIONED_DEVICES);
|
||||||
|
|
||||||
|
DeviceCredentials expectedDeviceCredentials = testRestClient.getDeviceCredentialsByDeviceId(device.getId());
|
||||||
|
|
||||||
|
JsonObject provisionRequest = new JsonObject();
|
||||||
|
provisionRequest.addProperty("provisionDeviceKey", TEST_PROVISION_DEVICE_KEY);
|
||||||
|
provisionRequest.addProperty("provisionDeviceSecret", TEST_PROVISION_DEVICE_SECRET);
|
||||||
|
provisionRequest.addProperty("deviceName", device.getName());
|
||||||
|
|
||||||
|
JsonPath provisionResponse = testRestClient.postProvisionRequest(provisionRequest.toString());
|
||||||
|
|
||||||
|
String credentialsType = provisionResponse.get("credentialsType");
|
||||||
|
String credentialsValue = provisionResponse.get("credentialsValue");
|
||||||
|
String status = provisionResponse.get("status");
|
||||||
|
|
||||||
|
assertThat(credentialsType).isEqualTo(expectedDeviceCredentials.getCredentialsType().name());
|
||||||
|
assertThat(credentialsValue).isEqualTo(expectedDeviceCredentials.getCredentialsId());
|
||||||
|
assertThat(status).isEqualTo("SUCCESS");
|
||||||
|
|
||||||
|
updateDeviceProfileWithProvisioningStrategy(deviceProfile, DeviceProfileProvisionType.DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void provisionRequestForDeviceWithAllowToCreateNewDevicesStrategy() throws Exception {
|
||||||
|
|
||||||
|
String testDeviceName = "test_provision_device";
|
||||||
|
|
||||||
|
DeviceProfile deviceProfile = testRestClient.getDeviceProfileById(device.getDeviceProfileId());
|
||||||
|
|
||||||
|
deviceProfile = updateDeviceProfileWithProvisioningStrategy(deviceProfile, DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES);
|
||||||
|
|
||||||
|
JsonObject provisionRequest = new JsonObject();
|
||||||
|
provisionRequest.addProperty("provisionDeviceKey", TEST_PROVISION_DEVICE_KEY);
|
||||||
|
provisionRequest.addProperty("provisionDeviceSecret", TEST_PROVISION_DEVICE_SECRET);
|
||||||
|
provisionRequest.addProperty("deviceName", testDeviceName);
|
||||||
|
|
||||||
|
JsonPath provisionResponse = testRestClient.postProvisionRequest(provisionRequest.toString());
|
||||||
|
|
||||||
|
String credentialsType = provisionResponse.get("credentialsType");
|
||||||
|
String credentialsValue = provisionResponse.get("credentialsValue");
|
||||||
|
String status = provisionResponse.get("status");
|
||||||
|
|
||||||
|
testRestClient.deleteDeviceIfExists(device.getId());
|
||||||
|
device = testRestClient.getDeviceByName(testDeviceName);
|
||||||
|
|
||||||
|
DeviceCredentials expectedDeviceCredentials = testRestClient.getDeviceCredentialsByDeviceId(device.getId());
|
||||||
|
|
||||||
|
assertThat(credentialsType).isEqualTo(expectedDeviceCredentials.getCredentialsType().name());
|
||||||
|
assertThat(credentialsValue).isEqualTo(expectedDeviceCredentials.getCredentialsId());
|
||||||
|
assertThat(status).isEqualTo("SUCCESS");
|
||||||
|
|
||||||
|
updateDeviceProfileWithProvisioningStrategy(deviceProfile, DeviceProfileProvisionType.DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void provisionRequestForDeviceWithDisabledProvisioningStrategy() throws Exception {
|
||||||
|
|
||||||
|
JsonObject provisionRequest = new JsonObject();
|
||||||
|
provisionRequest.addProperty("provisionDeviceKey", TEST_PROVISION_DEVICE_KEY);
|
||||||
|
provisionRequest.addProperty("provisionDeviceSecret", TEST_PROVISION_DEVICE_SECRET);
|
||||||
|
|
||||||
|
JsonPath provisionResponse = testRestClient.postProvisionRequest(provisionRequest.toString());
|
||||||
|
|
||||||
|
String status = provisionResponse.get("status");
|
||||||
|
|
||||||
|
assertThat(status).isEqualTo("NOT_FOUND");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,11 +37,6 @@ import org.thingsboard.server.common.data.Device;
|
|||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
import org.thingsboard.server.common.data.DeviceProfileProvisionType;
|
||||||
import org.thingsboard.server.common.data.StringUtils;
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
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.DeviceProfileData;
|
|
||||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileProvisionConfiguration;
|
|
||||||
import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
|
|
||||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
import org.thingsboard.server.common.data.page.PageData;
|
||||||
import org.thingsboard.server.common.data.page.PageLink;
|
import org.thingsboard.server.common.data.page.PageLink;
|
||||||
@ -76,9 +71,6 @@ import static org.thingsboard.server.msa.prototypes.DevicePrototypes.defaultDevi
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class MqttClientTest extends AbstractContainerTest {
|
public class MqttClientTest extends AbstractContainerTest {
|
||||||
|
|
||||||
private final static String TEST_PROVISION_DEVICE_KEY = "test_provision_key";
|
|
||||||
private final static String TEST_PROVISION_DEVICE_SECRET = "test_provision_secret";
|
|
||||||
|
|
||||||
private Device device;
|
private Device device;
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@ -430,30 +422,6 @@ public class MqttClientTest extends AbstractContainerTest {
|
|||||||
assertThat(provisionResponse.get("status").asText()).isEqualTo("NOT_FOUND");
|
assertThat(provisionResponse.get("status").asText()).isEqualTo("NOT_FOUND");
|
||||||
}
|
}
|
||||||
|
|
||||||
private DeviceProfile updateDeviceProfileWithProvisioningStrategy(DeviceProfile deviceProfile, DeviceProfileProvisionType provisionType) {
|
|
||||||
DeviceProfileProvisionConfiguration provisionConfiguration;
|
|
||||||
String testProvisionDeviceKey = TEST_PROVISION_DEVICE_KEY;
|
|
||||||
deviceProfile.setProvisionType(provisionType);
|
|
||||||
switch(provisionType) {
|
|
||||||
case ALLOW_CREATE_NEW_DEVICES:
|
|
||||||
provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(TEST_PROVISION_DEVICE_SECRET);
|
|
||||||
break;
|
|
||||||
case CHECK_PRE_PROVISIONED_DEVICES:
|
|
||||||
provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(TEST_PROVISION_DEVICE_SECRET);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case DISABLED:
|
|
||||||
testProvisionDeviceKey = null;
|
|
||||||
provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(null);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
DeviceProfileData deviceProfileData = deviceProfile.getProfileData();
|
|
||||||
deviceProfileData.setProvisionConfiguration(provisionConfiguration);
|
|
||||||
deviceProfile.setProfileData(deviceProfileData);
|
|
||||||
deviceProfile.setProvisionDeviceKey(testProvisionDeviceKey);
|
|
||||||
return testRestClient.postDeviceProfile(deviceProfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RuleChainId createRootRuleChainForRpcResponse() throws Exception {
|
private RuleChainId createRootRuleChainForRpcResponse() throws Exception {
|
||||||
RuleChain newRuleChain = new RuleChain();
|
RuleChain newRuleChain = new RuleChain();
|
||||||
newRuleChain.setName("testRuleChain");
|
newRuleChain.setName("testRuleChain");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user