use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class HttpsBatchMessageTest method addMessageSetsPropertiesCorrectly.
// Tests_SRS_HTTPSBATCHMESSAGE_11_005: [The JSON object shall have the field "properties" set to a JSON object which has a key-value pair for each message property, where the key is the HTTPS property name and the value is the property value.]
@Test
public void addMessageSetsPropertiesCorrectly(@Mocked final HttpsSingleMessage mockMsg, @Mocked final MessageProperty mockProperty) throws SizeLimitExceededException {
final String msgBody = "test-msg-body";
final boolean isBase64Encoded = false;
final String propertyHttpsName = "test-property-name";
final String propertyValue = "test-property-value";
final MessageProperty[] properties = { mockProperty };
new NonStrictExpectations() {
{
mockMsg.getBodyAsString();
result = msgBody;
mockMsg.getProperties();
result = properties;
mockProperty.getName();
result = propertyHttpsName;
mockProperty.getValue();
result = propertyValue;
mockMsg.isBase64Encoded();
result = isBase64Encoded;
}
};
HttpsBatchMessage batchMsg = new HttpsBatchMessage();
batchMsg.addMessage(mockMsg);
String testBatchBody = new String(batchMsg.getBody(), UTF8).replaceAll("\\s", "");
final String expectedMsgProperties = "\"properties\":{\"" + propertyHttpsName + "\":\"" + propertyValue + "\"}";
assertThat(testBatchBody, containsString(expectedMsgProperties));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty 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.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessagePropertyTest method constructorSavesPropertyName.
// Tests_SRS_MESSAGEPROPERTY_11_001: [The constructor shall save the property name and value.]
// Tests_SRS_MESSAGEPROPERTY_11_004: [The function shall return the property name.]
@Test
public void constructorSavesPropertyName() {
final String name = "test-name";
final String value = "test-value";
MessageProperty property = new MessageProperty(name, value);
String testName = property.getName();
final String expectedName = name;
assertThat(testName, is(expectedName));
}
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 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));
}
Aggregations