Search in sources :

Example 1 with AmqpReceive

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

the class AmqpReceiveTest method amqpReceive_init_ok.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_001: [The constructor shall copy all input parameters to private member variables for event processing]
@Test
public void amqpReceive_init_ok() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    // Act
    AmqpReceive amqpReceive = new AmqpReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
    String _hostName = Deencapsulation.getField(amqpReceive, "hostName");
    String _userName = Deencapsulation.getField(amqpReceive, "userName");
    String _sasToken = Deencapsulation.getField(amqpReceive, "sasToken");
    // Assert
    assertEquals(hostName, _hostName);
    assertEquals(userName, _userName);
    assertEquals(sasToken, _sasToken);
}
Also used : AmqpReceive(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 2 with AmqpReceive

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

the class AmqpReceiveTest method onFeedbackReceived_call_flow_ok.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_010: [The function shall parse the received Json string to FeedbackBath object]
@Test
public void onFeedbackReceived_call_flow_ok() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String jsonData = "[]";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpReceive amqpReceive = new AmqpReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            FeedbackBatchMessage.parse(jsonData);
        }
    };
    // Act
    amqpReceive.onFeedbackReceived(jsonData);
}
Also used : Expectations(mockit.Expectations) AmqpReceive(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 3 with AmqpReceive

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

the class AmqpReceiveTest method receiveException_throw.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_008: [The function shall throw IOException if the send handler object is not initialized]
// Assert
@Test(expected = IOException.class)
public void receiveException_throw() throws IOException, InterruptedException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    int timeoutMs = 1;
    AmqpReceive amqpReceive = new AmqpReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Act
    amqpReceive.receive(timeoutMs);
}
Also used : AmqpReceive(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 4 with AmqpReceive

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

the class FeedbackReceiverTest method constructor_save_properties.

// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_002: [The constructor shall store deviceId]
// Tests_SRS_SERVICE_SDK_JAVA_FEEDBACKRECEIVER_12_003: [The constructor shall create a new instance of AmqpReceive object]
@Test
public void constructor_save_properties() throws Exception {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String deviceId = "xxx";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    new Expectations() {

        {
            amqpReceive = new AmqpReceive(anyString, anyString, anyString, iotHubServiceClientProtocol);
        }
    };
    // Act
    FeedbackReceiver feedbackReceiver = new FeedbackReceiver(hostName, userName, sasToken, iotHubServiceClientProtocol, deviceId);
    // Assert
    assertEquals(deviceId, Deencapsulation.getField(feedbackReceiver, "deviceId"));
}
Also used : Expectations(mockit.Expectations) AmqpReceive(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 5 with AmqpReceive

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

the class AmqpReceiveTest method onReactorInit_call_flow_and_init_ok.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_002: [The event handler shall set the member AmqpsReceiveHandler object to handle the given connection events]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_003: [The function shall create an AmqpsReceiveHandler object to handle reactor events]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPRECEIVE_12_004: [The function shall invalidate the member AmqpsReceiveHandler object]
@Test
public void onReactorInit_call_flow_and_init_ok() throws IOException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpReceive amqpReceive = new AmqpReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpReceive.open();
    // Assert
    new Expectations() {

        {
            reactor = event.getReactor();
            connection = reactor.connection(Deencapsulation.getField(amqpReceive, "amqpReceiveHandler"));
        }
    };
    // Act
    amqpReceive.onReactorInit(event);
    amqpReceive.close();
    // Assert
    assertNull(Deencapsulation.getField(amqpReceive, "amqpReceiveHandler"));
}
Also used : Expectations(mockit.Expectations) AmqpReceive(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Aggregations

IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)7 AmqpReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive)7 Test (org.junit.Test)7 Expectations (mockit.Expectations)5 FeedbackReceiver (com.microsoft.azure.sdk.iot.service.FeedbackReceiver)1