use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method requestThrowsOnDeviceProvisioningServiceError.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_016: [If the Device Provisioning Service respond to the HttpRequest with any error code, the request shall throw the appropriated ProvisioningServiceClientException, by calling ProvisioningServiceClientExceptionManager.responseVerification().*/
@Test(expected = ProvisioningServiceClientException.class)
public void requestThrowsOnDeviceProvisioningServiceError() throws ProvisioningServiceClientException, IOException {
// arrange
new NonStrictExpectations() {
{
new ProvisioningSasToken(mockedProvisioningConnectionString);
result = mockedProvisioningSasToken;
mockedProvisioningSasToken.toString();
result = VALID_SASTOKEN;
mockedProvisioningConnectionString.getHostName();
result = VALID_HOST_NAME;
new URL((String) any);
result = mockedURL;
new HttpRequest(mockedURL, HttpMethod.PUT, VALID_PAYLOAD.getBytes(StandardCharsets.UTF_8));
result = mockedHttpRequest;
mockedHttpRequest.send();
result = mockedHttpResponse;
mockedHttpResponse.getStatus();
result = 401;
mockedHttpResponse.getErrorReason();
result = VALID_SUCCESS_MESSAGE.getBytes(StandardCharsets.UTF_8);
}
};
ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(mockedProvisioningConnectionString);
// act
contractApiHttp.request(HttpMethod.PUT, VALID_PATH, VALID_HEADER, VALID_PAYLOAD);
// assert
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken in project azure-iot-sdk-java by Azure.
the class ProvisioningServiceSasTokenTest method constructorThrowsOnBuildToken.
// Tests_SRS_PROVISIONING_SERVICE_SASTOKEN_12_007: [The constructor shall throw Exception if building the token failed]
@Test(expected = Exception.class)
public void constructorThrowsOnBuildToken() throws Exception {
// Arrange
String deviceProvisioningServiceName = "b.c.d";
String hostName = "HOSTNAME." + deviceProvisioningServiceName;
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = encodeBase64String("key".getBytes(StandardCharsets.UTF_8));
String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
// Act
ProvisioningConnectionString provisioningConnectionString = ProvisioningConnectionStringBuilder.createConnectionString(connectionString);
Deencapsulation.setField(provisioningConnectionString, "hostName", null);
ProvisioningSasToken provisioningServiceSasToken = new ProvisioningSasToken(provisioningConnectionString);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method requestThrowsOnNullPath.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_008: [If the provided path is null or empty, the request shall throw IllegalArgumentException.*/
@Test(expected = IllegalArgumentException.class)
public void requestThrowsOnNullPath() throws ProvisioningServiceClientException, IOException {
// arrange
new NonStrictExpectations() {
{
new ProvisioningSasToken(mockedProvisioningConnectionString);
result = mockedProvisioningSasToken;
mockedProvisioningSasToken.toString();
result = VALID_SASTOKEN;
mockedProvisioningConnectionString.getHostName();
result = VALID_HOST_NAME;
}
};
ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(mockedProvisioningConnectionString);
// act
contractApiHttp.request(HttpMethod.PUT, null, VALID_HEADER, VALID_PAYLOAD);
// assert
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method requestThrowsOnSasToken.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_006: [If the request get problem to create the SAS token, it shall throw IllegalArgumentException.*/
@Test(expected = IllegalArgumentException.class)
public void requestThrowsOnSasToken() throws ProvisioningServiceClientException, IOException {
// arrange
new NonStrictExpectations() {
{
new ProvisioningSasToken(mockedProvisioningConnectionString);
result = new IllegalArgumentException("");
}
};
ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(mockedProvisioningConnectionString);
// act
contractApiHttp.request(HttpMethod.PUT, VALID_PATH, VALID_HEADER, VALID_PAYLOAD);
// assert
}
Aggregations