Search in sources :

Example 51 with NonStrictExpectations

use of mockit.NonStrictExpectations 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 52 with NonStrictExpectations

use of mockit.NonStrictExpectations 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)

Example 53 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class AmqpResponseVerificationTest method getExceptionGets.

//Tests_SRS_SERVICE_SDK_JAVA_AMQPRESPONSEVERIFICATION_25_007: [** The function shall return the exception saved earlier by the constructor **]**
@Test
public void getExceptionGets() {
    //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)

Example 54 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class DeviceClientTest method openBadOpensTransportThrows.

/* Codes_SRS_DEVICECLIENT_21_007: [If the opening a connection via deviceIO is not successful, the open shall throw IOException.] */
@Test
public void openBadOpensTransportThrows() throws IOException, URISyntaxException {
    // arrange
    final String connString = "HostName=iothub.device.com;CredentialType=SharedAccessKey;DeviceId=testdevice;" + "SharedAccessKey=adjkl234j52=";
    final IotHubClientProtocol protocol = IotHubClientProtocol.AMQPS;
    new NonStrictExpectations() {

        {
            mockDeviceIO.open();
            result = new IOException();
        }
    };
    DeviceClient client = new DeviceClient(connString, protocol);
    // act
    try {
        client.open();
    } catch (IOException expected) {
    // Don't do anything, throw expected.
    }
    // assert
    new Verifications() {

        {
            mockDeviceIO.open();
            times = 1;
        }
    };
}
Also used : IOException(java.io.IOException) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 55 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class CustomLoggerTest method testLogTrace.

// Tests_SRS_CUSTOMERLOGGER_25_002: [The function shall print message for TRACE level.]
@Test
public void testLogTrace(@Mocked final Logger mockLogger) {
    final String message = "This is TRACE message";
    new NonStrictExpectations() {

        {
            Logger.getLogger((Class) any);
            result = mockLogger;
            mockLogger.isEnabledFor(Level.TRACE);
            result = true;
        }
    };
    new CustomLogger(this.getClass()).LogTrace(message);
    new Verifications() {

        {
            mockLogger.trace(anyString);
            times = 1;
        }
    };
}
Also used : CustomLogger(com.microsoft.azure.sdk.iot.device.CustomLogger) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

NonStrictExpectations (mockit.NonStrictExpectations)476 Test (org.junit.Test)470 Verifications (mockit.Verifications)154 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)77 IOException (java.io.IOException)64 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)51 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)51 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)47 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)32 HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)31 HttpConnection (com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection)26 HttpMethod (com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod)26 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)26 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)26 HashMap (java.util.HashMap)26 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)25 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)17 Date (java.util.Date)16 HashSet (java.util.HashSet)16 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)15