Search in sources :

Example 6 with Message

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

the class AmqpSendTest method send_throwsIOException_when_open_has_not_been_called.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_009: [The event handler shall throw IOException if the send handler object is not initialized]
// Assert
@Test(expected = IOException.class)
public void send_throwsIOException_when_open_has_not_been_called() 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);
    // Act
    amqpSend.send(deviceId, message);
}
Also used : 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 7 with Message

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

the class AmqpSendTest method send_creates_ProtonMessage.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_006: [The event handler shall create a Proton message with the given content]
@Test
public void send_creates_ProtonMessage() 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();
    AmqpSendHandler handler = Deencapsulation.getField(amqpSend, "amqpSendHandler");
    // Assert
    new Expectations() {

        {
            Deencapsulation.invoke(handler, "createProtonMessage", deviceId, message);
        }
    };
    // Act
    amqpSend.send(deviceId, message);
}
Also used : Expectations(mockit.Expectations) Message(com.microsoft.azure.sdk.iot.service.Message) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) 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)7 Message (com.microsoft.azure.sdk.iot.service.Message)7 Test (org.junit.Test)7 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)4 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)4 Expectations (mockit.Expectations)4 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)3 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)1 IOException (java.io.IOException)1 MockUp (mockit.MockUp)1