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));
}
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));
}
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));
}
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));
}
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);
}
Aggregations