Search in sources :

Example 6 with MessageType

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

the class IotHubTransportMessageTest method setMethodNameThrowsIllegalArgumentExceptionIfMethodNameIsNull.

/*
     **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_012: [**The function shall throw IllegalArgumentException if the methodName is null.**]**
     */
@Test(expected = IllegalArgumentException.class)
public void setMethodNameThrowsIllegalArgumentExceptionIfMethodNameIsNull() {
    // arrange
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    // act
    iotHubTransportMessage.setMethodName(null);
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 7 with MessageType

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

the class IotHubTransportMessageTest method setStatusSetsTheStatus.

/*
     **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_008: [**The function shall save the status.**]**
     */
@Test
public void setStatusSetsTheStatus() {
    // arrange
    String StatusStr = "abcdefg";
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    // act
    iotHubTransportMessage.setStatus(StatusStr);
    // assert
    assertEquals(StatusStr, iotHubTransportMessage.getStatus());
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 8 with MessageType

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

the class AmqpsSessionHandler method sendMessage.

SendResult sendMessage(Message message) {
    if (!this.deviceClientConfig.getDeviceId().equals(message.getConnectionDeviceId())) {
        // This should never happen since this session handler was chosen from a map of device Id -> session handler
        // so it should have the same device Id as in the map it was grabbed from.
        log.warn("Failed to send the message because this session belongs to a different device");
        return SendResult.WRONG_DEVICE;
    }
    MessageType messageType = message.getMessageType();
    if (messageType == null) {
        // Twin and method messages have a message type assigned to them when they are constructed by this SDK
        // (users can't construct twin/method messages directly), but telemetry messages don't necessarily have this
        // type assigned since users may create telemetry messages. By default, assume any messages with an
        // unassigned type are telemetry messages.
        messageType = DEVICE_TELEMETRY;
    }
    // Check if the message being sent is a subscription change message. If so, open the corresponding links.
    if (message instanceof IotHubTransportMessage) {
        IotHubTransportMessage transportMessage = (IotHubTransportMessage) message;
        DeviceOperations subscriptionType = transportMessage.getDeviceOperationType();
        if (subscriptionType == DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST) {
            return handleMethodSubscriptionRequest(transportMessage);
        }
        if (subscriptionType == DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST) {
            return handleTwinSubscriptionRequest(transportMessage);
        }
    }
    AmqpsSenderLinkHandler senderLinkHandler = this.senderLinkHandlers.get(messageType);
    if (senderLinkHandler == null) {
        // before their respective subscription messages have already opened their links.
        return SendResult.LINKS_NOT_OPEN;
    }
    if (messageType == DEVICE_TWIN) {
        if (explicitInProgressTwinSubscriptionMessage != null) {
            // has been acknowledged by the service before sending it.
            return SendResult.SUBSCRIPTION_IN_PROGRESS;
        }
        for (SubscriptionType subscriptionType : this.implicitInProgressSubscriptionMessages.values()) {
            if (subscriptionType == SubscriptionType.DESIRED_PROPERTIES_SUBSCRIPTION) {
                // executes again.
                return SendResult.SUBSCRIPTION_IN_PROGRESS;
            }
        }
    }
    AmqpsSendResult amqpsSendResult = senderLinkHandler.sendMessageAndGetDeliveryTag(message);
    if (amqpsSendResult.isDeliverySuccessful()) {
        return SendResult.SUCCESS;
    }
    return SendResult.UNKNOWN_FAILURE;
}
Also used : DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType)

Example 9 with MessageType

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

the class IotHubTransportMessageTest method getVersionGetsTheVersion.

/*
    **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_005: [**The function shall return the value of the version either set by the setter or the default (null) if unset so far.**]**
     */
@Test
public void getVersionGetsTheVersion() {
    // arrange
    String versionStr = "abcdefg";
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    iotHubTransportMessage.setVersion(versionStr);
    // act
    String version = iotHubTransportMessage.getVersion();
    // assert
    assertEquals(versionStr, version);
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 10 with MessageType

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

the class IotHubTransportMessageTest method setRequestIdSetsTheRequestId.

/*
    **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_006: [**The function shall save the request id.**]**
     */
@Test
public void setRequestIdSetsTheRequestId() {
    // arrange
    String requestIdStr = "abcdefg";
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    // act
    iotHubTransportMessage.setRequestId(requestIdStr);
    // assert
    assertEquals(requestIdStr, iotHubTransportMessage.getRequestId());
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Aggregations

MessageType (com.microsoft.azure.sdk.iot.device.MessageType)15 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)14 Test (org.junit.Test)14 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)3 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)1 Message (com.microsoft.azure.sdk.iot.device.Message)1 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)1 Date (java.util.Date)1