Search in sources :

Example 6 with MessageProperty

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

the class MessagePropertyTest method constructorSavesPropertyValueSlash.

@Test
public void constructorSavesPropertyValueSlash() {
    final String name = "topic";
    final String value = "/news/sports";
    MessageProperty property = new MessageProperty(name, value);
    String testValue = property.getValue();
    final String expectedValue = value;
    assertThat(testValue, is(expectedValue));
}
Also used : MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) Test(org.junit.Test)

Example 7 with MessageProperty

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

the class MessagePropertyTest method constructorSavesPropertyValue.

// Tests_SRS_MESSAGEPROPERTY_11_001: [The constructor shall save the property name and value.]
// Tests_SRS_MESSAGEPROPERTY_11_005: [The function shall return the property value.]
@Test
public void constructorSavesPropertyValue() {
    final String name = "test-name";
    final String value = "test-value";
    MessageProperty property = new MessageProperty(name, value);
    String testValue = property.getValue();
    final String expectedValue = value;
    assertThat(testValue, is(expectedValue));
}
Also used : MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) Test(org.junit.Test)

Example 8 with MessageProperty

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

the class MessagePropertyTest method constructorSavesPropertyValueTab.

@Test
public void constructorSavesPropertyValueTab() {
    final String name = "names";
    final String value = "First Name" + "\t" + "\t" + "Last Name";
    MessageProperty property = new MessageProperty(name, value);
    String testValue = property.getValue();
    final String expectedValue = value;
    assertThat(testValue, is(expectedValue));
}
Also used : MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) Test(org.junit.Test)

Example 9 with MessageProperty

use of com.microsoft.azure.sdk.iot.device.MessageProperty 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);
        }
    };
}
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 10 with MessageProperty

use of com.microsoft.azure.sdk.iot.device.MessageProperty 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));
}
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)

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