use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class FileUploadTest method constructorSuccess.
/* Tests_SRS_FILEUPLOAD_21_002: [The constructor shall create a new instance of `HttpsTransportManager` with the provided `config`.] */
/* Tests_SRS_FILEUPLOAD_21_012: [The constructor shall create an pool of 10 threads to execute the uploads in parallel.] */
/* Tests_SRS_FILEUPLOAD_21_013: [The constructor shall create a list `fileUploadInProgressesSet` to control the pending uploads.] */
@Test
public void constructorSuccess(@Mocked final LinkedBlockingDeque<?> mockFileUploadInProgressQueue) throws IOException {
// arrange
new Expectations() {
{
new HttpsTransportManager(mockConfig);
result = mockHttpsTransportManager;
Executors.newScheduledThreadPool(10);
result = mockScheduler;
}
};
// act
final FileUpload fileUpload = new FileUpload(mockConfig);
// assert
new Verifications() {
{
new LinkedBlockingDeque<>();
times = 1;
}
};
assertNotNull(fileUpload);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class ModuleClientTest method invokeMethodOnModuleWrapsExceptions.
// Tests_SRS_MODULECLIENT_34_036: [If this function encounters an exception, it shall throw a moduleClientException with that exception nested.]
@Test(expected = ModuleClientException.class)
public void invokeMethodOnModuleWrapsExceptions() throws URISyntaxException, ModuleClientException, IOException, TransportException {
// arrange
baseExpectations();
ModuleClient client = new ModuleClient("connection string", IotHubClientProtocol.AMQPS);
final String expectedDeviceId = "someDevice";
final String expectedModuleId = "someModule";
new NonStrictExpectations() {
{
new HttpsTransportManager((DeviceClientConfig) any);
result = mockedHttpsTransportManager;
mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, expectedModuleId);
result = new IOException();
}
};
// act
client.invokeMethod(expectedDeviceId, expectedModuleId, mockedMethodRequest);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class ModuleClientTest method invokeMethodOnDeviceSuccess.
// Tests_SRS_MODULECLIENT_34_033: [This function shall create an HttpsTransportManager and use it to invoke the method on the device.]
@Test
public void invokeMethodOnDeviceSuccess() throws URISyntaxException, ModuleClientException, IOException, TransportException {
// arrange
baseExpectations();
ModuleClient client = new ModuleClient("connection string", IotHubClientProtocol.AMQPS);
final String expectedDeviceId = "someDevice";
new NonStrictExpectations() {
{
new HttpsTransportManager((DeviceClientConfig) any);
result = mockedHttpsTransportManager;
mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, "");
result = mockedMethodResult;
}
};
// act
MethodResult actualResult = client.invokeMethod(expectedDeviceId, mockedMethodRequest);
// assert
assertEquals(mockedMethodResult, actualResult);
new Verifications() {
{
mockedHttpsTransportManager.open();
times = 1;
mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, "");
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class ModuleClientTest method invokeMethodOnModuleSuccess.
// Tests_SRS_MODULECLIENT_34_035: [This function shall create an HttpsTransportManager and use it to invoke the method on the module.]
@Test
public void invokeMethodOnModuleSuccess() throws URISyntaxException, ModuleClientException, IOException, TransportException {
// arrange
baseExpectations();
ModuleClient client = new ModuleClient("connection string", IotHubClientProtocol.AMQPS);
final String expectedDeviceId = "someDevice";
final String expectedModuleId = "someModule";
new NonStrictExpectations() {
{
new HttpsTransportManager((DeviceClientConfig) any);
result = mockedHttpsTransportManager;
mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, expectedModuleId);
result = mockedMethodResult;
}
};
// act
MethodResult actualResult = client.invokeMethod(expectedDeviceId, expectedModuleId, mockedMethodRequest);
// assert
assertEquals(mockedMethodResult, actualResult);
new Verifications() {
{
mockedHttpsTransportManager.open();
times = 1;
mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, expectedModuleId);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class ModuleClient method invokeMethod.
/**
* Invoke a method on a device
* @param deviceId the device to invoke a method on
* @param methodRequest the request containing the method to invoke on the device
* @return the result of the method call
* @throws ModuleClientException if the method cannot be invoked
* @throws IllegalArgumentException if deviceid is null or empty
*/
public MethodResult invokeMethod(String deviceId, MethodRequest methodRequest) throws ModuleClientException, IllegalArgumentException {
if (deviceId == null || deviceId.isEmpty()) {
// Codes_SRS_MODULECLIENT_34_039: [If the provided deviceId is null or empty, this function shall throw an IllegalArgumentException.]
throw new IllegalArgumentException("DeviceId cannot be null or empty");
}
try {
// Codes_SRS_MODULECLIENT_34_033: [This function shall create an HttpsTransportManager and use it to invoke the method on the device.]
HttpsTransportManager httpsTransportManager = new HttpsTransportManager(this.config);
httpsTransportManager.open();
return httpsTransportManager.invokeMethod(methodRequest, deviceId, "");
} catch (URISyntaxException | IOException | TransportException e) {
// Codes_SRS_MODULECLIENT_34_034: [If this function encounters an exception, it shall throw a moduleClientException with that exception nested.]
throw new ModuleClientException("Could not invoke method", e);
}
}
Aggregations