use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method parseHttpsJsonMessageFromMessageWithMessageId.
// Tests_SRS_HTTPSSINGLEMESSAGE_34_019: [If the message contains a system property, the parsed HttpsSingleMessage shall add the corresponding property with property value.]
@Test
public void parseHttpsJsonMessageFromMessageWithMessageId(@Mocked final Message mockMsg, @Mocked final MessageProperty mockProperty) {
// arrange
final byte[] body = { 0x61, 0x62, 0x63 };
final MessageProperty[] properties = { mockProperty };
final String messageidName = HTTPS_SYSTEM_PROPERTY_PREFIX + "messageid";
final String messageidValue = "test_messageid-value";
final String correlationidName = HTTPS_SYSTEM_PROPERTY_PREFIX + "correlationid";
final String correlationidValue = "1234";
final String useridName = HTTPS_SYSTEM_PROPERTY_PREFIX + "userid";
final String useridValue = "3456";
final String toName = HTTPS_SYSTEM_PROPERTY_PREFIX + "to";
final String toValue = "device4";
final String contentEncodingName = HTTPS_SYSTEM_PROPERTY_PREFIX + "contentencoding";
final String contentEncodingValue = "test_contentencoding-value";
final String contentTypeName = HTTPS_SYSTEM_PROPERTY_PREFIX + "contenttype";
final String contentTypeValue = "test_contenttype-value";
final String propertyName = "test-property-name";
final String propertyValue = "test-property-value";
new NonStrictExpectations() {
{
mockMsg.getBytes();
result = body;
mockMsg.getProperties();
result = properties;
mockMsg.getMessageId();
result = messageidValue;
mockProperty.getName();
result = propertyName;
mockProperty.getValue();
result = propertyValue;
mockMsg.getCorrelationId();
result = correlationidValue;
mockMsg.getUserId();
result = useridValue;
mockMsg.getTo();
result = toValue;
mockMsg.getContentType();
result = contentTypeValue;
mockMsg.getContentEncoding();
result = contentEncodingValue;
}
};
// act
HttpsSingleMessage httpsSingleMessage = HttpsSingleMessage.parseHttpsJsonMessage(mockMsg);
// assert
assertTrue(systemPropertyAssignedCorrectly(httpsSingleMessage.getSystemProperties(), messageidName, messageidValue));
assertTrue(systemPropertyAssignedCorrectly(httpsSingleMessage.getSystemProperties(), correlationidName, correlationidValue));
assertTrue(systemPropertyAssignedCorrectly(httpsSingleMessage.getSystemProperties(), useridName, useridValue));
assertTrue(systemPropertyAssignedCorrectly(httpsSingleMessage.getSystemProperties(), toName, toValue));
assertTrue(systemPropertyAssignedCorrectly(httpsSingleMessage.getSystemProperties(), contentTypeName, contentTypeValue));
assertTrue(systemPropertyAssignedCorrectly(httpsSingleMessage.getSystemProperties(), contentEncodingName, contentEncodingValue));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method parseHttpsMessageFromMessageSetContentType.
// Tests_SRS_HTTPSSINGLEMESSAGE_21_002: [The parsed HttpsSingleMessage shall set the contentType as `binary/octet-stream`.]
@Test
public void parseHttpsMessageFromMessageSetContentType(@Mocked final Message mockMsg, @Mocked final MessageProperty mockProperty) {
// arrange
final byte[] body = { 0x61, 0x62, 0x63 };
final MessageProperty[] properties = { mockProperty };
final String propertyName = "test-property-name";
final String propertyValue = "test-property-value";
new NonStrictExpectations() {
{
mockMsg.getBytes();
result = body;
mockMsg.getProperties();
result = properties;
mockProperty.getName();
result = propertyName;
mockProperty.getValue();
result = propertyValue;
}
};
// act
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockMsg);
// assert
String testContentType = httpsMsg.getContentType();
assertThat(testContentType, is("binary/octet-stream"));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method toMessageCopiesBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_007: [The function shall return an IoT Hub message with a copy of the message body as its body.]
@Test
public void toMessageCopiesBody(@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 Expectations() {
{
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();
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method getContentTypeReturnsCorrectContentType.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_011: [The function shall return the message content-type as 'binary/octet-stream'.]
@Test
public void getContentTypeReturnsCorrectContentType(@Mocked final Message mockMsg, @Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final boolean base64Encoded = false;
final MessageProperty[] properties = { mockProperty };
final String propertyName = "test-property-name";
final String propertyValue = "test-property-value";
new NonStrictExpectations() {
{
mockMsg.getBytes();
result = body;
mockMsg.getProperties();
result = properties;
mockProperty.getName();
result = propertyName;
mockProperty.getValue();
result = propertyValue;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockMsg);
String testContentType = httpsMsg.getContentType();
String expectedContentType = "binary/octet-stream";
assertThat(testContentType, is(expectedContentType));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class IotHubTransportMessageTest method constructorWithPropertiesSavesProperties.
// Tests_SRS_IOTHUBTRANSPORTMESSAGE_34_017: [This constructor shall return an instance of IotHubTransportMessage with provided bytes, messagetype, correlationid, messageid, and application properties.]
@Test
public void constructorWithPropertiesSavesProperties() {
// arrange
byte[] expectedData = new byte[] { 12, 34, 56 };
MessageType expectedMessageType = MessageType.DEVICE_TELEMETRY;
String expectedCorrelationId = "1234";
String expectedMessageId = "5678";
MessageProperty[] expectedProperties = new MessageProperty[2];
expectedProperties[0] = new MessageProperty("bob", "job");
expectedProperties[1] = new MessageProperty("john", "bill");
// act
IotHubTransportMessage transportMessage = new IotHubTransportMessage(expectedData, expectedMessageType, expectedMessageId, expectedCorrelationId, expectedProperties);
// assert
assertArrayEquals(expectedData, transportMessage.getBytes());
assertEquals(expectedMessageType, transportMessage.getMessageType());
assertEquals(expectedMessageId, transportMessage.getMessageId());
assertEquals(expectedCorrelationId, transportMessage.getCorrelationId());
assertEquals(expectedProperties.length, transportMessage.getProperties().length);
}
Aggregations