Search in sources :

Example 21 with HttpsSingleMessage

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 Expectations() {

        {
            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();
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) Expectations(mockit.Expectations) HttpsSingleMessage(com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage) Message(com.microsoft.azure.sdk.iot.device.Message) HashMap(java.util.HashMap) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) HttpsSingleMessage(com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage) Test(org.junit.Test)

Example 22 with HttpsSingleMessage

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage 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));
}
Also used : MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) NonStrictExpectations(mockit.NonStrictExpectations) HttpsSingleMessage(com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage) Test(org.junit.Test)

Example 23 with HttpsSingleMessage

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage 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);
        }
    };
}
Also used : HttpsSingleMessage(com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage) Message(com.microsoft.azure.sdk.iot.device.Message) HashMap(java.util.HashMap) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) HttpsSingleMessage(com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage) Test(org.junit.Test)

Example 24 with HttpsSingleMessage

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage 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));
}
Also used : MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) NonStrictExpectations(mockit.NonStrictExpectations) HttpsSingleMessage(com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage) Test(org.junit.Test)

Example 25 with HttpsSingleMessage

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage in project azure-iot-sdk-java by Azure.

the class HttpsSingleMessageTest method parseHttpsMessageFromResponseDoesNotIncludeNonAppProperties.

// Tests_SRS_HTTPSSINGLEMESSAGE_11_006: [The parsed HttpsSingleMessage shall include all valid HTTPS application-defined properties in the response header as message properties.]
@Test
public void parseHttpsMessageFromResponseDoesNotIncludeNonAppProperties(@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);
    MessageProperty[] testProperties = httpsMsg.getProperties();
    MessageProperty[] expectedProperties = {};
    assertThat(testProperties, is(expectedProperties));
}
Also used : HashMap(java.util.HashMap) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) NonStrictExpectations(mockit.NonStrictExpectations) HttpsSingleMessage(com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage) Test(org.junit.Test)

Aggregations

HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)38 Test (org.junit.Test)38 NonStrictExpectations (mockit.NonStrictExpectations)32 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)25 HttpsBatchMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsBatchMessage)12 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)11 Base64.encodeBase64String (org.apache.commons.codec.binary.Base64.encodeBase64String)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 Message (com.microsoft.azure.sdk.iot.device.Message)6 Verifications (mockit.Verifications)5 Expectations (mockit.Expectations)1