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();
assertThat(testBody, is(body));
body[0] = 0x34;
assertThat(testBody, is(not(body)));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessagePropertyTest method constructorSavesPropertyValueSlash.
@Test
public void constructorSavesPropertyValueSlash() {
final String name = "topic";
final String value = "/news/sports";
MessageProperty property = new MessageProperty(name, value);
String testValue = property.getValue();
assertThat(testValue, is(value));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessagePropertyTest method hasNameMatchesNameInCaseInsensitiveManner.
// Tests_SRS_MESSAGEPROPERTY_11_006: [The function shall return true if and only if the property has the given name, where the names are compared in a case-insensitive manner.]
@Test
public void hasNameMatchesNameInCaseInsensitiveManner() {
final String name = "test-name";
final String value = "test-value";
MessageProperty property = new MessageProperty(name, value);
boolean testHasName = property.hasSameName("Test-Name");
final boolean expectedHasName = true;
assertThat(testHasName, is(expectedHasName));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class SampleMessageReceiveCallback method execute.
@Override
public IotHubMessageResult execute(Message msg, Object context) {
log.debug("Received message with content: {}", new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET));
for (MessageProperty messageProperty : msg.getProperties()) {
log.debug("{}: {}", messageProperty.getName(), messageProperty.getValue());
}
IotHubMessageResult res = IotHubMessageResult.COMPLETE;
log.debug("Responding to message with {}", res.name());
return res;
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method sendShallIncludeCorrelationIdInPublishTopic.
// Tests_SRS_MqttMessaging_34_028: [If the message has a correlationId, this method shall append that correlationid to publishTopic before publishing using the key name `$.cid`.]
@Test
public void sendShallIncludeCorrelationIdInPublishTopic(@Mocked final Mqtt mockMqtt) throws TransportException {
// arrange
final byte[] messageBody = { 0x61, 0x62, 0x63 };
final MessageProperty[] messageProperties = new MessageProperty[] {};
final String correlationId = "test-correlation-id";
final String publishTopicWithCorrelationId = String.format("devices/%s/messages/events/$.cid=%s", CLIENT_ID, correlationId);
new NonStrictExpectations() {
{
mockedMessage.getBytes();
result = messageBody;
mockedMessage.getProperties();
result = messageProperties;
mockedMessage.getCorrelationId();
result = correlationId;
}
};
MqttMessaging testMqttMessaging = new MqttMessaging(CLIENT_ID, null, "", false, mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
// act
testMqttMessaging.send(mockedMessage);
// assert
new Verifications() {
{
Deencapsulation.invoke(mockMqtt, "publish", publishTopicWithCorrelationId, mockedMessage);
times = 1;
}
};
}
Aggregations