use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFails.
// Tests_SRS_MQTTIOTHUBCONNECTION_15_005: [If an MQTT connection is unable to be established for any reason,
// the function shall throw an IOException.]
@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFails() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
new IotHubSasToken(mockConfig, anyLong);
result = mockToken;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
result = new IOException(anyString);
}
};
try {
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
} catch (Exception e) {
new Verifications() {
{
}
};
throw e;
}
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method startCallsConnectAndSubscribe.
/*
**Tests_SRS_MqttMessaging_25_020: [**start method shall be call connect to establish a connection to IOT Hub with the given configuration.**]**
**Tests_SRS_MqttMessaging_25_021: [**start method shall subscribe to messaging subscribe topic once connected.**]**
*/
@Test
public void startCallsConnectAndSubscribe(@Mocked final Mqtt mockMqtt) throws IOException {
new NonStrictExpectations() {
{
Deencapsulation.invoke(mockMqtt, "connect");
Deencapsulation.invoke(mockMqtt, "subscribe", anyString);
}
};
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
testMqttMessaging.start();
new Verifications() {
{
Deencapsulation.invoke(mockMqtt, "connect");
times = 1;
Deencapsulation.invoke(mockMqtt, "subscribe", anyString);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method sendShallMessageWithPropertiesToLowerLayer.
/*
**Tests_SRS_MqttMessaging_25_026: [**send method shall append the message properties to publishTopic before publishing.**]**
*/
@Test
public void sendShallMessageWithPropertiesToLowerLayer(@Mocked final Mqtt mockMqtt) throws IOException {
final byte[] messageBody = { 0x61, 0x62, 0x63 };
final String propertyName = "key";
final String propertyValue = "value";
final MessageProperty[] messageProperties = new MessageProperty[] { new MessageProperty(propertyName, propertyValue) };
new NonStrictExpectations() {
{
mockMessage.getBytes();
result = messageBody;
mockMessage.getProperties();
result = messageProperties;
Deencapsulation.invoke(mockMqtt, "publish", anyString, messageBody);
}
};
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
testMqttMessaging.send(mockMessage);
final String publishTopicWithProperties = String.format("devices/%s/messages/events/%s=%s", clientId, propertyName, propertyValue);
new Verifications() {
{
mockMessage.getBytes();
times = 2;
mockMessage.getProperties();
Deencapsulation.invoke(mockMqtt, "publish", publishTopicWithProperties, messageBody);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parsePayloadShallThrowIOExceptionIfQueueIsNull.
/*
**Tests_SRS_MqttMessaging_25_013: [**If receiveMessage queue is null then this method shall throw IOException.**]**
*/
@Test(expected = IOException.class)
public void parsePayloadShallThrowIOExceptionIfQueueIsNull(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
final String insertTopic = "$iothub/twin/PATCH/properties/desired/#";
ConcurrentSkipListMap<String, byte[]> testMap = null;
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
byte[] retrieveMessage = Deencapsulation.invoke(testMqttMessaging, "parsePayload", insertTopic);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method constructorCallsBaseConstructorWithArguments.
/*
**Tests_SRS_MqttMessaging_25_002: [**The constructor shall use the configuration to instantiate super class and passing the parameters.**]**
*/
/*
**Tests_SRS_MqttMessaging_25_003: [**The constructor construct publishTopic and subscribeTopic from deviceId.**]**
*/
@Test
public void constructorCallsBaseConstructorWithArguments(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
String actualPublishTopic = Deencapsulation.getField(testMqttMessaging, "publishTopic");
assertNotNull(actualPublishTopic);
String actualSubscribeTopic = Deencapsulation.getField(testMqttMessaging, "subscribeTopic");
assertNotNull(actualSubscribeTopic);
String actualParseTopic = Deencapsulation.getField(testMqttMessaging, "parseTopic");
assertNotNull(actualParseTopic);
}
Aggregations