use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method createFromConnectionStringSucceeded.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_004: [The createFromConnectionString shall create a new ContractApiHttp instance and return it.] */
@Test
public void createFromConnectionStringSucceeded() throws ProvisioningServiceClientException {
// arrange
final ProvisioningConnectionString provisioningConnectionString = mockedProvisioningConnectionString;
// act
ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(provisioningConnectionString);
// assert
assertNotNull(contractApiHttp);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method requestThrowsOnSendHttpRequestFailed.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_015: [If the HttpRequest failed send the message, the request shall throw ProvisioningServiceClientTransportException, threw by the callee.*/
@Test(expected = ProvisioningServiceClientException.class)
public void requestThrowsOnSendHttpRequestFailed() 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 = new ProvisioningServiceClientException();
}
};
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.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method requestThrowsOnWrongPath.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_009: [If the provided path contains not valid characters, the request shall throw IllegalArgumentException.*/
@Test(expected = IllegalArgumentException.class)
public void requestThrowsOnWrongPath() 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 = new MalformedURLException();
}
};
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.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method requestCreatesSasToken.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_005: [The request shall create a SAS token based on the connection string.*/
@Test
public void requestCreatesSasToken() throws ProvisioningServiceClientException, IOException {
// arrange
new Expectations() {
{
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 = VALID_SUCCESS_STATUS;
mockedHttpResponse.getErrorReason();
result = VALID_SUCCESS_MESSAGE.getBytes(StandardCharsets.UTF_8);
mockedHttpResponse.getBody();
result = VALID_BODY;
mockedHttpResponse.getHeaderFields();
result = VALID_HEADER;
ProvisioningServiceClientExceptionManager.httpResponseVerification(VALID_SUCCESS_STATUS, VALID_SUCCESS_MESSAGE);
}
};
ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(mockedProvisioningConnectionString);
requestNonStrictExpectations();
// act
contractApiHttp.request(HttpMethod.PUT, VALID_PATH, VALID_HEADER, VALID_PAYLOAD);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method privateConstructorSucceeded.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_001: [The constructor shall store the provided connection string.] */
@Test
public void privateConstructorSucceeded() {
// arrange
// act
ContractApiHttp httpDeviceRegistrationClient = Deencapsulation.newInstance(ContractApiHttp.class, new Class[] { ProvisioningConnectionString.class }, mockedProvisioningConnectionString);
// assert
assertNotNull(httpDeviceRegistrationClient);
assertEquals(mockedProvisioningConnectionString, Deencapsulation.getField(httpDeviceRegistrationClient, "provisioningConnectionString"));
}
Aggregations