Search in sources :

Example 6 with HttpsIotHubConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection 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)

Example 7 with HttpsIotHubConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection in project azure-iot-sdk-java by Azure.

the class IotHubTransport method openConnection.

/**
 * Creates a new iotHubTransportConnection instance, sets this object as its listener, and opens that connection
 *
 * @throws TransportException if any exception is thrown while opening the connection
 */
private void openConnection() throws TransportException {
    if (this.iotHubTransportConnection == null) {
        switch(this.protocol) {
            case HTTPS:
                this.iotHubTransportConnection = new HttpsIotHubConnection(this.getDefaultConfig());
                break;
            case MQTT:
            case MQTT_WS:
                this.iotHubTransportConnection = new MqttIotHubConnection(this.getDefaultConfig());
                break;
            case AMQPS:
            case AMQPS_WS:
                if (this.isMultiplexing) {
                    // The default config is only null when someone creates a multiplexing client and opens it before
                    // registering any devices to it
                    this.iotHubTransportConnection = new AmqpsIotHubConnection(this.hostName, this.transportUniqueIdentifier, this.protocol == IotHubClientProtocol.AMQPS_WS, this.sslContext, this.proxySettings, this.keepAliveInterval);
                    for (DeviceClientConfig config : this.deviceClientConfigs.values()) {
                        ((AmqpsIotHubConnection) this.iotHubTransportConnection).registerMultiplexedDevice(config);
                    }
                } else {
                    this.iotHubTransportConnection = new AmqpsIotHubConnection(this.getDefaultConfig(), this.transportUniqueIdentifier);
                }
                break;
            default:
                throw new TransportException("Protocol not supported");
        }
    }
    this.iotHubTransportConnection.setListener(this);
    this.iotHubTransportConnection.open();
    this.updateStatus(IotHubConnectionStatus.CONNECTED, IotHubConnectionStatusChangeReason.CONNECTION_OK, null);
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) HttpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection)

Example 8 with HttpsIotHubConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection 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 9 with HttpsIotHubConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection 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 10 with HttpsIotHubConnection

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection in project azure-iot-sdk-java by Azure.

the class HttpsTransportManagerTest method sendParseHttpsJsonMessageThrows.

/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_008: [If send failed to parse the message, it shall bypass the exception.] */
@Test(expected = IllegalArgumentException.class)
public void sendParseHttpsJsonMessageThrows() {
    // 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 = new IllegalArgumentException();
        }
    };
    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)

Aggregations

HttpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection)13 HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)12 Test (org.junit.Test)12 IOException (java.io.IOException)2 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)1 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)1