Search in sources :

Example 71 with IotHubTransportMessage

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

the class DeviceTwin method checkSubscription.

private void checkSubscription() {
    if (!isSubscribed) {
        IotHubTransportMessage desiredPropertiesNotificationRequest = new IotHubTransportMessage(new byte[0], MessageType.DEVICE_TWIN);
        desiredPropertiesNotificationRequest.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST);
        this.deviceIO.sendEventAsync(desiredPropertiesNotificationRequest, new deviceTwinRequestMessageCallback(), null, this.config.getDeviceId());
    }
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)

Example 72 with IotHubTransportMessage

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

the class DeviceTwin method getDeviceTwin.

public void getDeviceTwin() {
    checkSubscription();
    IotHubTransportMessage getTwinRequestMessage = new IotHubTransportMessage(new byte[0], MessageType.DEVICE_TWIN);
    getTwinRequestMessage.setRequestId(UUID.randomUUID().toString());
    getTwinRequestMessage.setCorrelationId(getTwinRequestMessage.getRequestId());
    getTwinRequestMessage.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_GET_REQUEST);
    this.deviceIO.sendEventAsync(getTwinRequestMessage, new deviceTwinRequestMessageCallback(), null, this.config.getDeviceId());
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)

Example 73 with IotHubTransportMessage

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

the class MqttDeviceMethodTest method sendSucceedsCallsPublish.

/*
    Tests_SRS_MqttDeviceMethod_25_022: [**send method shall build the publish topic of the format mentioned in spec ($iothub/methods/res/{status}/?$rid={request id}) and publish if the operation is of type DEVICE_OPERATION_METHOD_SEND_RESPONSE.**]**
     */
@Test
public void sendSucceedsCallsPublish(@Mocked final Mqtt mockMqtt) throws IOException, TransportException {
    final byte[] actualPayload = "TestMessage".getBytes(StandardCharsets.UTF_8);
    final IotHubTransportMessage testMessage = new IotHubTransportMessage(actualPayload, MessageType.DEVICE_METHODS);
    testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_SEND_RESPONSE);
    testMessage.setRequestId("ReqId");
    testMessage.setStatus("testStatus");
    final MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
    testMethod.start();
    // act
    testMethod.send(testMessage);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(testMethod, "publish", new Class[] { String.class, Message.class }, anyString, any);
            maxTimes = 1;
        }
    };
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) Verifications(mockit.Verifications) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 74 with IotHubTransportMessage

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

the class MqttDeviceMethodTest method sendSucceedsCallsSubscribe.

/*
    Tests_SRS_MqttDeviceMethod_25_020: [**send method shall subscribe to topic from spec ($iothub/methods/POST/#) if the operation is of type DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST.**]**
     */
@Test
public void sendSucceedsCallsSubscribe(@Mocked final Mqtt mockMqtt) throws IOException, TransportException {
    // arrange
    final String actualSubscribeTopic = "$iothub/methods/POST/#";
    byte[] actualPayload = "TestMessage".getBytes(StandardCharsets.UTF_8);
    IotHubTransportMessage testMessage = new IotHubTransportMessage(actualPayload, MessageType.DEVICE_METHODS);
    testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST);
    final MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
    testMethod.start();
    // act
    testMethod.send(testMessage);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(testMethod, "subscribe", actualSubscribeTopic);
            maxTimes = 1;
        }
    };
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) Verifications(mockit.Verifications) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 75 with IotHubTransportMessage

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

the class MqttDeviceMethodTest method sendThrowsOnInvalidOperation.

@Test(expected = TransportException.class)
public void sendThrowsOnInvalidOperation(@Mocked final Mqtt mockMqtt) throws TransportException {
    final byte[] actualPayload = "TestMessage".getBytes(StandardCharsets.UTF_8);
    final IotHubTransportMessage testMessage = new IotHubTransportMessage(actualPayload, MessageType.DEVICE_METHODS);
    testMessage.setDeviceOperationType(DEVICE_OPERATION_UNKNOWN);
    MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
    testMethod.start();
    // act
    testMethod.send(testMessage);
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Aggregations

IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)129 Test (org.junit.Test)108 Message (com.microsoft.azure.sdk.iot.device.Message)37 MutablePair (org.apache.commons.lang3.tuple.MutablePair)33 Pair (org.apache.commons.lang3.tuple.Pair)33 DeviceTwin (com.microsoft.azure.sdk.iot.device.DeviceTwin)30 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)25 HashMap (java.util.HashMap)24 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)16 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)16 MessageType (com.microsoft.azure.sdk.iot.device.MessageType)14 Verifications (mockit.Verifications)10 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)8 NonStrictExpectations (mockit.NonStrictExpectations)8 IOException (java.io.IOException)5 FileUploadTask (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask)4 MessageCallback (com.microsoft.azure.sdk.iot.device.MessageCallback)3 MethodResult (com.microsoft.azure.sdk.iot.device.edge.MethodResult)3 HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)3 HashSet (java.util.HashSet)3