Search in sources :

Example 11 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 closeSucceed.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_006: [The close shall destroy the transport connection `HttpsIotHubConnection`.] */
@Test
public void closeSucceed() {
    // arrange
    final HttpsIotHubConnection httpsIotHubConnection = mockConn;
    HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
    // act
    Deencapsulation.invoke(httpsTransportManager, "close");
    // assert
    assertNull(Deencapsulation.getField(httpsTransportManager, "httpsIotHubConnection"));
}
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 12 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 invokeMethodOnDeviceSuccess.

// Tests_SRS_HTTPSTRANSPORTMANAGER_34_018: [If a moduleId is provided, this function shall call invokeMethod with the provided request and
// a uri in the format twins/<device id>/modules/<module id>/methods?api-version=<api_version>.]
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_021: [This function shall set the methodrequest json as the body of the http message.]
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_022: [This function shall set the http method to POST.]
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_023: [This function shall set the http message's uri path to the provided uri path.]
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_024 [This function shall set a custom property of 'x-ms-edge-moduleId' to the value of <device id>/<module id> of the sending module/device.]
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_025 [This function shall send the built message.]
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_027 [If the http response doesn't contain an error code, this function return a method result with the response message body as the method result body.]
@Test
public void invokeMethodOnDeviceSuccess() throws TransportException, IOException, URISyntaxException {
    // arrange
    final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
    final String expectedDeviceId = "myDevice";
    final String expectedModuleId = "myModule";
    final String expectedSenderDeviceId = "mySenderDevice";
    final String expectedSenderModuleId = "mySenderModule";
    final String expectedMethodRequestJson = "someJson";
    final String expectedResponseBody = "some body";
    // assert
    new Expectations(HttpsTransportManager.class) {

        {
            mockedMethodRequest.toJson();
            result = expectedMethodRequestJson;
            new IotHubTransportMessage(expectedMethodRequestJson);
            result = mockedTransportMessage;
            mockedTransportMessage.setIotHubMethod(IotHubMethod.POST);
            mockedTransportMessage.setUriPath("/twins/" + expectedDeviceId + "/methods");
            mockConfig.getDeviceId();
            result = expectedSenderDeviceId;
            mockConfig.getModuleId();
            result = expectedSenderModuleId;
            transportManager.send(mockedTransportMessage, (Map) any);
            result = mockResponseMessage;
            mockResponseMessage.getStatus();
            result = IotHubStatusCode.OK_EMPTY;
            mockResponseMessage.getBytes();
            result = expectedResponseBody.getBytes(StandardCharsets.UTF_8);
            new MethodResult(expectedResponseBody);
        }
    };
    // act
    transportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, "");
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MethodResult(com.microsoft.azure.sdk.iot.device.edge.MethodResult) Test(org.junit.Test)

Example 13 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 sendCreateHttpMessageSucceed.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_007: [The send shall create a new instance of the `HttpMessage`, by parsing the Message with `parseHttpsJsonMessage` from `HttpsSingleMessage`.] */
@Test
public void sendCreateHttpMessageSucceed() 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.POST;
            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() {

        {
            Deencapsulation.invoke(HttpsSingleMessage.class, "parseHttpsJsonMessage", new Class[] { Message.class }, mockTransportMsg);
            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 14 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 sendFileUploadNotificationMessageSuccessWithoutModule.

// Tests_SRS_HTTPSTRANSPORTMANAGER_34_029 [This function shall set the uri path of the provided message to the
// format devices/<deviceid>/modules/<moduleid>/files/notifications if a moduleId is present or
// devices/<deviceid>/modules/<moduleid>/files/notifications otherwise, and then send it.]
@Test
public void sendFileUploadNotificationMessageSuccessWithoutModule() 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/notifications");
            transportManager.send(mockedTransportMessage, (Map) any);
            result = mockResponseMessage;
        }
    };
    // act
    transportManager.sendFileUploadNotification(mockedTransportMessage);
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) Test(org.junit.Test)

Example 15 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 receiveSucceed.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_015: [The receive shall receive and bypass message from `HttpsIotHubConnection`, by calling `receiveMessage`.] */
@Test
public void receiveSucceed() 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 = mockedTransportMessage;
        }
    };
    HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
    Deencapsulation.invoke(httpsTransportManager, "open");
    // act
    Deencapsulation.invoke(httpsTransportManager, "receive");
    // assert
    new Verifications() {

        {
            httpsIotHubConnection.receiveMessage();
            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)

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