use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method toMessageRemovesPrefixFromProperties.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_008: [The function shall return an IoT Hub message with application-defined properties that have the prefix 'iothub-app' removed.]
@Test
public void toMessageRemovesPrefixFromProperties(@Mocked final HttpsResponse mockResponse, @Mocked final MessageProperty mockProperty, @Mocked final Message mockMsg) {
final byte[] body = { 0x61, 0x62, 0x63 };
final Map<String, String> headerFields = new HashMap<>();
final String propertyName = "iothub-app-test-property-name";
final String propertyValue = "test-property-value";
headerFields.put(propertyName, propertyValue);
new NonStrictExpectations() {
{
mockResponse.getBody();
result = body;
mockResponse.getHeaderFields();
result = headerFields;
MessageProperty.isValidAppProperty(propertyName, propertyValue);
result = true;
new MessageProperty(propertyName, propertyValue);
result = mockProperty;
mockProperty.getName();
result = propertyName;
mockProperty.getValue();
result = propertyValue;
new Message(body);
result = mockMsg;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockResponse);
httpsMsg.toMessage();
final String expectedPropertyName = "test-property-name";
final String expectedPropertyValue = propertyValue;
new Verifications() {
{
mockMsg.setProperty(expectedPropertyName, expectedPropertyValue);
}
};
}
use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class MessageTest method getPropertyRejectsNonexistentProperty.
// Tests_SRS_MESSAGE_11_034: [If no value associated with the property name is found, the function shall return null.]
@Test
public void getPropertyRejectsNonexistentProperty(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
Message msg = new Message(body);
String testValue = msg.getProperty(name);
// expected is null since test-name property doesn't exist
String expectedValue = null;
assertThat(testValue, is(expectedValue));
}
use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class MessageTest method isExpiredReturnsFalseIfCurrentTimeIsSmallerThanExpiryTime.
// 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 isExpiredReturnsFalseIfCurrentTimeIsSmallerThanExpiryTime() throws InterruptedException {
final byte[] body = { 0x61, 0x62, 0x63 };
Message msg = new Message(body);
msg.setExpiryTime(1000);
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 MqttDeviceMethodTest method receiveReturnsNullMessageIfTopicNotFound.
/*
Tests_SRS_MqttDeviceMethod_25_025: [**If the call parseTopic returns null or empty string then this method shall do nothing and return null**]**
*/
@Test
public void receiveReturnsNullMessageIfTopicNotFound() throws IOException {
//arrange
String topic = "$iothub/not_methods/POST/testMethod/?$rid=10";
byte[] actualPayload = "TestPayload".getBytes();
ConcurrentSkipListMap<String, byte[]> testAllReceivedMessages = new ConcurrentSkipListMap<>();
testAllReceivedMessages.put(topic, actualPayload);
Deencapsulation.setField(mockedMqtt, "allReceivedMessages", testAllReceivedMessages);
MqttDeviceMethod testMethod = new MqttDeviceMethod();
testMethod.start();
//act
Message testMessage = testMethod.receive();
//assert
assertNull(testMessage);
}
use of com.microsoft.azure.sdk.iot.device.Message in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveThrowsIfRIDCouldNotBeParsed.
/*
Tests_SRS_MqttDeviceMethod_25_031: [**If request id is not found or is null then receive shall throw IOException **]**
*/
@Test(expected = IOException.class)
public void receiveThrowsIfRIDCouldNotBeParsed() throws IOException {
//arrange
String topic = "$iothub/methods/POST/testMethod/";
byte[] actualPayload = "TestPayload".getBytes();
ConcurrentSkipListMap<String, byte[]> testAllReceivedMessages = new ConcurrentSkipListMap<>();
testAllReceivedMessages.put(topic, actualPayload);
Deencapsulation.setField(mockedMqtt, "allReceivedMessages", testAllReceivedMessages);
MqttDeviceMethod testMethod = new MqttDeviceMethod();
testMethod.start();
//act
Message testMessage = testMethod.receive();
}
Aggregations