use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessageTest method setPropertyRejectsIllegalValue.
// Tests_SRS_MESSAGE_11_031: [If value name contains a character not specified in RFC 2047, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void setPropertyRejectsIllegalValue(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
final String invalidValue = "test-value@";
new NonStrictExpectations() {
{
new MessageProperty(name, invalidValue);
result = new IllegalArgumentException();
}
};
Message msg = new Message(body);
msg.setProperty(name, invalidValue);
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessageTest method getPropertiesReturnsCopyOfProperties.
// Tests_SRS_MESSAGE_11_033: [The function shall return a copy of the message properties.]
@Test
public void getPropertiesReturnsCopyOfProperties(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
final String value = "test-value";
final String httpsName = "test-https-name";
new NonStrictExpectations() {
{
new MessageProperty(name, value);
result = mockProperty;
mockProperty.hasSameName(name);
result = true;
mockProperty.getValue();
result = value;
mockProperty.getName();
result = httpsName;
}
};
Message msg = new Message(body);
msg.setProperty(name, value);
MessageProperty[] testProperties = msg.getProperties();
int expectedNumProperties = 1;
assertThat(testProperties.length, is(expectedNumProperties));
assertThat(testProperties[0], is(not(mockProperty)));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessageTest method setPropertyAndGetPropertyMatch.
// Tests_SRS_MESSAGE_11_026: [The function shall set the message property to the given value.]
// Tests_SRS_MESSAGE_11_032: [The function shall return the value associated with the message property name, where the name can be either the HTTPS or AMQPS property name.]
@Test
public void setPropertyAndGetPropertyMatch(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String name = "test-name";
final String value1 = "test-value1";
final String value2 = "test-value2";
new NonStrictExpectations() {
{
new MessageProperty(name, value1);
result = mockProperty;
mockProperty.hasSameName(name);
result = true;
mockProperty.getValue();
result = value1;
}
};
Message msg = new Message(body);
msg.setProperty(name, value1);
String testValue = msg.getProperty(name);
String expectedValue = value1;
assertThat(testValue, is(expectedValue));
new NonStrictExpectations() {
{
new MessageProperty(name, value2);
result = mockProperty;
mockProperty.hasSameName(name);
result = true;
mockProperty.getValue();
result = value2;
}
};
msg.setProperty(name, value2);
testValue = msg.getProperty(name);
expectedValue = value2;
assertThat(testValue, is(expectedValue));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessagePropertyTest method hasNameFailsForNonMatchingName.
// 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 hasNameFailsForNonMatchingName() {
final String name = "test-name";
final String value = "test-value";
MessageProperty property = new MessageProperty(name, value);
boolean testHasName = property.hasSameName("test-mame");
final boolean expectedHasName = false;
assertThat(testHasName, is(expectedHasName));
}
use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.
the class MessageTest method setPropertyRejectsIllegalName.
// Tests_SRS_MESSAGE_11_030: [If name contains a character not specified in RFC 2047, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void setPropertyRejectsIllegalName(@Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final String invalidName = " ";
final String value = "test-value";
new NonStrictExpectations() {
{
new MessageProperty(invalidName, value);
result = new IllegalArgumentException();
}
};
Message msg = new Message(body);
msg.setProperty(invalidName, value);
}
Aggregations