Search in sources :

Example 1 with AmqpResponseVerification

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification in project azure-iot-sdk-java by Azure.

the class AmqpSendHandlerTest method sendComplete_flow_OK.

/*
    Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_029: [** The event handler shall check the status queue to get the response for the sent message **]**

    Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_030: [** The event handler shall remove the response from the queue **]**

    Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_031: [** The event handler shall get the exception from the response and throw is it is not null **]**
     */
@Test
public void sendComplete_flow_OK(@Mocked final AmqpResponseVerification mockedVerification) throws IotHubException, IOException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
    Queue<AmqpResponseVerification> testsendStatusQueue = new LinkedBlockingQueue<>();
    testsendStatusQueue.add(mockedVerification);
    Deencapsulation.setField(amqpSendHandler, "sendStatusQueue", testsendStatusQueue);
    // Assert
    new Expectations() {

        {
            mockedVerification.getException();
            result = null;
        }
    };
    // Act
    amqpSendHandler.sendComplete();
}
Also used : Expectations(mockit.Expectations) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) AmqpResponseVerification(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification) Test(org.junit.Test)

Example 2 with AmqpResponseVerification

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification in project azure-iot-sdk-java by Azure.

the class AmqpSendHandlerTest method sendComplete_throws_exception_if_found.

//Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_031: [** The event handler shall get the exception from the response and throw is it is not null **]**
@Test(expected = IotHubException.class)
public void sendComplete_throws_exception_if_found(@Mocked final AmqpResponseVerification mockedVerification, @Mocked final IotHubException mockedIotHubException) throws IotHubException, IOException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
    Queue<AmqpResponseVerification> testsendStatusQueue = new LinkedBlockingQueue<>();
    testsendStatusQueue.add(mockedVerification);
    Deencapsulation.setField(amqpSendHandler, "sendStatusQueue", testsendStatusQueue);
    // Assert
    new Expectations() {

        {
            mockedVerification.getException();
            result = mockedIotHubException;
        }
    };
    // Act
    amqpSendHandler.sendComplete();
}
Also used : Expectations(mockit.Expectations) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) AmqpResponseVerification(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification) Test(org.junit.Test)

Example 3 with AmqpResponseVerification

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification in project azure-iot-sdk-java by Azure.

the class AmqpResponseVerificationTest method constructor_saves_if_released.

@Test
public void constructor_saves_if_released() {
    //Act
    AmqpResponseVerification testVerification = new AmqpResponseVerification(mockedReleased);
    //Assert
    new Verifications() {

        {
            assertNull(testVerification.getException());
        }
    };
}
Also used : Verifications(mockit.Verifications) AmqpResponseVerification(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification) Test(org.junit.Test)

Example 4 with AmqpResponseVerification

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification in project azure-iot-sdk-java by Azure.

the class AmqpResponseVerificationTest method constructor_saves_NOT_ALLOWED_exception.

//Tests_SRS_SERVICE_SDK_JAVA_AMQPRESPONSEVERIFICATION_25_003: [** The function shall save IotHubInvalidOperationException if the amqp delivery state is rejected and error condition is amqp error code amqp:not-allowed **]**
@Test
public void constructor_saves_NOT_ALLOWED_exception() {
    //Arrange
    String errorDescription = "TestDescription";
    new NonStrictExpectations() {

        {
            mockedRejected.getError();
            result = mockedErrorCondition;
            mockedErrorCondition.getCondition();
            result = AmqpError.NOT_ALLOWED;
            mockedErrorCondition.getDescription();
            result = errorDescription;
        }
    };
    //Act
    AmqpResponseVerification testVerification = new AmqpResponseVerification(mockedRejected);
    //Assert
    new Verifications() {

        {
            assertTrue(testVerification.getException() instanceof IotHubInvalidOperationException);
        }
    };
}
Also used : Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) AmqpResponseVerification(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification) Test(org.junit.Test)

Example 5 with AmqpResponseVerification

use of com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification in project azure-iot-sdk-java by Azure.

the class AmqpResponseVerificationTest method constructor_saves_RESOURCE_LIMIT_EXCEEDED_exception.

//Tests_SRS_SERVICE_SDK_JAVA_AMQPRESPONSEVERIFICATION_25_005: [** The function shall save IotHubDeviceMaximumQueueDepthExceededException if the amqp delivery state is rejected and error condition is amqp error code amqp:resource-limit-exceeded **]**
@Test
public void constructor_saves_RESOURCE_LIMIT_EXCEEDED_exception() {
    //Arrange
    String errorDescription = "TestDescription";
    new NonStrictExpectations() {

        {
            mockedRejected.getError();
            result = mockedErrorCondition;
            mockedErrorCondition.getCondition();
            result = AmqpError.RESOURCE_LIMIT_EXCEEDED;
            mockedErrorCondition.getDescription();
            result = errorDescription;
        }
    };
    //Act
    AmqpResponseVerification testVerification = new AmqpResponseVerification(mockedRejected);
    //Assert
    new Verifications() {

        {
            assertTrue(testVerification.getException() instanceof IotHubDeviceMaximumQueueDepthExceededException);
        }
    };
}
Also used : Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) AmqpResponseVerification(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification) Test(org.junit.Test)

Aggregations

AmqpResponseVerification (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification)13 Test (org.junit.Test)13 Verifications (mockit.Verifications)11 NonStrictExpectations (mockit.NonStrictExpectations)7 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)2 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Expectations (mockit.Expectations)2