use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method hasNextReturnsTrue.
/* SRS_QUERY_21_010: [The hasNext shall return the store hasNext.] */
@Test
public void hasNextReturnsTrue() {
// 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 - assert
assertTrue(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 nextStoreContinuationToken.
/* SRS_QUERY_21_019: [The next shall store the provided continuationToken.] */
/* SRS_QUERY_21_020: [The next shall return the next page of results by calling the next().] */
@Test
public void nextStoreContinuationToken() throws ProvisioningServiceClientException {
// arrange
final ContractApiHttp contractApiHttp = mockedContractApiHttp;
final String targetPath = "enrollments";
final QuerySpecification querySpecification = mockedQuerySpecification;
final String continuationToken = "validToken";
final String querySpecificationJson = "validJson";
class MockedQuery extends Query {
MockedQuery() {
super(contractApiHttp, targetPath, querySpecification, 0);
}
@Override
public QueryResult next() {
return mockedQueryResult;
}
}
new StrictExpectations() {
{
mockedQuerySpecification.toJson();
result = querySpecificationJson;
}
};
MockedQuery mockedQuery = new MockedQuery();
// act
QueryResult queryResult = mockedQuery.next(continuationToken);
// assert
assertEquals(continuationToken, Deencapsulation.getField(mockedQuery, "continuationToken"));
assertEquals(mockedQueryResult, queryResult);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method setPageSizeThrowsOnNegativePageSize.
/* SRS_QUERY_21_022: [The setPageSize shall throw IllegalArgumentException if the provided pageSize is negative.] */
@Test(expected = IllegalArgumentException.class)
public void setPageSizeThrowsOnNegativePageSize() {
// 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(-10);
// assert
}
use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.
the class QueryTest method constructorThrowsOnContractApiHttpNull.
/* SRS_QUERY_21_001: [The constructor shall throw IllegalArgumentException if the provided contractApiHttp is null.] */
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnContractApiHttpNull() {
// arrange
final ContractApiHttp contractApiHttp = null;
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 nextReturnsQueryResultWithContinuationToken.
/* 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 nextReturnsQueryResultWithContinuationToken() 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", 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, type, 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