Search in sources :

Example 11 with FeedbackReceiver

use of com.microsoft.azure.sdk.iot.service.FeedbackReceiver in project azure-iot-sdk-java by Azure.

the class FeedbackReceiverTest method receive_call_receive_timeout.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_008: [The function shall call receive(long timeoutMs) function with the default timeout]
@Test
public void receive_call_receive_timeout() throws Exception {
    // Arrange
    String hostName = "xxx";
    String userName = "xxx";
    String sasToken = "xxx";
    String deviceId = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol, deviceId);
    // Assert
    new Expectations() {

        {
            amqpReceive.receive(Deencapsulation.getField(feedbackReceiver, "DEFAULT_TIMEOUT_MS"));
        }
    };
    // Act
    feedbackReceiver.receive();
}
Also used : Expectations(mockit.Expectations) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 12 with FeedbackReceiver

use of com.microsoft.azure.sdk.iot.service.FeedbackReceiver in project azure-iot-sdk-java by Azure.

the class FeedbackReceiverTest method close_call_receiver_close_without_deviceId.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_007: [The function shall call close() on the member AMQPReceive object]
@Test
public void close_call_receiver_close_without_deviceId() throws Exception {
    // Arrange
    String hostName = "xxx";
    String userName = "xxx";
    String sasToken = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            amqpReceive.close();
        }
    };
    // Act
    feedbackReceiver.close();
}
Also used : Expectations(mockit.Expectations) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 13 with FeedbackReceiver

use of com.microsoft.azure.sdk.iot.service.FeedbackReceiver in project azure-iot-sdk-java by Azure.

the class FeedbackReceiverTest method receive_with_timeout_receiver_null_without_deviceId.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_009: [The function shall throw IOException if the member AMQPReceive object has not been initialized]
// Assert
@Test(expected = IOException.class)
public void receive_with_timeout_receiver_null_without_deviceId() throws Exception {
    // Arrange
    long timeoutMs = 1000;
    String hostName = "xxx";
    String userName = "xxx";
    String sasToken = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol);
    Deencapsulation.setField(feedbackReceiver, "amqpReceive", null);
    // Act
    feedbackReceiver.receive(timeoutMs);
}
Also used : FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 14 with FeedbackReceiver

use of com.microsoft.azure.sdk.iot.service.FeedbackReceiver in project azure-iot-sdk-java by Azure.

the class ServiceClientTest method getFeedbackReceiver_good_case.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICECLIENT_12_017: [The function shall create a FeedbackReceiver object and returns with it]
@Test
public void getFeedbackReceiver_good_case() throws Exception {
    // Arrange
    String iotHubName = "IOTHUBNAME";
    String hostName = "HOSTNAME";
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + "." + iotHubName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    String deviceId = "XXX";
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(connectionString, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            feedbackReceiver = new FeedbackReceiver(anyString, anyString, anyString, iotHubServiceClientProtocol, deviceId);
        }
    };
    // Act
    FeedbackReceiver feedbackReceiver = serviceClient.getFeedbackReceiver(deviceId);
    // Assert
    assertNotEquals(null, feedbackReceiver);
}
Also used : Expectations(mockit.Expectations) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 15 with FeedbackReceiver

use of com.microsoft.azure.sdk.iot.service.FeedbackReceiver in project azure-iot-sdk-java by Azure.

the class FeedbackReceiverTest method open_receiver_null.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_004: [The function shall throw IOException if the member AMQPReceive object has not been initialized]
// Assert
@Test(expected = IOException.class)
public void open_receiver_null() throws Exception {
    // Arrange
    String hostName = "xxx";
    String userName = "xxx";
    String sasToken = "xxx";
    String deviceId = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol, deviceId);
    Deencapsulation.setField(feedbackReceiver, "amqpReceive", null);
    // Act
    feedbackReceiver.open();
}
Also used : FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Aggregations

FeedbackReceiver (com.microsoft.azure.sdk.iot.service.FeedbackReceiver)40 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)40 Test (org.junit.Test)40 Expectations (mockit.Expectations)19 FeedbackBatch (com.microsoft.azure.sdk.iot.service.FeedbackBatch)4 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)2 AmqpReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive)1