Search in sources :

Example 6 with Message

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

the class MessageTest method isExpiredReturnsTrueIfCurrentTimeIsGreaterThanExpiryTime.

// Tests_SRS_MESSAGE_15_036: [The function shall return true if the current time is greater than the expiry time and false otherwise.]
@Test
public void isExpiredReturnsTrueIfCurrentTimeIsGreaterThanExpiryTime() throws InterruptedException {
    final byte[] body = { 0x61, 0x62, 0x63 };
    Message msg = new Message(body);
    msg.setExpiryTime(9);
    Thread.sleep(10);
    boolean actualResult = msg.isExpired();
    boolean expectedResult = true;
    assertThat(expectedResult, is(actualResult));
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) Test(org.junit.Test)

Example 7 with Message

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

the class MessageTest method isExpiredReturnsTrueIfExpiryIsNotSet.

// Tests_SRS_MESSAGE_15_035: [The function shall return true if the expiryTime is set to 0.]
@Test
public void isExpiredReturnsTrueIfExpiryIsNotSet() {
    final byte[] body = { 0x61, 0x62, 0x63 };
    Message msg = new Message(body);
    boolean actualResult = msg.isExpired();
    boolean expectedResult = false;
    assertThat(expectedResult, is(actualResult));
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) Test(org.junit.Test)

Example 8 with Message

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

the class MessageTest method constructorSavesBody.

// Tests_SRS_MESSAGE_11_024: [The constructor shall save the message body.]
// Tests_SRS_MESSAGE_11_002: [The function shall return the message body.]
@Test
public void constructorSavesBody() {
    final byte[] body = { 1, 2, 3 };
    Message msg = new Message(body);
    byte[] testBody = msg.getBytes();
    byte[] expectedBody = body;
    assertThat(testBody, is(expectedBody));
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) Test(org.junit.Test)

Example 9 with Message

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

the class MessageTest method getBodyAsStringReturnsUtf8Body.

// Tests_SRS_MESSAGE_11_022: [The function shall return the message body, encoded using charset UTF-8.]
@Test
public void getBodyAsStringReturnsUtf8Body() {
    final byte[] body = { 0x61, 0x62, 0x63 };
    Message msg = new Message(body);
    String testBody = new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET);
    String expectedBody = new String(body, UTF8);
    assertThat(testBody, is(expectedBody));
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) Test(org.junit.Test)

Example 10 with Message

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

the class MessageTest method setPropertyRejectsIllegalName.

// Tests_SRS_MESSAGE_11_030: [If name contains a character not specified in RFC 2047, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void setPropertyRejectsIllegalName(@Mocked final MessageProperty mockProperty) {
    final byte[] body = { 0x61, 0x62, 0x63 };
    final String invalidName = "  ";
    final String value = "test-value";
    new NonStrictExpectations() {

        {
            new MessageProperty(invalidName, value);
            result = new IllegalArgumentException();
        }
    };
    Message msg = new Message(body);
    msg.setProperty(invalidName, value);
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

Message (com.microsoft.azure.sdk.iot.device.Message)31 Test (org.junit.Test)29 DeviceMethodMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage)7 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)7 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)6 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)6 NonStrictExpectations (mockit.NonStrictExpectations)6 Mqtt (com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt)4 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)4 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)3 HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)3 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 HashMap (java.util.HashMap)3 DeviceConnectionString (tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString)3 EventCallback (tests.integration.com.microsoft.azure.sdk.iot.device.EventCallback)3 Success (tests.integration.com.microsoft.azure.sdk.iot.device.Success)3 Verifications (mockit.Verifications)2 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)1