use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method stopIfDisconnectFailsThrowsIOException.
@Test(expected = TransportException.class)
public void stopIfDisconnectFailsThrowsIOException(@Mocked final Mqtt mockMqtt) throws TransportException {
new StrictExpectations() {
{
Deencapsulation.invoke(mockMqtt, "connect");
Deencapsulation.invoke(mockMqtt, "subscribe", anyString);
Deencapsulation.invoke(mockMqtt, "disconnect");
result = new TransportException();
}
};
MqttMessaging testMqttMessaging = new MqttMessaging(CLIENT_ID, null, "", false, mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
testMqttMessaging.start();
testMqttMessaging.stop();
new Verifications() {
{
Deencapsulation.invoke(mockMqtt, "disconnect");
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method startThrowsIoExceptionIfSubscribeFails.
@Test(expected = TransportException.class)
public void startThrowsIoExceptionIfSubscribeFails(@Mocked final Mqtt mockMqtt) throws TransportException {
new StrictExpectations() {
{
Deencapsulation.invoke(mockMqtt, "connect");
Deencapsulation.invoke(mockMqtt, "subscribe", anyString);
result = new TransportException();
}
};
MqttMessaging testMqttMessaging = new MqttMessaging(CLIENT_ID, null, "", false, mockConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
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.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method readInputClosesStreamIfExceptionWhileReading.
// Tests_SRS_HTTPSCONNECTION_11_019: [The function shall close the input stream after it has been completely read.]
@Test
public void readInputClosesStreamIfExceptionWhileReading(@Mocked final InputStream mockIs) throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getInputStream();
result = mockIs;
mockIs.read();
result = new TransportException("This is a test exception");
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
// act
try {
byte[] testResponse = conn.readInput();
} catch (TransportException e) {
// expected exception, but not testing for it, so it can be ignored
}
new Verifications() {
{
mockIs.close();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class HttpsIotHubConnectionTest method receiveMessageThrowsProtocolConnectionExceptionIfRequestFails.
// Tests_SRS_HTTPSIOTHUBCONNECTION_11_023: [If the IoT Hub could not be reached, the function shall throw a TransportException.]
@Test(expected = TransportException.class)
public void receiveMessageThrowsProtocolConnectionExceptionIfRequestFails(@Mocked final IotHubMessageUri mockUri) throws TransportException {
new NonStrictExpectations() {
{
mockRequest.send();
result = new TransportException();
}
};
HttpsIotHubConnection conn = new HttpsIotHubConnection(mockConfig);
conn.receiveMessage();
}
use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method readInputFailsIfCannotAccessInputStreamAndIsNoRouteToHost.
// Tests_SRS_HTTPSCONNECTION_34_027: [If an UnknownHostException or a NoRouteToHostException is encountered, the thrown TransportException shall be retryable.]
@Test
public void readInputFailsIfCannotAccessInputStreamAndIsNoRouteToHost() throws IOException, TransportException {
boolean exceptionCaught = false;
final HttpsMethod httpsMethod = HttpsMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getInputStream();
result = new NoRouteToHostException();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
try {
conn.readInput();
} catch (TransportException e) {
exceptionCaught = true;
if (!e.isRetryable()) {
fail("NoRouteToHostException should yield retriable TransportException");
}
}
assertTrue(exceptionCaught);
}
Aggregations