Search in sources :

Example 41 with Verifications

use of mockit.Verifications in project azure-iot-sdk-java by Azure.

the class AmqpsMessageTest method acknowledgeSettlesDelivery.

// Tests_SRS_AMQPSMESSAGE_14_005: [The function shall settle the delivery after setting the proper disposition.]
@Test
public void acknowledgeSettlesDelivery() {
    AmqpsMessage message = new AmqpsMessage();
    message.setDelivery(mockDelivery);
    message.acknowledge(AmqpsMessage.ACK_TYPE.COMPLETE);
    message.acknowledge(AmqpsMessage.ACK_TYPE.ABANDON);
    message.acknowledge(AmqpsMessage.ACK_TYPE.REJECT);
    final Delivery expectedDelivery = mockDelivery;
    new Verifications() {

        {
            expectedDelivery.settle();
            times = 3;
        }
    };
}
Also used : Delivery(org.apache.qpid.proton.engine.Delivery) Verifications(mockit.Verifications) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) Test(org.junit.Test)

Example 42 with Verifications

use of mockit.Verifications in project azure-iot-sdk-java by Azure.

the class IotHubSendTaskTest method runSendsAllMessages.

// Tests_SRS_IOTHUBSENDTASK_11_001: [The constructor shall save the transport.]
// Tests_SRS_IOTHUBSENDTASK_11_002: [The function shall send all messages on the transport queue.]
@Test
public void runSendsAllMessages() throws IOException, URISyntaxException {
    IotHubSendTask sendTask = new IotHubSendTask(mockTransport);
    sendTask.run();
    new Verifications() {

        {
            mockTransport.sendMessages();
        }
    };
}
Also used : IotHubSendTask(com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 43 with Verifications

use of mockit.Verifications in project azure-iot-sdk-java by Azure.

the class MqttIotHubConnectionTest method receiveMessageSucceeds.

// Tests_SRS_MQTTIOTHUBCONNECTION_15_014: [The function shall attempt to consume a message
// from the received messages queue.]
@Test
public void receiveMessageSucceeds() throws IOException {
    baseExpectations();
    openExpectations();
    final byte[] expectedMessageBody = { 0x61, 0x62, 0x63 };
    new NonStrictExpectations() {

        {
            mockDeviceMethods.receive();
            result = null;
            mockDeviceTwin.receive();
            result = null;
            mockDeviceMessaging.receive();
            result = new Message(expectedMessageBody);
        }
    };
    MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
    connection.open();
    Message message = connection.receiveMessage();
    byte[] actualMessageBody = message.getBytes();
    for (int i = 0; i < expectedMessageBody.length; i++) {
        assertEquals(expectedMessageBody[i], actualMessageBody[i]);
    }
    new Verifications() {

        {
            mockDeviceTwin.receive();
            times = 1;
            mockDeviceMethods.receive();
            times = 1;
            mockDeviceMessaging.receive();
            times = 1;
        }
    };
}
Also used : DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) DeviceMethodMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage) MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 44 with Verifications

use of mockit.Verifications in project azure-iot-sdk-java by Azure.

the class MqttIotHubConnectionTest method openDoesNothingIfAlreadyOpened.

// Tests_SRS_MQTTIOTHUBCONNECTION_15_006: [If the MQTT connection is already open, the function shall do nothing.]
@Test
public void openDoesNothingIfAlreadyOpened() throws IOException {
    baseExpectations();
    openExpectations();
    MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
    connection.open();
    connection.open();
    new Verifications() {

        {
            new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
            times = 1;
        }
    };
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 45 with Verifications

use of mockit.Verifications in project azure-iot-sdk-java by Azure.

the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInTwin.

@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInTwin() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            new IotHubSasToken(mockConfig, anyLong);
            result = mockToken;
            new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
            result = mockDeviceMessaging;
            new MqttDeviceMethod();
            result = mockDeviceMethods;
            new MqttDeviceTwin();
            result = new IOException(anyString);
        }
    };
    try {
        MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
        connection.open();
    } catch (Exception e) {
        new Verifications() {

            {
                mockDeviceMessaging.stop();
                times = 1;
                mockDeviceMethods.stop();
                times = 1;
            }
        };
        throw e;
    }
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IOException(java.io.IOException) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) IOException(java.io.IOException) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Aggregations

Verifications (mockit.Verifications)103 Test (org.junit.Test)103 NonStrictExpectations (mockit.NonStrictExpectations)66 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)14 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)12 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)11 AmqpResponseVerification (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification)11 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)10 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)10 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)10 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)10 FileUploadNotificationReceiver (com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver)9 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)9 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)9 HashMap (java.util.HashMap)9 Template (com.microsoft.azure.sdk.iot.device.Template)8 CustomLogger (com.microsoft.azure.sdk.iot.device.CustomLogger)6 DeviceMethodMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage)6 IOException (java.io.IOException)6 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)5