Search in sources :

Example 26 with HttpsTransportManager

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"));
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) Test(org.junit.Test)

Example 27 with HttpsTransportManager

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;
        }
    };
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) HttpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection) Test(org.junit.Test)

Example 28 with HttpsTransportManager

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;
        }
    };
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HashMap(java.util.HashMap) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) Test(org.junit.Test)

Example 29 with HttpsTransportManager

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);
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with HttpsTransportManager

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);
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) Test(org.junit.Test)

Aggregations

HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)32 Test (org.junit.Test)31 HttpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection)12 FileUpload (com.microsoft.azure.sdk.iot.device.fileupload.FileUpload)5 IOException (java.io.IOException)5 MethodResult (com.microsoft.azure.sdk.iot.device.edge.MethodResult)4 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)3 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)3 HashMap (java.util.HashMap)2 IotHubEventCallback (com.microsoft.azure.sdk.iot.device.IotHubEventCallback)1 ModuleClientException (com.microsoft.azure.sdk.iot.device.exceptions.ModuleClientException)1 TransportException (com.microsoft.azure.sdk.iot.device.exceptions.TransportException)1 FileUploadInProgress (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress)1 FileUploadStatusCallBack (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadStatusCallBack)1 URISyntaxException (java.net.URISyntaxException)1