Search in sources :

Example 1 with AmqpSend

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

the class AmqpSendTest method constructor_checks_if_protocol_null.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_001: [The constructor shall throw IllegalArgumentException if any of the input parameter is null or empty]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_checks_if_protocol_null() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = null;
    // Act
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
}
Also used : AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 2 with AmqpSend

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

the class AmqpSendTest method onReactorInit_invalidates_SendHandler.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_005: [The event handler shall invalidate the member AmqpsSendHandler object]
@Test
public void onReactorInit_invalidates_SendHandler() throws IOException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpSend.open();
    amqpSend.onReactorInit(event);
    // Act
    amqpSend.close();
    // Assert
    assertNull(Deencapsulation.getField(amqpSend, "amqpSendHandler"));
}
Also used : AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 3 with AmqpSend

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

the class AmqpSendTest method send_initializes_Reactor.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_007: [The event handler shall initialize the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_008: [The event handler shall start the Proton reactor object]
@Test
public void send_initializes_Reactor() throws Exception {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String deviceId = "deviceId";
    String content = "abcdefghijklmnopqrst";
    Message message = new Message(content);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpSend.open();
    // Assert
    new Expectations() {

        {
            reactor = proton.reactor(amqpSend);
            reactor.run();
        }
    };
    // Act
    amqpSend.send(deviceId, message);
}
Also used : Expectations(mockit.Expectations) Message(com.microsoft.azure.sdk.iot.service.Message) AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 4 with AmqpSend

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

the class AmqpSendTest method constructor_copies_params_to_members_amqps.

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

Example 5 with AmqpSend

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

the class AmqpSendTest method constructor_checks_if_userName_null.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_001: [The constructor shall throw IllegalArgumentException if any of the input parameter is null or empty]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructor_checks_if_userName_null() {
    // Arrange
    String hostName = "aaa";
    String userName = null;
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    // Act
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
}
Also used : AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Aggregations

IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)15 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)15 Test (org.junit.Test)15 Expectations (mockit.Expectations)4 Message (com.microsoft.azure.sdk.iot.service.Message)3 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)1 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)1 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)1