use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method constructorSucceed.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_001: [The constructor shall store the device client configuration `config`.] */
@Test
public void constructorSucceed() {
// arrange
final DeviceClientConfig config = mockConfig;
// act
HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, config);
// assert
assertEquals(config, Deencapsulation.getField(httpsTransportManager, "config"));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method sendMethodGETSucceed.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_009: [If the IotHubMethod is `GET`, the send shall set the httpsMethod as `GET`.] */
@Test
public void sendMethodGETSucceed() throws IOException, TransportException {
// arrange
final HttpsIotHubConnection httpsIotHubConnection = mockConn;
final String uriPath = "/files/notifications";
new NonStrictExpectations() {
{
Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
result = httpsIotHubConnection;
Deencapsulation.invoke(HttpsSingleMessage.class, "parseHttpsJsonMessage", new Class[] { Message.class }, mockTransportMsg);
result = mockHttpsMessage;
mockTransportMsg.getIotHubMethod();
result = IotHubMethod.GET;
mockTransportMsg.getUriPath();
result = uriPath;
httpsIotHubConnection.sendHttpsMessage(mockHttpsMessage, (HttpsMethod) any, (String) any, (Map) any);
result = mockResponseMessage;
}
};
HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
Deencapsulation.invoke(httpsTransportManager, "open");
// act
Deencapsulation.invoke(httpsTransportManager, "send", new Class[] { IotHubTransportMessage.class, Map.class }, mockTransportMsg, new HashMap<String, String>());
// assert
new Verifications() {
{
httpsIotHubConnection.sendHttpsMessage(mockHttpsMessage, HttpsMethod.GET, (String) any, (Map) any);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class FileUploadTest method closeNowWithPendingUploadSuccess.
/* Tests_SRS_FILEUPLOAD_21_018: [If there is pending file uploads, the closeNow shall cancel the upload, and call the `statusCallback` reporting ERROR.] */
@Test
public void closeNowWithPendingUploadSuccess(@Mocked final Future mockFuture) throws IOException {
// arrange
final Map<String, Object> context = new HashMap<>();
final Queue<FileUploadInProgress> fileUploadInProgressSet = new LinkedBlockingDeque<FileUploadInProgress>() {
{
add(mockFileUploadInProgress);
}
};
new NonStrictExpectations() {
{
new HttpsTransportManager(mockConfig);
result = mockHttpsTransportManager;
Executors.newScheduledThreadPool(10);
result = mockScheduler;
Deencapsulation.invoke(mockFileUploadInProgress, "isCancelled");
result = true;
}
};
FileUpload fileUpload = new FileUpload(mockConfig);
Deencapsulation.setField(fileUpload, "fileUploadInProgressesSet", fileUploadInProgressSet);
// act
fileUpload.closeNow();
// assert
new Verifications() {
{
Deencapsulation.invoke(mockFileUploadInProgress, "triggerCallback", new Class[] { IotHubStatusCode.class }, IotHubStatusCode.ERROR);
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 invokeMethodOnDeviceWrapsExceptions.
// Tests_SRS_MODULECLIENT_34_034: [If this function encounters an exception, it shall throw a moduleClientException with that exception nested.]
@Test(expected = ModuleClientException.class)
public void invokeMethodOnDeviceWrapsExceptions() 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 = new IOException();
}
};
// act
client.invokeMethod(expectedDeviceId, mockedMethodRequest);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class FileUploadTest method constructorExecutorThrows.
/* Tests_SRS_FILEUPLOAD_21_015: [If create the executor failed, the constructor shall throws IOException.] */
@Test(expected = IOException.class)
public void constructorExecutorThrows() throws IOException {
// arrange
new NonStrictExpectations() {
{
new HttpsTransportManager(mockConfig);
result = mockHttpsTransportManager;
Executors.newScheduledThreadPool(10);
result = new IllegalArgumentException();
times = 1;
}
};
// act
FileUpload fileUpload = new FileUpload(mockConfig);
}
Aggregations