use of org.eclipse.hono.adapter.monitoring.HonoEventConnectionEventProducer in project hono by eclipse.
the class AbstractProtocolAdapterBaseTest method testConnectionEventGetsSent.
/**
* Verifies that the (default) ConnectionEvent API configured for a protocol adapter
* forwards the message to downstream applications.
*
* @param ctx The vert.x test context.
*/
@Test
public void testConnectionEventGetsSent(final VertxTestContext ctx) {
// GIVEN a protocol adapter configured to send connection events
final ConnectionEventProducer connectionEventProducer = new HonoEventConnectionEventProducer();
adapter.setConnectionEventProducer(connectionEventProducer);
when(amqpEventSender.sendEvent(any(TenantObject.class), any(RegistrationAssertion.class), any(), any(), any(), any())).thenReturn(Future.succeededFuture());
// WHEN a device connects to such an adapter
final Device authenticatedDevice = new Device(Constants.DEFAULT_TENANT, "4711");
final TenantObject tenantObject = TenantObject.from(Constants.DEFAULT_TENANT, true);
when(tenantClient.get(eq(Constants.DEFAULT_TENANT), any())).thenReturn(Future.succeededFuture(tenantObject));
// THEN the adapter forwards the connection event message downstream
adapter.sendConnectedEvent("remote-id", authenticatedDevice, null).onComplete(ctx.succeeding(result -> {
ctx.verify(() -> {
verify(amqpEventSender).sendEvent(eq(tenantObject), argThat(assertion -> assertion.getDeviceId().equals("4711")), eq(EventConstants.EVENT_CONNECTION_NOTIFICATION_CONTENT_TYPE), any(Buffer.class), any(), any());
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.adapter.monitoring.HonoEventConnectionEventProducer in project hono by eclipse.
the class AbstractProtocolAdapterBaseTest method testConnectionEventWithTenantConfiguredMessaging.
/**
* Verifies that when a tenant is configured to use Kafka-based messaging, the connection event is forwarded to
* Kafka.
*
* @param ctx The vert.x test context.
*/
@Test
public void testConnectionEventWithTenantConfiguredMessaging(final VertxTestContext ctx) {
// GIVEN a protocol adapter configured to send connection events
final ConnectionEventProducer connectionEventProducer = new HonoEventConnectionEventProducer();
adapter.setConnectionEventProducer(connectionEventProducer);
when(kafkaEventSender.sendEvent(any(TenantObject.class), any(RegistrationAssertion.class), any(), any(), any(), any())).thenReturn(Future.succeededFuture());
// WHEN a device of a tenant that is configured to use Kafka-based messaging connects to such an adapter
final Device authenticatedDevice = new Device(Constants.DEFAULT_TENANT, "4711");
final TenantObject tenantObject = TenantObject.from(Constants.DEFAULT_TENANT, true);
tenantObject.setProperty(TenantConstants.FIELD_EXT, Map.of(TenantConstants.FIELD_EXT_MESSAGING_TYPE, MessagingType.kafka.name()));
when(tenantClient.get(eq(Constants.DEFAULT_TENANT), any())).thenReturn(Future.succeededFuture(tenantObject));
// THEN the adapter forwards the connection event message downstream
adapter.sendConnectedEvent("remote-id", authenticatedDevice, null).onComplete(ctx.succeeding(result -> {
ctx.verify(() -> {
verify(kafkaEventSender).sendEvent(eq(tenantObject), argThat(assertion -> assertion.getDeviceId().equals("4711")), eq(EventConstants.EVENT_CONNECTION_NOTIFICATION_CONTENT_TYPE), any(Buffer.class), any(), any());
});
ctx.completeNow();
}));
}
Aggregations