Search in sources :

Example 16 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 sendInvalidMethodThrows.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_011: [If the IotHubMethod is not `GET` or `POST`, the send shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void sendInvalidMethodThrows() {
    // 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 = null;
        }
    };
    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>());
}
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 17 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 invokeMethodThrowsForNullUri.

// Tests_SRS_HTTPSTRANSPORTMANAGER_34_020: [If the provided uri is null or empty, this function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void invokeMethodThrowsForNullUri() throws TransportException, IOException, URISyntaxException {
    // arrange
    final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
    final String expectedDeviceId = "myDevice";
    // act
    Deencapsulation.invoke(transportManager, "invokeMethod", new Class[] { MethodRequest.class, URI.class }, mockedMethodRequest, (URI) null);
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) Test(org.junit.Test)

Example 18 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 receiveReceiveMessageThrows.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_016: [If `receiveMessage` failed, the receive shall bypass the exception.] */
@Test(expected = IOException.class)
public void receiveReceiveMessageThrows() throws TransportException {
    // arrange
    final HttpsIotHubConnection httpsIotHubConnection = mockConn;
    final String uriPath = "/files/notifications";
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
            result = httpsIotHubConnection;
            httpsIotHubConnection.receiveMessage();
            result = new IOException();
        }
    };
    HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
    Deencapsulation.invoke(httpsTransportManager, "open");
    // act
    Deencapsulation.invoke(httpsTransportManager, "receive");
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) HttpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection) IOException(java.io.IOException) Test(org.junit.Test)

Example 19 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 sendFileUploadMessageSuccessWithoutModule.

// Tests_SRS_HTTPSTRANSPORTMANAGER_34_028 [This function shall set the uri path of the provided message to the
// format devices/<deviceid>/modules/<moduleid>/files if a moduleId is present or
// devices/<deviceid>/modules/<moduleid>/files otherwise, and then send it.]
@Test
public void sendFileUploadMessageSuccessWithoutModule() throws TransportException, IOException, URISyntaxException {
    // arrange
    final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
    final String expectedDeviceId = "myDevice";
    // assert
    new Expectations(HttpsTransportManager.class) {

        {
            mockConfig.getDeviceId();
            result = expectedDeviceId;
            mockConfig.getModuleId();
            result = "";
            mockedTransportMessage.setUriPath("/devices/" + expectedDeviceId + "/files");
            transportManager.send(mockedTransportMessage, (Map) any);
            result = mockResponseMessage;
        }
    };
    // act
    transportManager.getFileUploadSasUri(mockedTransportMessage);
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) Test(org.junit.Test)

Example 20 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 invokeMethodThrowsForNullRequest.

// Tests_SRS_HTTPSTRANSPORTMANAGER_34_019: [If the provided method request is null, this function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void invokeMethodThrowsForNullRequest() throws TransportException, IOException, URISyntaxException {
    // arrange
    final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
    final String expectedDeviceId = "myDevice";
    // act
    transportManager.invokeMethod(null, expectedDeviceId, "");
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) 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