use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method constructorThrowsOnQuerySpecificationNull.
/* SRS_QUERY_21_003: [The constructor shall throw IllegalArgumentException if the provided querySpecification is null.] */
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnQuerySpecificationNull() {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = "enrollments";
final QuerySpecification querySpecification = null;
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 hasNextReturnsFalse.
/* SRS_QUERY_21_010: [The hasNext shall return the store hasNext.] */
@Test
public void hasNextReturnsFalse() 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 int pageSize = 10;
final Map<String, String> headersResult = new HashMap<String, String>() {
{
put("x-ms-item-type", "enrollment");
}
};
new NonStrictExpectations() {
{
mockedQuerySpecification.toJson();
result = querySpecificationJson;
mockedContractApiHttp.request(HttpMethod.POST, queryPath, (Map) any, querySpecificationJson);
result = mockedHttpResponse;
mockedHttpResponse.getBody();
result = "result".getBytes(StandardCharsets.UTF_8);
mockedHttpResponse.getHeaderFields();
result = headersResult;
}
};
Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, pageSize);
query.next();
// act - assert
assertFalse(query.hasNext());
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method setPageSizeChangePageSize.
/* SRS_QUERY_21_023: [The setPageSize shall store the new pageSize value.] */
@Test
public void setPageSizeChangePageSize() {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = "enrollments";
final QuerySpecification querySpecification = mockedQuerySpecification;
final String querySpecificationJson = "validJson";
final int pageSize = 10;
new NonStrictExpectations() {
{
mockedQuerySpecification.toJson();
result = querySpecificationJson;
}
};
Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, pageSize);
// act
query.setPageSize(20);
// assert
assertEquals(20, (int) Deencapsulation.getField(query, "pageSize"));
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method nextThrowsOnRequestFailed.
/* SRS_QUERY_21_015: [The next shall throw IllegalArgumentException if the Http request throws any ProvisioningServiceClientException.] */
@Test(expected = IllegalArgumentException.class)
public void nextThrowsOnRequestFailed() throws ProvisioningServiceClientException {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = "enrollments";
final String queryPath = targetPath + "/query";
final QuerySpecification querySpecification = mockedQuerySpecification;
final String querySpecificationJson = "validJson";
new StrictExpectations() {
{
mockedQuerySpecification.toJson();
result = querySpecificationJson;
mockedContractApiHttp.request(HttpMethod.POST, queryPath, (Map) any, querySpecificationJson);
result = new ProvisioningServiceClientBadFormatException();
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 nextReturnsQueryResultWithoutContinuationToken.
/* SRS_QUERY_21_017: [The next shall set hasNext as true if the continuationToken is not null, or false if it is null.] */
/* SRS_QUERY_21_017: [The next shall set hasNext as true if the continuationToken is not null, or false if it is null.] */
@Test
public void nextReturnsQueryResultWithoutContinuationToken() 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 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", type);
}
};
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 }, type, bodyResult, null);
}
};
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);
assertFalse(query.hasNext());
}
Aggregations