use of org.eclipse.hono.notification.AbstractNotification in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testDeviceConnectionIsClosedOnDeviceOrTenantChangeNotification.
private void testDeviceConnectionIsClosedOnDeviceOrTenantChangeNotification(final VertxTestContext ctx, final Device device, final AbstractNotification notification) {
// GIVEN a device connected to an adapter
givenAnAdapter(properties);
givenAnEventSenderForAnyTenant();
final MqttEndpoint endpoint = mockEndpoint();
when(endpoint.isConnected()).thenReturn(true);
final Promise<Void> startPromise = Promise.promise();
adapter.doStart(startPromise);
assertThat(startPromise.future().succeeded()).isTrue();
adapter.createMqttDeviceEndpoint(endpoint, device, OptionalInt.empty());
final Promise<Void> endpointClosedPromise = Promise.promise();
doAnswer(invocation -> {
endpointClosedPromise.complete();
return null;
}).when(endpoint).close();
// WHEN a notification is sent about the tenant/device having been deleted or disabled
NotificationEventBusSupport.sendNotification(vertx, notification);
// THEN the MQTT endpoint representing the device connection is closed
endpointClosedPromise.future().onComplete(ctx.succeeding(v -> {
ctx.verify(() -> {
// and the adapter didn't send an empty notification downstream
assertEmptyNotificationHasNotBeenSentDownstream(device.getTenantId(), device.getDeviceId(), 0);
});
ctx.completeNow();
}));
}
Aggregations