Search in sources :

Example 1 with MessageProperty

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

the class MessageTest method setPropertyRejectsIllegalValue.

// Tests_SRS_MESSAGE_11_031: [If value name contains a character not specified in RFC 2047, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void setPropertyRejectsIllegalValue(@Mocked final MessageProperty mockProperty) {
    final byte[] body = { 0x61, 0x62, 0x63 };
    final String name = "test-name";
    final String invalidValue = "test-value@";
    new NonStrictExpectations() {

        {
            new MessageProperty(name, invalidValue);
            result = new IllegalArgumentException();
        }
    };
    Message msg = new Message(body);
    msg.setProperty(name, invalidValue);
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 2 with MessageProperty

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

the class MessageTest method getPropertiesReturnsCopyOfProperties.

// Tests_SRS_MESSAGE_11_033: [The function shall return a copy of the message properties.]
@Test
public void getPropertiesReturnsCopyOfProperties(@Mocked final MessageProperty mockProperty) {
    final byte[] body = { 0x61, 0x62, 0x63 };
    final String name = "test-name";
    final String value = "test-value";
    final String httpsName = "test-https-name";
    new NonStrictExpectations() {

        {
            new MessageProperty(name, value);
            result = mockProperty;
            mockProperty.hasSameName(name);
            result = true;
            mockProperty.getValue();
            result = value;
            mockProperty.getName();
            result = httpsName;
        }
    };
    Message msg = new Message(body);
    msg.setProperty(name, value);
    MessageProperty[] testProperties = msg.getProperties();
    int expectedNumProperties = 1;
    assertThat(testProperties.length, is(expectedNumProperties));
    assertThat(testProperties[0], is(not(mockProperty)));
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 3 with MessageProperty

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

the class MessageTest method setPropertyAndGetPropertyMatch.

// Tests_SRS_MESSAGE_11_026: [The function shall set the message property to the given value.]
// Tests_SRS_MESSAGE_11_032: [The function shall return the value associated with the message property name, where the name can be either the HTTPS or AMQPS property name.]
@Test
public void setPropertyAndGetPropertyMatch(@Mocked final MessageProperty mockProperty) {
    final byte[] body = { 0x61, 0x62, 0x63 };
    final String name = "test-name";
    final String value1 = "test-value1";
    final String value2 = "test-value2";
    new NonStrictExpectations() {

        {
            new MessageProperty(name, value1);
            result = mockProperty;
            mockProperty.hasSameName(name);
            result = true;
            mockProperty.getValue();
            result = value1;
        }
    };
    Message msg = new Message(body);
    msg.setProperty(name, value1);
    String testValue = msg.getProperty(name);
    String expectedValue = value1;
    assertThat(testValue, is(expectedValue));
    new NonStrictExpectations() {

        {
            new MessageProperty(name, value2);
            result = mockProperty;
            mockProperty.hasSameName(name);
            result = true;
            mockProperty.getValue();
            result = value2;
        }
    };
    msg.setProperty(name, value2);
    testValue = msg.getProperty(name);
    expectedValue = value2;
    assertThat(testValue, is(expectedValue));
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 4 with MessageProperty

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

the class MessagePropertyTest method hasNameFailsForNonMatchingName.

// Tests_SRS_MESSAGEPROPERTY_11_006: [The function shall return true if and only if the property has the given name, where the names are compared in a case-insensitive manner.]
@Test
public void hasNameFailsForNonMatchingName() {
    final String name = "test-name";
    final String value = "test-value";
    MessageProperty property = new MessageProperty(name, value);
    boolean testHasName = property.hasSameName("test-mame");
    final boolean expectedHasName = false;
    assertThat(testHasName, is(expectedHasName));
}
Also used : MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) Test(org.junit.Test)

Example 5 with MessageProperty

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

the class MessageTest method setPropertyRejectsIllegalName.

// Tests_SRS_MESSAGE_11_030: [If name contains a character not specified in RFC 2047, the function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void setPropertyRejectsIllegalName(@Mocked final MessageProperty mockProperty) {
    final byte[] body = { 0x61, 0x62, 0x63 };
    final String invalidName = "  ";
    final String value = "test-value";
    new NonStrictExpectations() {

        {
            new MessageProperty(invalidName, value);
            result = new IllegalArgumentException();
        }
    };
    Message msg = new Message(body);
    msg.setProperty(invalidName, value);
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) NonStrictExpectations(mockit.NonStrictExpectations) 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