use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInTwin.
@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInTwin() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubSasToken(mockConfig, anyLong);
result = mockToken;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
result = mockDeviceMessaging;
new MqttDeviceMethod();
result = mockDeviceMethods;
new MqttDeviceTwin();
result = new IOException(anyString);
}
};
try {
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
} catch (Exception e) {
new Verifications() {
{
mockDeviceMessaging.stop();
times = 1;
mockDeviceMethods.stop();
times = 1;
}
};
throw e;
}
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInMethod.
@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInMethod() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubSasToken(mockConfig, anyLong);
result = mockToken;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
result = mockDeviceMessaging;
new MqttDeviceMethod();
result = new IOException(anyString);
}
};
try {
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
} catch (Exception e) {
new Verifications() {
{
mockDeviceMessaging.stop();
times = 1;
}
};
throw e;
}
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveReturnsNullMessageIfTopicWasNotPost.
// Tests_SRS_MqttDeviceMethod_34_027: [This method shall parse message to look for Post topic ($iothub/methods/POST/) and return null other wise.]
@Test
public void receiveReturnsNullMessageIfTopicWasNotPost() throws TransportException {
// arrange
String topic = "$iothub/methods/Not_POST/testMethod/?$rid=10";
byte[] actualPayload = "TestPayload".getBytes(StandardCharsets.UTF_8);
Queue<Pair<String, byte[]>> testreceivedMessages = new ConcurrentLinkedQueue<>();
testreceivedMessages.add(new MutablePair<>(topic, actualPayload));
MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
testMethod.start();
// act
Message actualMessage = testMethod.receive();
// assert
assertNull(actualMessage);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveThrowsIfRIDCouldNotBeParsed.
/*
Tests_SRS_MqttDeviceMethod_25_031: [**If request id is not found or is null then receive shall throw TransportException **]**
*/
@Test(expected = TransportException.class)
public void receiveThrowsIfRIDCouldNotBeParsed() throws TransportException {
// arrange
String topic = "$iothub/methods/POST/testMethod/";
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 startSucceedsCalls.
/*
Tests_SRS_MqttDeviceMethod_25_014: [**start method shall just mark that this class is ready to start.**]**
*/
@Test
public void startSucceedsCalls(@Mocked final Mqtt mockMqtt) throws TransportException {
// arrange
final MqttDeviceMethod testMethod = new MqttDeviceMethod("", mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
// act
testMethod.start();
// assert
new Verifications() {
{
Deencapsulation.invoke(testMethod, "subscribe", anyString);
times = 0;
}
};
}
Aggregations