use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method nextThrowsOnNullContinuationToken.
/* SRS_QUERY_21_018: [The next shall throw NoSuchElementException if the provided continuationToken is null or empty.] */
@Test(expected = NoSuchElementException.class)
public void nextThrowsOnNullContinuationToken() throws ProvisioningServiceClientException {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = "enrollments";
final QuerySpecification querySpecification = mockedQuerySpecification;
final String querySpecificationJson = "validJson";
new StrictExpectations() {
{
mockedQuerySpecification.toJson();
result = querySpecificationJson;
}
};
Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, 0);
// act
query.next(null);
// assert
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method constructorStoresContractApiHttpAndPageSize.
/* SRS_QUERY_21_005: [The constructor shall store the provided `contractApiHttp` and `pageSize`.] */
/* SRS_QUERY_21_006: [The constructor shall create and store a JSON from the provided querySpecification.] */
/* SRS_QUERY_21_007: [The constructor shall create and store a queryPath adding `/query` to the provided `targetPath`.] */
/* SRS_QUERY_21_008: [The constructor shall set continuationToken as null.] */
/* SRS_QUERY_21_009: [The constructor shall set hasNext as true.] */
@Test
public void constructorStoresContractApiHttpAndPageSize() {
// 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;
new NonStrictExpectations() {
{
mockedQuerySpecification.toJson();
result = querySpecificationJson;
times = 1;
}
};
// act
Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, pageSize);
// assert
assertEquals(contractApiHttp, Deencapsulation.getField(query, "contractApiHttp"));
assertEquals(pageSize, (int) Deencapsulation.getField(query, "pageSize"));
assertEquals(querySpecificationJson, Deencapsulation.getField(query, "querySpecificationJson"));
assertEquals(queryPath, Deencapsulation.getField(query, "queryPath"));
assertNull(Deencapsulation.getField(query, "continuationToken"));
assertTrue(Deencapsulation.getField(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 nextSucceedOnNullContinuationToken.
/* 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.] */
/* 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 nextSucceedOnNullContinuationToken() 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", type);
put("x-ms-continuation", null);
}
};
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());
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method constructorThrowsOnPageSizeNegative.
/* SRS_QUERY_21_004: [The constructor shall throw IllegalArgumentException if the provided pageSize is negative.] */
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnPageSizeNegative() {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = "enrollments";
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 nextThrowsOnFalseHasNext.
/* SRS_QUERY_21_011: [The next shall throw NoSuchElementException if the hasNext is false.] */
@Test(expected = NoSuchElementException.class)
public void nextThrowsOnFalseHasNext() 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();
assertFalse(query.hasNext());
// act
query.next();
// assert
}
Aggregations