Search in sources :

Example 16 with MessageProperty

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

the class AmqpsSenderLinkHandler method iotHubMessageToProtonMessage.

MessageImpl iotHubMessageToProtonMessage(Message message) {
    log.trace("Converting IoT Hub message to proton message for {} sender link with address {} and link correlation id {}. IoT Hub message correlationId {}", getLinkInstanceType(), this.senderLinkAddress, this.linkCorrelationId, message.getCorrelationId());
    MessageImpl outgoingMessage = (MessageImpl) Proton.message();
    Properties properties = new Properties();
    if (message.getMessageId() != null) {
        properties.setMessageId(message.getMessageId());
    }
    if (message.getCorrelationId() != null) {
        properties.setCorrelationId(message.getCorrelationId());
    }
    if (message.getContentType() != null) {
        properties.setContentType(Symbol.valueOf(message.getContentType()));
    }
    if (message.getContentEncoding() != null) {
        properties.setContentEncoding(Symbol.valueOf(message.getContentEncoding()));
    }
    outgoingMessage.setProperties(properties);
    Map<String, Object> userProperties = new HashMap<>();
    if (message.getProperties().length > 0) {
        for (MessageProperty messageProperty : message.getProperties()) {
            if (!MessageProperty.RESERVED_PROPERTY_NAMES.contains(messageProperty.getName())) {
                userProperties.put(messageProperty.getName(), messageProperty.getValue());
            }
        }
    }
    if (message.getConnectionDeviceId() != null) {
        userProperties.put(MessageProperty.CONNECTION_DEVICE_ID, message.getConnectionDeviceId());
    }
    if (message.getConnectionModuleId() != null) {
        userProperties.put(MessageProperty.CONNECTION_MODULE_ID, message.getConnectionModuleId());
    }
    if (message.getCreationTimeUTC() != null) {
        userProperties.put(MessageProperty.IOTHUB_CREATION_TIME_UTC, message.getCreationTimeUTCString());
    }
    ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
    outgoingMessage.setApplicationProperties(applicationProperties);
    Map<Symbol, Object> messageAnnotationsMap = new HashMap<>();
    if (message.isSecurityMessage()) {
        messageAnnotationsMap.put(Symbol.valueOf(MessageProperty.IOTHUB_SECURITY_INTERFACE_ID), MessageProperty.IOTHUB_SECURITY_INTERFACE_ID_VALUE);
    }
    if (message.getComponentName() != null && !message.getComponentName().isEmpty()) {
        messageAnnotationsMap.put(Symbol.valueOf(MessageProperty.COMPONENT_ID), message.getComponentName());
    }
    MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap);
    outgoingMessage.setMessageAnnotations(messageAnnotations);
    Binary binary = new Binary(message.getBytes());
    Section section = new Data(binary);
    outgoingMessage.setBody(section);
    return outgoingMessage;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) Data(org.apache.qpid.proton.amqp.messaging.Data) Properties(org.apache.qpid.proton.amqp.messaging.Properties) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Section(org.apache.qpid.proton.amqp.messaging.Section) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Binary(org.apache.qpid.proton.amqp.Binary) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl)

Example 17 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() throws IotHubSizeExceededException {
    List<HttpsSingleMessage> mockMessageList = new ArrayList<>();
    HttpsBatchMessage batchMsg = new HttpsBatchMessage(mockMessageList);
    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) ArrayList(java.util.ArrayList) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) HttpsSingleMessage(com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage) Test(org.junit.Test)

Example 18 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 19 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();
    assertThat(testValue, is(value));
}
Also used : MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) Test(org.junit.Test)

Example 20 with MessageProperty

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

the class MessagePropertyTest method constructorSavesPropertyName.

// Tests_SRS_MESSAGEPROPERTY_11_001: [The constructor shall save the property name and value.]
// Tests_SRS_MESSAGEPROPERTY_11_004: [The function shall return the property name.]
@Test
public void constructorSavesPropertyName() {
    final String name = "test-name";
    final String value = "test-value";
    MessageProperty property = new MessageProperty(name, value);
    String testName = property.getName();
    assertThat(testName, is(name));
}
Also used : 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