use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method openClearsLocalStateIfOpenInterrupted.
@Test
public void openClearsLocalStateIfOpenInterrupted() throws TransportException, InterruptedException {
// arrange
baseExpectations();
final CountDownLatch workerLinkLatch = new CountDownLatch(0);
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, "");
connection.setListener(mockedIotHubListener);
new Expectations() {
{
new CountDownLatch(anyInt);
result = workerLinkLatch;
workerLinkLatch.await(anyLong, TimeUnit.SECONDS);
// simulates getting interrupted while opening
result = new InterruptedException("test interrupted exception");
}
};
// act
try {
connection.open();
fail("expected an exception to be thrown");
} catch (TransportException e) {
// expected exception
}
Map<String, AmqpsSessionHandler> sessionHandlers = Deencapsulation.getField(connection, "sessionHandlers");
Queue<AmqpsSasTokenRenewalHandler> sasTokenRenewalHandlers = Deencapsulation.getField(connection, "sasTokenRenewalHandlers");
assertTrue(sessionHandlers.isEmpty());
assertTrue(sasTokenRenewalHandlers.isEmpty());
}
use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class PahoExceptionTranslatorTest method onConnectionLostMapsFailedAuthenticationException.
// Tests_SRS_PahoExceptionTranslator_34_144: [When deriving the TransportException from the provided MqttException, this function shall map REASON_CODE_FAILED_AUTHENTICATION to MqttBadUsernameOrPasswordException.]
@Test
public void onConnectionLostMapsFailedAuthenticationException() throws IOException, TransportException {
// arrange
new NonStrictExpectations() {
{
mockedMqttException.getReasonCode();
result = MqttException.REASON_CODE_FAILED_AUTHENTICATION;
}
};
// act
Exception e = PahoExceptionTranslator.convertToMqttException(new MqttException(MqttException.REASON_CODE_FAILED_AUTHENTICATION), "");
// assert
assertTrue(e instanceof MqttBadUsernameOrPasswordException);
}
use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class PahoExceptionTranslatorTest method onConnectionLostMapsUnexpectedConnectCodeException.
// Tests_SRS_PahoExceptionTranslator_34_147: [When deriving the TransportException from the provided MqttException, this function shall map any connect codes between 6 and 255 inclusive to MqttUnexpectedErrorException.]
@Test
public void onConnectionLostMapsUnexpectedConnectCodeException() throws IOException, TransportException {
// arrange
new NonStrictExpectations() {
{
mockedMqttException.getReasonCode();
result = MqttException.REASON_CODE_UNEXPECTED_ERROR;
}
};
// act
Exception e = PahoExceptionTranslator.convertToMqttException(new MqttException(MqttException.REASON_CODE_UNEXPECTED_ERROR), "");
// assert
assertTrue(e instanceof MqttUnexpectedErrorException);
}
use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class PahoExceptionTranslatorTest method onConnectionLostMapsInvalidProtocolVersionException.
// Tests_SRS_PahoExceptionTranslator_34_141: [When deriving the TransportException from the provided MqttException, this function shall map REASON_CODE_INVALID_PROTOCOL_VERSION to MqttRejectedProtocolVersionException.]
@Test
public void onConnectionLostMapsInvalidProtocolVersionException() {
// arrange
new NonStrictExpectations() {
{
mockedMqttException.getReasonCode();
result = MqttException.REASON_CODE_INVALID_PROTOCOL_VERSION;
}
};
// act
Exception e = PahoExceptionTranslator.convertToMqttException(new MqttException(MqttException.REASON_CODE_INVALID_PROTOCOL_VERSION), "");
// assert
assertTrue(e instanceof MqttRejectedProtocolVersionException);
}
use of com.microsoft.azure.sdk.iot.device.exceptions.TransportException in project azure-iot-sdk-java by Azure.
the class PahoExceptionTranslatorTest method onConnectionLostMapsUnknownPahoException.
// Tests_SRS_PahoExceptionTranslator_34_148: [When deriving the TransportException from the provided MqttException, this function shall map all other MqttExceptions to ProtocolException.]
@Test
public void onConnectionLostMapsUnknownPahoException() throws IOException, TransportException {
// arrange
new NonStrictExpectations() {
{
mockedMqttException.getReasonCode();
result = MqttException.REASON_CODE_SSL_CONFIG_ERROR;
}
};
// act
Exception e = PahoExceptionTranslator.convertToMqttException(new MqttException(MqttException.REASON_CODE_SSL_CONFIG_ERROR), "");
// assert
assertTrue(e instanceof ProtocolException);
}
Aggregations