use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsBatchMessage in project azure-iot-sdk-java by Azure.
the class HttpsBatchMessageTest method testAddMessage.
// Tests_SRS_HTTPSBATCHMESSAGE_11_008: [If adding the message causes the batched message to exceed 256 kb in size, the function shall throw a SizeLimitExceededException.]
// Tests_SRS_HTTPSBATCHMESSAGE_11_009: [If the function throws a SizeLimitExceedException, the batched message shall remain as if the message was never added.]
@Test
public void testAddMessage(@Mocked final HttpsSingleMessage mockMsg) throws SizeLimitExceededException {
// Note: this will currently result on a message size of 261154 bytes, considering the extra attributes contained on the json-serialized message.
// Note: so the current body size limit alone actually is (255 * 1024 - 36) bytes.
final byte[] validSizeBody = new byte[255 * 1024 - 1];
new NonStrictExpectations() {
{
mockMsg.getBodyAsString();
result = new String(validSizeBody, Message.DEFAULT_IOTHUB_MESSAGE_CHARSET);
}
};
boolean httpsBatchMessageSizeLimitVerified = false;
try {
HttpsBatchMessage batchMsg = new HttpsBatchMessage();
batchMsg.addMessage(mockMsg);
} catch (SizeLimitExceededException ex) {
httpsBatchMessageSizeLimitVerified = true;
}
assertThat(httpsBatchMessageSizeLimitVerified, is(true));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsBatchMessage in project azure-iot-sdk-java by Azure.
the class HttpsBatchMessageTest method addMessageSetsBodyCorrectly.
// Tests_SRS_HTTPSBATCHMESSAGE_11_002: [The function shall add the message as a JSON object appended to the current JSON array.]
// Tests_SRS_HTTPSBATCHMESSAGE_11_003: [The JSON object shall have the field "body" set to the raw message.]
@Test
public void addMessageSetsBodyCorrectly(@Mocked final HttpsSingleMessage mockMsg) throws SizeLimitExceededException {
final String msgBody = "test-msg-body";
final boolean isBase64Encoded = false;
new NonStrictExpectations() {
{
mockMsg.getBodyAsString();
result = msgBody;
mockMsg.isBase64Encoded();
result = isBase64Encoded;
}
};
HttpsBatchMessage batchMsg = new HttpsBatchMessage();
batchMsg.addMessage(mockMsg);
String testBatchBody = new String(batchMsg.getBody(), UTF8).replaceAll("\\s", "");
final String expectedMsgBody = "\"body\":\"" + msgBody + "\"";
assertThat(testBatchBody, containsString(expectedMsgBody));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsBatchMessage in project azure-iot-sdk-java by Azure.
the class HttpsBatchMessageTest method getPropertiesReturnsNoProperties.
// Tests_SRS_HTTPSBATCHMESSAGE_11_012: [The function shall return an empty array.]
@Test
public void getPropertiesReturnsNoProperties() {
HttpsBatchMessage batchMsg = new HttpsBatchMessage();
MessageProperty[] testProperties = batchMsg.getProperties();
MessageProperty[] expectedProperties = new MessageProperty[0];
assertThat(testProperties, is(expectedProperties));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsBatchMessage in project azure-iot-sdk-java by Azure.
the class HttpsBatchMessageTest method numMessagesInitializedCorrectly.
// Tests_SRS_HTTPSBATCHMESSAGE_11_010: [The function shall return the number of messages currently in the batch.]
@Test
public void numMessagesInitializedCorrectly(@Mocked final HttpsSingleMessage mockMsg) throws SizeLimitExceededException {
HttpsBatchMessage batchMsg = new HttpsBatchMessage();
int testNumMessages = batchMsg.numMessages();
final int expectedNumMessages = 0;
assertThat(testNumMessages, is(expectedNumMessages));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsBatchMessage in project azure-iot-sdk-java by Azure.
the class HttpsBatchMessageTest method addMessageSetsBase64Correctly.
// Tests_SRS_HTTPSBATCHMESSAGE_11_004: [The JSON object shall have the field "base64Encoded" set to whether the raw message was Base64-encoded.]
@Test
public void addMessageSetsBase64Correctly(@Mocked final HttpsSingleMessage mockMsg) throws SizeLimitExceededException {
final String msgBody = "test-msg-body";
final boolean isBase64Encoded = false;
new NonStrictExpectations() {
{
mockMsg.getBodyAsString();
result = msgBody;
mockMsg.isBase64Encoded();
result = isBase64Encoded;
}
};
HttpsBatchMessage batchMsg = new HttpsBatchMessage();
batchMsg.addMessage(mockMsg);
String testBatchBody = new String(batchMsg.getBody(), UTF8).replaceAll("\\s", "");
final String expectedMsgBase64 = "\"base64Encoded\":" + Boolean.toString(isBase64Encoded);
assertThat(testBatchBody, containsString(expectedMsgBase64));
}
Aggregations