use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class DeviceOperationsTest method requestNullUrlFailed.
/* Tests_SRS_DEVICE_OPERATIONS_21_002: [The request shall throw IllegalArgumentException if the provided `url` is null.] */
@Test(expected = IllegalArgumentException.class)
public void requestNullUrlFailed() throws Exception {
// arrange
final IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(STANDARD_CONNECTIONSTRING);
// act
HttpResponse response = DeviceOperations.request(IOT_HUB_CONNECTION_STRING, null, HttpMethod.POST, STANDARD_PAYLOAD, STANDARD_REQUEST_ID, 0);
// assert
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class QueryCollectionTest method sendQueryRequestUsesQueryStringJsonBytesAsPayload.
// Tests_SRS_QUERYCOLLECTION_34_015: [If this is a sql query, the payload of the query message shall be set to the json bytes representation of this object's query string.]
@Test
public void sendQueryRequestUsesQueryStringJsonBytesAsPayload(@Mocked final URL mockUrl) throws IOException, IotHubException {
// arrange
String expectedQueryString = "some query";
String expectedQueryStringJson = "some query json";
byte[] expectedQueryStringBytes = expectedQueryStringJson.getBytes(StandardCharsets.UTF_8);
QueryCollection queryCollection = Deencapsulation.newInstance(QueryCollection.class, new Class[] { String.class, int.class, QueryType.class, IotHubConnectionString.class, URL.class, HttpMethod.class, long.class }, expectedQueryString, expectedPageSize, QueryType.RAW, mockConnectionString, mockUrl, mockHttpMethod, expectedTimeout);
new NonStrictExpectations() {
{
mockQueryOptions.getContinuationToken();
result = expectedRequestContinuationToken;
Deencapsulation.newInstance(QueryRequestParser.class, new Class[] { String.class }, expectedQueryString);
result = mockQueryRequestParser;
mockQueryRequestParser.toJson();
result = expectedQueryStringJson;
expectedQueryStringJson.getBytes(StandardCharsets.UTF_8);
result = expectedQueryStringBytes;
DeviceOperations.request((IotHubConnectionString) any, (URL) any, (HttpMethod) any, expectedQueryStringBytes, null, anyLong);
result = mockHttpResponse;
mockHttpResponse.getHeaderFields();
result = expectedValidResponseHeaders;
}
};
// act
Deencapsulation.invoke(queryCollection, "sendQueryRequest", new Class[] { QueryOptions.class }, mockQueryOptions);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method buildRegistryManagerWithAzureSasCredential.
private static RegistryManager buildRegistryManagerWithAzureSasCredential() {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
RegistryManagerOptions options = RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
return new RegistryManager(iotHubConnectionStringObj.getHostName(), azureSasCredential, options);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class ServiceClientTests method buildServiceClientWithAzureSasCredential.
private static ServiceClient buildServiceClientWithAzureSasCredential(IotHubServiceClientProtocol protocol, ServiceClientOptions options) {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
return new ServiceClient(iotHubConnectionStringObj.getHostName(), azureSasCredential, protocol, options);
}
use of com.microsoft.azure.sdk.iot.service.IotHubConnectionString in project azure-iot-sdk-java by Azure.
the class ServiceClientTests method feedbackMessageReceiverWithAzureSasCredential.
@Test
@StandardTierHubOnlyTest
public void feedbackMessageReceiverWithAzureSasCredential() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential sasTokenProvider = new AzureSasCredential(serviceSasToken.toString());
ServiceClient serviceClient = new ServiceClient(iotHubConnectionStringObj.getHostName(), sasTokenProvider, testInstance.protocol);
FeedbackReceiver feedbackReceiver = serviceClient.getFeedbackReceiver();
feedbackReceiver.open();
// received feedback message can be ignored since we no longer have any tests that need to consume them
// All this test cares about is that this API doesn't result in an unauthorized exception
feedbackReceiver.receive(2 * 1000);
feedbackReceiver.close();
serviceClient.close();
registryManager.close();
}
Aggregations