Search in sources :

Example 11 with ProvisioningAmqpOperations

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations in project azure-iot-sdk-java by Azure.

the class ProvisioningAmqpOperationsTest method openThrowsOnNullSSLContext.

// SRS_ProvisioningAmqpOperations_07_004: [open shall throw ProvisioningDeviceClientException if either registrationId or sslContext are null or empty.]
@Test(expected = ProvisioningDeviceConnectionException.class)
public void openThrowsOnNullSSLContext() throws ProvisioningDeviceClientException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    // act
    provisioningAmqpOperations.open(TEST_REGISTRATION_ID, null, null, false);
// assert
}
Also used : ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 12 with ProvisioningAmqpOperations

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations in project azure-iot-sdk-java by Azure.

the class ProvisioningAmqpOperationsTest method closeSucceeds.

// SRS_ProvisioningAmqpOperations_07_007: [If amqpConnection is null, this method shall do nothing.]
// SRS_ProvisioningAmqpOperations_07_008: [This method shall call close on amqpConnection.]
@Test
public void closeSucceeds() throws ProvisioningDeviceClientException, IOException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    new NonStrictExpectations() {

        {
            mockedAmqpConnection.setListener((AmqpListener) any);
            mockedAmqpConnection.open();
        }
    };
    provisioningAmqpOperations.open(TEST_REGISTRATION_ID, mockedSSLContext, null, false);
    // act
    provisioningAmqpOperations.close();
    // assert
    new Verifications() {

        {
            mockedAmqpConnection.close();
            times = 1;
        }
    };
}
Also used : Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 13 with ProvisioningAmqpOperations

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations in project azure-iot-sdk-java by Azure.

the class ProvisioningAmqpOperationsTest method openSucceeds.

// SRS_ProvisioningAmqpOperations_07_005: [This method shall construct the Link Address with /<scopeId>/registrations/<registrationId>.]
@Test
public void openSucceeds() throws ProvisioningDeviceClientException, IOException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    new NonStrictExpectations() {

        {
            mockedAmqpConnection.setListener((AmqpListener) any);
            mockedAmqpConnection.open();
        }
    };
    // act
    provisioningAmqpOperations.open(TEST_REGISTRATION_ID, mockedSSLContext, null, false);
    // assert
    new Verifications() {

        {
            mockedAmqpConnection.open();
            times = 1;
        }
    };
}
Also used : Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 14 with ProvisioningAmqpOperations

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations in project azure-iot-sdk-java by Azure.

the class ProvisioningAmqpOperationsTest method closeThrowsIoException.

@Test(expected = IOException.class)
public void closeThrowsIoException() throws ProvisioningDeviceClientException, IOException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    new NonStrictExpectations() {

        {
            mockedAmqpConnection.setListener((AmqpListener) any);
            mockedAmqpConnection.open();
        }
    };
    provisioningAmqpOperations.open(TEST_REGISTRATION_ID, mockedSSLContext, null, false);
    new NonStrictExpectations() {

        {
            mockedAmqpConnection.setListener((AmqpListener) any);
            mockedAmqpConnection.close();
            result = new IOException();
        }
    };
    // act
    provisioningAmqpOperations.close();
// assert
}
Also used : IOException(java.io.IOException) NonStrictExpectations(mockit.NonStrictExpectations) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 15 with ProvisioningAmqpOperations

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations in project azure-iot-sdk-java by Azure.

the class ProvisioningAmqpOperationsTest method MessageReceivedSucceeds.

// SRS_ProvisioningAmqpOperations_07_013: [This method shall add the message to a message queue.]
// SRS_ProvisioningAmqpOperations_07_014: [This method shall then Notify the receiveLock.]
@Test
public void MessageReceivedSucceeds() throws ProvisioningDeviceClientException, IOException, InterruptedException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    // act
    provisioningAmqpOperations.messageReceived(mockedAmqpMessage);
    // assert
    new Verifications() {

        {
            mockedObjectLock.notifyLock();
            times = 1;
        }
    };
}
Also used : Verifications(mockit.Verifications) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Aggregations

ProvisioningAmqpOperations (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations)24 Test (org.junit.Test)24 NonStrictExpectations (mockit.NonStrictExpectations)12 Verifications (mockit.Verifications)5 IOException (java.io.IOException)3 AmqpMessage (com.microsoft.azure.sdk.iot.deps.transport.amqp.AmqpMessage)2 ProvisioningDeviceClientException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException)2 ProvisioningDeviceConnectionException (com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException)2