Search in sources :

Example 26 with Verifications

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

the class HttpsConnectionTest method connectStreamsRequestBody.

// Tests_SRS_HTTPSCONNECTION_11_004: [The function shall stream the request body, if present, through the connection.]
// Tests_SRS_HTTPSCONNECTION_11_009: [The function shall save the body to be sent with the request.]
@Test
public void connectStreamsRequestBody() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.PUT;
    byte[] body = { 1, 2, 3 };
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
        }
    };
    HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
    conn.writeOutput(body);
    body[0] = 5;
    conn.connect();
    final byte[] expectedBody = { 1, 2, 3 };
    new Verifications() {

        {
            mockUrl.openConnection().getOutputStream().write(expectedBody);
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 27 with Verifications

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

the class HttpsConnectionTest method constructorOpensConnection.

// Tests_SRS_HTTPSCONNECTION_11_001: [The constructor shall open a connection to the given URL.]
@Test
public void constructorOpensConnection() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.PUT;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
        }
    };
    new HttpsConnection(mockUrl, httpsMethod);
    new Verifications() {

        {
            mockUrl.openConnection();
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 28 with Verifications

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

the class HttpsConnectionTest method setRequestHeaderSetsRequestHeader.

// Tests_SRS_HTTPSCONNECTION_11_008: [The function shall set the given request header field.]
@Test
public void setRequestHeaderSetsRequestHeader() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.POST;
    final String field = "test-field";
    final String value = "test-value";
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
        }
    };
    HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
    conn.setRequestHeader(field, value);
    new Verifications() {

        {
            mockUrl.openConnection().setRequestProperty(field, value);
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 29 with Verifications

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

the class HttpsConnectionTest method constructorSetsRequestMethod.

// Tests_SRS_HTTPSCONNECTION_11_021: [The constructor shall set the HTTPS method to the given method.]
@Test
public void constructorSetsRequestMethod() throws IOException {
    final HttpsMethod httpsMethod = HttpsMethod.PUT;
    new NonStrictExpectations() {

        {
            mockUrl.getProtocol();
            result = "https";
            mockUrl.openConnection();
            result = mockUrlConn;
            mockUrlConn.getRequestMethod();
            result = httpsMethod.name();
        }
    };
    new HttpsConnection(mockUrl, httpsMethod);
    new Verifications() {

        {
            mockUrl.openConnection();
        }
    };
}
Also used : HttpsConnection(com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection) HttpsMethod(com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 30 with Verifications

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

the class FileUploadNotificationReceiverTest method receiveCallReceiveTimeout.

// Tests_SRS_SERVICE_SDK_JAVA_FILEUPLOADNOTIFICATIONRECEIVER_25_007: [ The function shall call receive(long timeoutMs) function with the default timeout ]
@Test
public void receiveCallReceiveTimeout() throws Exception {
    // Arrange
    final String hostName = "xxx";
    final String userName = "xxx";
    final String sasToken = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FileUploadNotificationReceiver fileUploadNotificationReceiver = Deencapsulation.newInstance(FileUploadNotificationReceiver.class, hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Act
    fileUploadNotificationReceiver.receive();
    // Assert
    new Verifications() {

        {
            amqpFileUploadNotificationReceive.receive(Deencapsulation.getField(fileUploadNotificationReceiver, "DEFAULT_TIMEOUT_MS"));
            times = 1;
        }
    };
}
Also used : FileUploadNotificationReceiver(com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver) Verifications(mockit.Verifications) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Aggregations

Verifications (mockit.Verifications)103 Test (org.junit.Test)103 NonStrictExpectations (mockit.NonStrictExpectations)66 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)14 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)12 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)11 AmqpResponseVerification (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpResponseVerification)11 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)10 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)10 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)10 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)10 FileUploadNotificationReceiver (com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver)9 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)9 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)9 HashMap (java.util.HashMap)9 Template (com.microsoft.azure.sdk.iot.device.Template)8 CustomLogger (com.microsoft.azure.sdk.iot.device.CustomLogger)6 DeviceMethodMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage)6 IOException (java.io.IOException)6 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)5