use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method toMessageCopiesBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_007: [The function shall return an IoT Hub message with a copy of the message body as its body.]
@Test
public void toMessageCopiesBody(@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 byte[] expectedBody = body;
new Verifications() {
{
new Message(expectedBody);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method parseHttpsMessageFromResponseDoesNotBase64EncodeBody.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_005: [The parsed HttpsSingleMessage shall not be Base64-encoded.]
@Test
public void parseHttpsMessageFromResponseDoesNotBase64EncodeBody(@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);
boolean testBase64Encoded = httpsMsg.isBase64Encoded();
boolean expectedBase64Encoded = false;
assertThat(testBase64Encoded, is(expectedBase64Encoded));
}
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();
byte[] expectedBody = body;
assertThat(testBody, is(expectedBody));
expectedBody[0] = 0x34;
assertThat(testBody, is(not(expectedBody)));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage in project azure-iot-sdk-java by Azure.
the class HttpsSingleMessageTest method getBodyAsStringsReturnsUtf8Body.
// Tests_SRS_HTTPSSINGLEMESSAGE_11_010: [The function shall return the message body as a string encoded using charset UTF-8.]
@Test
public void getBodyAsStringsReturnsUtf8Body(@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);
String testBody = httpsMsg.getBodyAsString();
String expectedBody = "abc";
assertThat(testBody, is(expectedBody));
}
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();
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;
}
};
}
Aggregations