use of com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingClientDeviceRegistrationAuthenticationException in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method registerDeviceWithIncorrectCredentialsAfterOpenThrows.
// Attempt to register a single device with the wrong connection string. The thrown exception
// should contain all the exceptions thrown by the service.
@ContinuousIntegrationTest
@Test
public void registerDeviceWithIncorrectCredentialsAfterOpenThrows() throws Exception {
testInstance.setup(DEVICE_MULTIPLEX_COUNT);
testInstance.multiplexingClient.unregisterDeviceClient(testInstance.deviceClientArray.get(0));
testInstance.multiplexingClient.open();
// Get a valid connection string, but swap out the deviceId for a deviceId that does exist, but whose symmetric key is different
String incorrectConnectionString = registryManager.getDeviceConnectionString(testInstance.deviceIdentityArray.get(1)).replace(testInstance.deviceIdentityArray.get(1).getDeviceId(), testInstance.deviceIdentityArray.get(0).getDeviceId());
DeviceClient clientWithIncorrectCredentials = new DeviceClient(incorrectConnectionString, testInstance.protocol);
boolean expectedExceptionThrown = false;
try {
testInstance.multiplexingClient.registerDeviceClient(clientWithIncorrectCredentials);
} catch (MultiplexingClientDeviceRegistrationAuthenticationException e) {
Map<String, Exception> registrationExceptions = e.getRegistrationExceptions();
assertEquals(1, registrationExceptions.size());
String deviceId = testInstance.deviceIdentityArray.get(0).getDeviceId();
assertTrue(registrationExceptions.containsKey(deviceId));
assertTrue(registrationExceptions.get(deviceId) instanceof UnauthorizedException);
expectedExceptionThrown = true;
}
testInstance.multiplexingClient.close();
assertTrue("Expected exception was not thrown", expectedExceptionThrown);
}
use of com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingClientDeviceRegistrationAuthenticationException in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method failedRegistrationDoesNotAffectSubsequentRegistrations.
@ContinuousIntegrationTest
@Test
public void failedRegistrationDoesNotAffectSubsequentRegistrations() throws Exception {
testInstance.setup(0);
testInstance.multiplexingClient.open();
TestDeviceIdentity testDeviceIdentity = Tools.getTestDevice(iotHubConnectionString, this.testInstance.protocol, AuthenticationType.SAS, false);
String deviceConnectionString = registryManager.getDeviceConnectionString(testDeviceIdentity.getDevice());
String deviceNotFoundConnectionString = deviceConnectionString.replace(testDeviceIdentity.getDeviceId(), testDeviceIdentity.getDeviceId().toUpperCase());
DeviceClient validDeviceClient = new DeviceClient(deviceConnectionString, testInstance.protocol);
DeviceClient invalidDeviceClient = new DeviceClient(deviceNotFoundConnectionString, testInstance.protocol);
try {
testInstance.multiplexingClient.registerDeviceClient(invalidDeviceClient);
fail("Expected multiplexingClient to throw since it registered a device that did not exist.");
} catch (MultiplexingClientDeviceRegistrationAuthenticationException e) {
// expected throw since the deviceId in the connection string does not exist, ignore
}
testInstance.multiplexingClient.registerDeviceClient(validDeviceClient);
testSendingMessageFromDeviceClient(validDeviceClient);
testInstance.multiplexingClient.close();
}
Aggregations