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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations