Search in sources :

Example 56 with IotHubServiceClientProtocol

use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol 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 57 with IotHubServiceClientProtocol

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

the class AmqpFileUploadNotificationReceiveTest method onFeedbackReceivedCallFlowOk.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVE_25_010: [The function shall parse the received Json string to FeedbackBath object]
@Test
public void onFeedbackReceivedCallFlowOk(@Mocked FileUploadNotification mockedNotification) {
    // Arrange
    final String hostName = "aaa";
    final String userName = "bbb";
    final String sasToken = "ccc";
    final String jsonData = "[]";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpFileUploadNotificationReceive amqpFileUploadNotificationReceive = new AmqpFileUploadNotificationReceive(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Act
    amqpFileUploadNotificationReceive.onFeedbackReceived(jsonData);
    //assert
    new Verifications() {

        {
            mockNotificationParser.getBlobName();
            times = 1;
            mockNotificationParser.getBlobSizeInBytesTag();
            times = 1;
            mockNotificationParser.getBlobUri();
            times = 1;
            mockNotificationParser.getDeviceId();
            times = 1;
            mockNotificationParser.getEnqueuedTimeUtc();
            times = 1;
            mockNotificationParser.getLastUpdatedTime();
            times = 1;
        }
    };
}
Also used : Verifications(mockit.Verifications) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) AmqpFileUploadNotificationReceive(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFileUploadNotificationReceive) Test(org.junit.Test)

Example 58 with IotHubServiceClientProtocol

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

the class AmqpFileUploadNotificationReceiveTest method onReactorInitCallFlowAndInitOk.

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

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

Example 59 with IotHubServiceClientProtocol

use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol 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 60 with IotHubServiceClientProtocol

use of com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol 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)

Aggregations

IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)137 Test (org.junit.Test)137 Expectations (mockit.Expectations)60 FeedbackReceiver (com.microsoft.azure.sdk.iot.service.FeedbackReceiver)40 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)20 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)19 FileUploadNotificationReceiver (com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver)17 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)17 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)15 Verifications (mockit.Verifications)11 Message (com.microsoft.azure.sdk.iot.service.Message)7 AmqpFileUploadNotificationReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFileUploadNotificationReceive)7 AmqpReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive)7 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)6 FeedbackBatch (com.microsoft.azure.sdk.iot.service.FeedbackBatch)4 WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)3 IOException (java.io.IOException)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 MockUp (mockit.MockUp)3 Symbol (org.apache.qpid.proton.amqp.Symbol)3