use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class ContractApiHttpTest method requestThrowsOnHttpRequestFailed.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_011: [If the request get problem creating the HttpRequest, it shall throw ProvisioningServiceClientTransportException.*/
@Test(expected = ProvisioningServiceClientTransportException.class)
public void requestThrowsOnHttpRequestFailed() 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 = new IOException();
}
};
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 requestCreatesURL.
/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_007: [The request shall create a HTTP URL based on the Device Registration path.*/
@Test
public void requestCreatesURL() throws ProvisioningServiceClientException, IOException {
// arrange
requestNonStrictExpectations();
ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(mockedProvisioningConnectionString);
String expectedURL = "https://" + VALID_HOST_NAME + "/" + VALID_PATH + "?api-version=" + SDKUtils.getServiceApiVersion();
// act
contractApiHttp.request(HttpMethod.PUT, VALID_PATH, VALID_HEADER, VALID_PAYLOAD);
// assert
new Verifications() {
{
new URL(expectedURL);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method constructorThrowsOnTargetPathNull.
/* SRS_QUERY_21_002: [The constructor shall throw IllegalArgumentException if the provided targetPath is null or empty.] */
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnTargetPathNull() {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = null;
final QuerySpecification querySpecification = mockedQuerySpecification;
final int pageSize = 10;
// act
Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, pageSize);
// assert
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method nextSendWithoutPageSizeOrContinuationTokenIntoHttpHeader.
/* SRS_QUERY_21_012: [If the pageSize is not 0, the next shall send the Http request with `x-ms-max-item-count=[pageSize]` in the header.] */
/* SRS_QUERY_21_013: [If the continuationToken is not null or empty, the next shall send the Http request with `x-ms-continuation=[continuationToken]` in the header.] */
@Test
public void nextSendWithoutPageSizeOrContinuationTokenIntoHttpHeader() throws ProvisioningServiceClientException {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = "enrollments";
final String queryPath = targetPath + "/query";
final QuerySpecification querySpecification = mockedQuerySpecification;
final String querySpecificationJson = "validJson";
final Map<String, String> headersSend = new HashMap<>();
final Map<String, String> headersResult = new HashMap<String, String>() {
{
put("x-ms-item-type", "enrollment");
}
};
new StrictExpectations() {
{
mockedQuerySpecification.toJson();
result = querySpecificationJson;
mockedContractApiHttp.request(HttpMethod.POST, queryPath, headersSend, querySpecificationJson);
times = 1;
result = mockedHttpResponse;
mockedHttpResponse.getBody();
result = "result".getBytes(StandardCharsets.UTF_8);
mockedHttpResponse.getHeaderFields();
result = headersResult;
times = 1;
}
};
Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, 0);
// act
query.next();
// assert
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method nextSucceedOnNullType.
/* SRS_QUERY_21_016: [The next shall create and return a new instance of the QueryResult using the `x-ms-item-type` as type, `x-ms-continuation` as the next continuationToken, and the message body.] */
@Test
public void nextSucceedOnNullType() throws ProvisioningServiceClientException {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = "enrollments";
final String queryPath = targetPath + "/query";
final QuerySpecification querySpecification = mockedQuerySpecification;
final String querySpecificationJson = "validJson";
final String continuationToken = "validToken";
final String type = "validToken";
final String bodyResult = "result";
final Map<String, String> headersSend = new HashMap<>();
final Map<String, String> headersResult = new HashMap<String, String>() {
{
put("x-ms-item-type", null);
put("x-ms-continuation", continuationToken);
}
};
new StrictExpectations() {
{
mockedQuerySpecification.toJson();
result = querySpecificationJson;
mockedContractApiHttp.request(HttpMethod.POST, queryPath, headersSend, querySpecificationJson);
result = mockedHttpResponse;
mockedHttpResponse.getBody();
result = bodyResult.getBytes(StandardCharsets.UTF_8);
mockedHttpResponse.getHeaderFields();
result = headersResult;
Deencapsulation.newInstance(QueryResult.class, new Class[] { String.class, String.class, String.class }, null, bodyResult, continuationToken);
}
};
Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, 0);
// act
QueryResult queryResult = query.next();
// assert
assertNotNull(queryResult);
assertTrue(query.hasNext());
}
Aggregations