Search in sources :

Example 11 with MessageProperty

use of com.microsoft.azure.sdk.iot.device.MessageProperty 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;
        }
    };
}
Also used : 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 12 with MessageProperty

use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.

the class HttpsSingleMessageTest method getBodyReturnsCopyOfBody.

// Tests_SRS_HTTPSSINGLEMESSAGE_11_009: [The function shall return a copy of the message body.]
@Test
public void getBodyReturnsCopyOfBody(@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();
    byte[] expectedBody = body;
    assertThat(testBody, is(expectedBody));
    testBody[0] = 0x34;
    testBody = httpsMsg.getBody();
    assertThat(testBody, is(expectedBody));
}
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 13 with MessageProperty

use of com.microsoft.azure.sdk.iot.device.MessageProperty 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();
    byte[] expectedBody = body;
    assertThat(testBody, is(expectedBody));
    expectedBody[0] = 0x34;
    assertThat(testBody, is(not(expectedBody)));
}
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 14 with MessageProperty

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

Example 15 with MessageProperty

use of com.microsoft.azure.sdk.iot.device.MessageProperty in project azure-iot-sdk-java by Azure.

the class MqttMessagingTest method sendShallMessageWithPropertiesToLowerLayer.

/*
     **Tests_SRS_MqttMessaging_25_026: [**send method shall append the message properties to publishTopic before publishing.**]**
     */
@Test
public void sendShallMessageWithPropertiesToLowerLayer(@Mocked final Mqtt mockMqtt) throws IOException {
    final byte[] messageBody = { 0x61, 0x62, 0x63 };
    final String propertyName = "key";
    final String propertyValue = "value";
    final MessageProperty[] messageProperties = new MessageProperty[] { new MessageProperty(propertyName, propertyValue) };
    new NonStrictExpectations() {

        {
            mockMessage.getBytes();
            result = messageBody;
            mockMessage.getProperties();
            result = messageProperties;
            Deencapsulation.invoke(mockMqtt, "publish", anyString, messageBody);
        }
    };
    MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
    ;
    testMqttMessaging.send(mockMessage);
    final String publishTopicWithProperties = String.format("devices/%s/messages/events/%s=%s", clientId, propertyName, propertyValue);
    new Verifications() {

        {
            mockMessage.getBytes();
            times = 2;
            mockMessage.getProperties();
            Deencapsulation.invoke(mockMqtt, "publish", publishTopicWithProperties, messageBody);
            times = 1;
        }
    };
}
Also used : MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) Test(org.junit.Test)

Aggregations

MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)66 Test (org.junit.Test)56 NonStrictExpectations (mockit.NonStrictExpectations)33 HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)25 Message (com.microsoft.azure.sdk.iot.device.Message)20 HashMap (java.util.HashMap)11 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)9 Pair (org.apache.commons.lang3.tuple.Pair)7 HttpsBatchMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsBatchMessage)6 ArrayList (java.util.ArrayList)5 Verifications (mockit.Verifications)5 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)4 Base64.encodeBase64String (org.apache.commons.codec.binary.Base64.encodeBase64String)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 IotHubMessageResult (com.microsoft.azure.sdk.iot.device.IotHubMessageResult)1 MessageType (com.microsoft.azure.sdk.iot.device.MessageType)1 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)1 Date (java.util.Date)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1