use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod 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.mqtt.MqttDeviceMethod 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.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveThrowsIfMethodNameCouldNotBeParsed.
// Tests_SRS_MQTTDEVICEMETHOD_25_029: [**If method name not found or is null then receive shall throw TransportException **]**
@Test(expected = TransportException.class)
public void receiveThrowsIfMethodNameCouldNotBeParsed() throws TransportException {
// arrange
String topic = "$iothub/methods/POST/";
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
testMethod.receive();
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveReturnsNullMessageIfTopicNotFound.
// 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.**]**
@Test
public void receiveReturnsNullMessageIfTopicNotFound() throws TransportException {
// arrange
Queue<Pair<String, byte[]>> testreceivedMessages = new ConcurrentLinkedQueue<>();
MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
testMethod.start();
// act
Message testMessage = testMethod.receive();
// assert
assertNull(testMessage);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod 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