use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage 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();
assertThat(testProperties.length, is(properties.length));
new Verifications() {
{
new MessageProperty(httpsPropertyName, propertyValue);
times = 2;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method parseHttpsMessageFromResponseCopiesBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_004: [The parsed HttpsSingleMessage shall have a copy of the original response body as its body.]
@Test
public void parseHttpsMessageFromResponseCopiesBody(@Mocked final HttpsResponse mockResponse, @Mocked final MessageProperty mockProperty) {
final byte[] body = { 0x61, 0x62, 0x63 };
final Map<String, String> headerFields = new HashMap<>();
final String propertyName = "test-property-name";
final String propertyValue = "test-property-value";
headerFields.put(propertyName, propertyValue);
new NonStrictExpectations() {
{
mockResponse.getBody();
result = body;
mockResponse.getHeaderFields();
result = headerFields;
}
};
HttpsSingleMessage httpsMsg = HttpsSingleMessage.parseHttpsMessage(mockResponse);
byte[] testBody = httpsMsg.getBody();
assertThat(testBody, is(body));
body[0] = 0x34;
assertThat(testBody, is(not(body)));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage 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)));
}
Aggregations