Search in sources :

Example 21 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 sendStatusThrowsOnOperationIdEmpty.

// SRS_ProvisioningAmqpOperations_07_015: [sendStatusMessage shall throw ProvisioningDeviceClientException if either operationId or responseCallback are null or empty.]
@Test(expected = ProvisioningDeviceClientException.class)
public void sendStatusThrowsOnOperationIdEmpty() throws ProvisioningDeviceClientException, IOException, InterruptedException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    // act
    provisioningAmqpOperations.sendStatusMessage("", mockedResponseCallback, null);
// assert
}
Also used : ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 22 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 sendStatusMessageSucceeds.

// SRS_ProvisioningAmqpOperations_07_016: [This method shall send the Operation Status AMQP Provisioning message.]
// SRS_ProvisioningAmqpOperations_07_017: [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 sendStatusMessageSucceeds() 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);
    setupSendReceiveMocks();
    // act
    provisioningAmqpOperations.sendStatusMessage(TEST_OPERATION_ID, mockedResponseCallback, null);
// assert
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 23 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 sendStatusMessageThrowsIfSendFails.

@Test(expected = ProvisioningDeviceClientException.class)
public void sendStatusMessageThrowsIfSendFails() 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);
    setupSendReceiveMocks();
    Deencapsulation.setField(provisioningAmqpOperations, "messageSendFailedExceptionMessage", "someError");
    // act
    provisioningAmqpOperations.sendStatusMessage(TEST_OPERATION_ID, mockedResponseCallback, null);
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 24 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 openOpensAmqpConnectionAsynchronouslyWithSaslHandler.

// SRS_ProvisioningAmqpOperations_34_019: [If the provided sasl handler is not null, this function shall open the underlying amqpConnection asynchronously.]
@Test
public void openOpensAmqpConnectionAsynchronouslyWithSaslHandler() throws ProvisioningDeviceClientException, IOException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    // act
    provisioningAmqpOperations.open(TEST_REGISTRATION_ID, mockedSSLContext, mockedSaslHandler, false);
    // assert
    new Verifications() {

        {
            mockedAmqpConnection.open();
            times = 0;
            mockedAmqpConnection.openAmqpAsync();
            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