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