Search in sources :

Example 6 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 sendRegisterMessageThrowsIfSendMessageFails.

@Test(expected = ProvisioningDeviceClientException.class)
public void sendRegisterMessageThrowsIfSendMessageFails() 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();
    Deencapsulation.setField(provisioningAmqpOperations, "messageSendFailedExceptionMessage", "someError");
    // 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 7 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 sendRegisterMessageThrowsOnResponseCallbackNull.

// SRS_ProvisioningAmqpOperations_07_009: [sendRegisterMessage shall throw ProvisioningDeviceClientException if either responseCallback is null.]
@Test(expected = ProvisioningDeviceClientException.class)
public void sendRegisterMessageThrowsOnResponseCallbackNull() throws ProvisioningDeviceClientException, IOException, InterruptedException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    // act
    provisioningAmqpOperations.sendRegisterMessage(null, null, null);
// assert
}
Also used : ProvisioningAmqpOperations(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.ProvisioningAmqpOperations) Test(org.junit.Test)

Example 8 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 openThrowsOnEmptyRegistrationId.

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

Example 9 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 openOpensAmqpConnectionSynchronouslyWithoutSaslHandler.

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

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

Example 10 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 sendStatusThrowsOnOperationIdNull.

// SRS_ProvisioningAmqpOperations_07_015: [sendStatusMessage shall throw ProvisioningDeviceClientException if either operationId or responseCallback are null or empty.]
@Test(expected = ProvisioningDeviceClientException.class)
public void sendStatusThrowsOnOperationIdNull() throws ProvisioningDeviceClientException, IOException, InterruptedException {
    // arrange
    ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
    // act
    provisioningAmqpOperations.sendStatusMessage(null, mockedResponseCallback, null);
// assert
}
Also used : 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