use of com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt in project azure-iot-sdk-java by Azure.
the class MqttTest method constructorInitiliasesWithConfig.
/*
**Tests_SRS_Mqtt_25_003: [**The constructor shall use the configuration to instantiate an instance of the inner class MqttConnectionInfo if not already created.**]**
*/
@Test
public void constructorInitiliasesWithConfig() throws IOException, MqttException {
//arrange
baseConstructorExpectations(true);
//act
Mqtt mockMqtt = instantiateMqtt(true);
//assert
Object actualInfo = Deencapsulation.getField(mockMqtt, "info");
assertNotNull(actualInfo);
MqttAsyncClient actualAsyncClient = Deencapsulation.getField(actualInfo, "mqttAsyncClient");
assertNotNull(actualAsyncClient);
MqttConnectOptions actualConnectionOptions = Deencapsulation.getField(actualInfo, "connectionOptions");
assertNotNull(actualConnectionOptions);
ConcurrentSkipListMap<String, byte[]> actualMap = Deencapsulation.getField(mockMqtt, "allReceivedMessages");
assertNotNull(actualMap);
Object actualLock = Deencapsulation.getField(mockMqtt, "MQTT_LOCK");
assertNotNull(actualLock);
baseConstructorVerifications(true);
mockMqtt.restartBaseMqtt();
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt in project azure-iot-sdk-java by Azure.
the class MqttTest method publishThrowsIOExceptionWhenAnyOfTheAsyncMethodsThrow.
/*
**Tests_SRS_Mqtt_25_047: [**If the Mqtt Client Async throws MqttException, the function shall throw an IOException with the message.**]**
*/
@Test(expected = IOException.class)
public void publishThrowsIOExceptionWhenAnyOfTheAsyncMethodsThrow() throws IOException, MqttException {
//arrange
Mqtt mockMqtt = null;
try {
baseConstructorExpectations(true);
final byte[] payload = { 0x61, 0x62, 0x63 };
new NonStrictExpectations() {
{
mockMqttAsyncClient.isConnected();
result = true;
new MqttMessage(payload);
result = mockMqttMessage;
mockMqttAsyncClient.publish(mockParseTopic, mockMqttMessage);
result = mockMqttException;
}
};
mockMqtt = instantiateMqtt(true);
Deencapsulation.invoke(mockMqtt, "connect");
//act
Deencapsulation.invoke(mockMqtt, "publish", mockParseTopic, payload);
//assert
new Verifications() {
{
mockMqttAsyncClient.isConnected();
minTimes = 1;
}
};
} finally {
testCleanUp(mockMqtt);
}
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt in project azure-iot-sdk-java by Azure.
the class MqttTest method connectSuccess.
/*
**Tests_SRS_Mqtt_25_005: [**The function shall establish an MQTT connection with an IoT Hub using the provided host name, user name, device ID, and sas token.**]**
*/
@Test
public void connectSuccess() throws IOException, MqttException {
//arrange
baseConstructorExpectations(true);
baseConnectExpectation();
Mqtt mockMqtt = instantiateMqtt(true);
//act
Deencapsulation.invoke(mockMqtt, "connect");
//assert
new Verifications() {
{
mockMqttAsyncClient.isConnected();
minTimes = 1;
mockMqttAsyncClient.connect(mockMqttConnectionOptions);
times = 1;
mockMqttToken.waitForCompletion();
times = 1;
}
};
mockMqtt.restartBaseMqtt();
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt in project azure-iot-sdk-java by Azure.
the class MqttTest method receiveReturnsNullMessageWhenParseTopicReturnsNull.
/*
**Tests_SRS_Mqtt_25_022: [**If the call parseTopic returns null or empty string then this method shall do nothing and return null**]**
*/
@Test
public void receiveReturnsNullMessageWhenParseTopicReturnsNull() throws IOException, MqttException {
//arrange
final byte[] payload = { 0x61, 0x62, 0x63 };
baseConstructorExpectations(true);
baseConnectExpectation();
new MockUp<MqttMessaging>() {
@Mock
String parseTopic() throws IOException {
return null;
}
@Mock
byte[] parsePayload(String topic) throws IOException {
return payload;
}
};
final Mqtt mockMqtt = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
try {
new NonStrictExpectations() {
{
mockMqttAsyncClient.isConnected();
result = true;
}
};
Deencapsulation.invoke(mockMqtt, "connect");
//act
Message receivedMessage = mockMqtt.receive();
//assert
assertNull(receivedMessage);
} finally {
testCleanUp(mockMqtt);
}
}
Aggregations