Search in sources :

Example 1 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 sendRegisterMessageSucceeds.

// SRS_ProvisioningAmqpOperations_07_010: [This method shall send the Register AMQP Provisioning message.]
// SRS_ProvisioningAmqpOperations_07_011: [This method shall wait for the response of this message for MAX_WAIT_TO_SEND_MSG and call the responseCallback with the reply.]
@Test
public void sendRegisterMessageSucceeds() throws Exception {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    new NonStrictExpectations() {

        {
            mockedAmqpConnection.setListener((AmqpListener) any);
            mockedAmqpConnection.open();
            mockedAmqpConnection.isConnected();
            result = true;
        }
    };
    provisioningAmqpOperations.open(TEST_REGISTRATION_ID, mockedSSLContext, null, false);
    setupSendReceiveMocks();
    // act
    provisioningAmqpOperations.sendRegisterMessage(mockedResponseCallback, null, null);
// assert
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 2 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 isAmqpConnectedSucceeds.

@Test
public void isAmqpConnectedSucceeds() throws Exception {
    // 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.isConnected();
            result = true;
        }
    };
    // act
    boolean isConnected = provisioningAmqpOperations.isAmqpConnected();
    // assert
    assertTrue(isConnected);
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 3 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 isAmqpConnectedNotConnectedSucceeds.

@Test
public void isAmqpConnectedNotConnectedSucceeds() throws Exception {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    // act
    boolean isConnected = provisioningAmqpOperations.isAmqpConnected();
    // assert
    assertFalse(isConnected);
}
Also used : ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 4 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 sendStatusMessageThrowsOnWaitLock.

// SRS_ProvisioningAmqpOperations_07_018: [This method shall throw ProvisioningDeviceClientException if any failure is encountered.]
@Test(expected = ProvisioningDeviceClientException.class)
public void sendStatusMessageThrowsOnWaitLock() throws Exception {
    // 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() {

        {
            new AmqpMessage();
            result = mockedAmqpMessage;
            mockedAmqpConnection.sendAmqpMessage(mockedAmqpMessage);
            mockedObjectLock.waitLock(anyLong);
            result = new InterruptedException();
        }
    };
    // act
    provisioningAmqpOperations.sendStatusMessage(TEST_OPERATION_ID, mockedResponseCallback, null);
// assert
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) AmqpMessage(com.microsoft.azure.sdk.iot.deps.transport.amqp.AmqpMessage) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 5 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 sendStatusMessageThrowsOnSendAmqpMessage.

// SRS_ProvisioningAmqpOperations_07_018: [This method shall throw ProvisioningDeviceClientException if any failure is encountered.]
@Test(expected = ProvisioningDeviceClientException.class)
public void sendStatusMessageThrowsOnSendAmqpMessage() throws ProvisioningDeviceClientException, IOException, InterruptedException {
    // 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() {

        {
            new AmqpMessage();
            result = new Exception();
        }
    };
    // act
    provisioningAmqpOperations.sendStatusMessage(TEST_OPERATION_ID, mockedResponseCallback, null);
// assert
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) AmqpMessage(com.microsoft.azure.sdk.iot.deps.transport.amqp.AmqpMessage) ProvisioningDeviceConnectionException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException) IOException(java.io.IOException) ProvisioningDeviceClientException(com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException) 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