Search in sources :

Example 56 with IotHubTransportMessage

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

the class MqttDeviceMethodTest method receiveSucceeds.

/*
    * Tests_SRS_MQTTDEVICEMETHOD_25_026: [**This method shall call peekMessage to get the message payload from the received Messages queue corresponding to the messaging client's operation.**]**
    * Tests_SRS_MQTTDEVICEMETHOD_25_028: [**If the topic is of type post topic then this method shall parse further for method name and set it for the message by calling setMethodName for the message**]**
    * Tests_SRS_MQTTDEVICEMETHOD_25_030: [**If the topic is of type post topic then this method shall parse further to look for request id which if found is set by calling setRequestId**]**
    * Tests_SRS_MQTTDEVICEMETHOD_25_032: [**If the topic is of type post topic and if method name and request id has been successfully parsed then this method shall set operation type as DEVICE_OPERATION_METHOD_RECEIVE_REQUEST **]**
    */
@Test
public void receiveSucceeds() throws TransportException {
    // arrange
    String topic = "$iothub/methods/POST/testMethod/?$rid=10";
    byte[] actualPayload = "TestPayload".getBytes(StandardCharsets.UTF_8);
    testreceivedMessages.add(new MutablePair<>(topic, actualPayload));
    MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
    Deencapsulation.setField(testMethod, "receivedMessages", testreceivedMessages);
    testMethod.start();
    // act
    Message testMessage = testMethod.receive();
    IotHubTransportMessage testDMMessage = (IotHubTransportMessage) testMessage;
    // assert
    assertNotNull(testMessage);
    assertEquals(testMessage.getMessageType(), MessageType.DEVICE_METHODS);
    assertEquals(testDMMessage.getRequestId(), String.valueOf(10));
    assertEquals("testMethod", testDMMessage.getMethodName());
    assertEquals(testDMMessage.getDeviceOperationType(), DEVICE_OPERATION_METHOD_RECEIVE_REQUEST);
}
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)

Example 57 with IotHubTransportMessage

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

the class IotHubTransportMessageTest method setGetIotHubMethodSuccess.

/* Tests_SRS_IOTHUBTRANSPORTMESSAGE_21_002: [The setIotHubMethod shall store the iotHubMethod. This function do not evaluates this parameter.] */
/* Tests_SRS_IOTHUBTRANSPORTMESSAGE_21_004: [The getIotHubMethod shall return the stored iotHubMethod.] */
@Test
public void setGetIotHubMethodSuccess() {
    // arrange
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage("This is a valid body");
    // act
    iotHubTransportMessage.setIotHubMethod(IotHubMethod.POST);
    // assert
    assertEquals(IotHubMethod.POST, iotHubTransportMessage.getIotHubMethod());
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) Test(org.junit.Test)

Example 58 with IotHubTransportMessage

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

the class IotHubTransportMessageTest method setVersionSetsTheVersion.

/*
    **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_004: [**The function shall set the version.**]**
     */
@Test
public void setVersionSetsTheVersion() {
    // arrange
    String versionStr = "abcdefg";
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    // act
    iotHubTransportMessage.setVersion(versionStr);
    // assert
    assertEquals(versionStr, iotHubTransportMessage.getVersion());
}
Also used : IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) MessageType(com.microsoft.azure.sdk.iot.device.MessageType) Test(org.junit.Test)

Example 59 with IotHubTransportMessage

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

the class IotHubTransportMessageTest method getOperationTypeGetsTheOperationType.

/*
     **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_011: [**The function shall return the operation type either set by the setter or the default if unset so far.**]**
     */
@Test
public void getOperationTypeGetsTheOperationType() {
    // arrange
    DeviceOperations deviceOperations = DeviceOperations.DEVICE_OPERATION_TWIN_GET_REQUEST;
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    iotHubTransportMessage.setDeviceOperationType(deviceOperations);
    // act
    DeviceOperations operationType = iotHubTransportMessage.getDeviceOperationType();
    // assert
    assertEquals(deviceOperations, operationType);
}
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) Test(org.junit.Test)

Example 60 with IotHubTransportMessage

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

the class IotHubTransportMessageTest method setOperationTypeSetsTheOperationType.

/*
     **Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_010: [**The function shall save the device twin operation type.**]**
     */
@Test
public void setOperationTypeSetsTheOperationType() {
    // arrange
    DeviceOperations deviceOperations = DeviceOperations.DEVICE_OPERATION_TWIN_GET_REQUEST;
    byte[] data = new byte[1];
    MessageType messageType = MessageType.DEVICE_TWIN;
    IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
    // act
    iotHubTransportMessage.setDeviceOperationType(deviceOperations);
    // assert
    assertEquals(deviceOperations, iotHubTransportMessage.getDeviceOperationType());
}
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) 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