use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method getPropertiesReturnsCopyOfProperties.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_013: [The function shall return a copy of the message properties.]
@Test
public void getPropertiesReturnsCopyOfProperties(@Mocked final Message mockMsg, @Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final MessageProperty[] properties = { mockProperty };
final String propertyName = "test-property-name";
final String httpsPropertyName = "iothub-app-test-property-name";
final String propertyValue = "test-property-value";
new NonStrictExpectations() {
{
mockMsg.getBytes();
result = body;
mockMsg.getProperties();
result = properties;
mockProperty.getName();
result = propertyName;
result = httpsPropertyName;
mockProperty.getValue();
result = propertyValue;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockMsg);
MessageProperty[] testProperties = httpsMsg.getProperties();
final MessageProperty[] expectedProperties = properties;
assertThat(testProperties.length, is(expectedProperties.length));
final String expectedPropertyName = httpsPropertyName;
final String expectedPropertyValue = propertyValue;
new Verifications() {
{
new MessageProperty(expectedPropertyName, expectedPropertyValue);
times = 2;
}
};
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method getBodyReturnsCopyOfBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_009: [The function shall return a copy of the message body.]
@Test
public void getBodyReturnsCopyOfBody(@Mocked final Message mockMsg, @Mocked final MessageProperty mockProperty) {
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;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockMsg);
byte[] testBody = httpsMsg.getBody();
byte[] expectedBody = body;
assertThat(testBody, is(expectedBody));
testBody[0] = 0x34;
testBody = httpsMsg.getBody();
assertThat(testBody, is(expectedBody));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method parseHttpsMessageFromMessageCopiesBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_001: [The parsed HttpsSingleMessage shall have a copy of the original message body as its body.]
@Test
public void parseHttpsMessageFromMessageCopiesBody(@Mocked final Message mockMsg, @Mocked final MessageProperty mockProperty) {
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;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockMsg);
byte[] testBody = httpsMsg.getBody();
byte[] expectedBody = body;
assertThat(testBody, is(expectedBody));
expectedBody[0] = 0x34;
assertThat(testBody, is(not(expectedBody)));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsBatchMessageTest method getPropertiesReturnsNoProperties.
// Tests_SRS_HTTPSBATCHMESSAGE_11_012: [The function shall return an empty array.]
@Test
public void getPropertiesReturnsNoProperties() {
HttpsBatchMessage batchMsg = new HttpsBatchMessage();
MessageProperty[] testProperties = batchMsg.getProperties();
MessageProperty[] expectedProperties = new MessageProperty[0];
assertThat(testProperties, is(expectedProperties));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method sendShallMessageWithPropertiesToLowerLayer.
/*
**Tests_SRS_MqttMessaging_25_026: [**send method shall append the message properties to publishTopic before publishing.**]**
*/
@Test
public void sendShallMessageWithPropertiesToLowerLayer(@Mocked final Mqtt mockMqtt) throws IOException {
final byte[] messageBody = { 0x61, 0x62, 0x63 };
final String propertyName = "key";
final String propertyValue = "value";
final MessageProperty[] messageProperties = new MessageProperty[] { new MessageProperty(propertyName, propertyValue) };
new NonStrictExpectations() {
{
mockMessage.getBytes();
result = messageBody;
mockMessage.getProperties();
result = messageProperties;
Deencapsulation.invoke(mockMqtt, "publish", anyString, messageBody);
}
};
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
testMqttMessaging.send(mockMessage);
final String publishTopicWithProperties = String.format("devices/%s/messages/events/%s=%s", clientId, propertyName, propertyValue);
new Verifications() {
{
mockMessage.getBytes();
times = 2;
mockMessage.getProperties();
Deencapsulation.invoke(mockMqtt, "publish", publishTopicWithProperties, messageBody);
times = 1;
}
};
}
Aggregations