Search in sources :

Example 1 with JsonObjectSerializer

use of io.vertx.kafka.client.serialization.JsonObjectSerializer in project hono by eclipse.

the class KafkaBasedNotificationSenderTest method testSendFailsWithTheExpectedError.

/**
 * Verifies that the send method returns the underlying error wrapped in a {@link ServerErrorException}.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testSendFailsWithTheExpectedError(final VertxTestContext ctx) {
    // GIVEN a sender sending a message
    final RuntimeException expectedError = new RuntimeException("boom");
    final MockProducer<String, JsonObject> mockProducer = new MockProducer<>(false, new StringSerializer(), new JsonObjectSerializer());
    final KafkaBasedNotificationSender sender = newSender(mockProducer);
    sender.publish(new TenantChangeNotification(CHANGE, TENANT_ID, CREATION_TIME, ENABLED)).onComplete(ctx.failing(t -> {
        ctx.verify(() -> {
            // THEN it fails with the expected error
            assertThat(t).isInstanceOf(ServerErrorException.class);
            assertThat(((ServerErrorException) t).getErrorCode()).isEqualTo(503);
            assertThat(t.getCause()).isEqualTo(expectedError);
        });
        ctx.completeNow();
    }));
    // WHEN the send operation fails
    mockProducer.errorNext(expectedError);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AbstractNotification(org.eclipse.hono.notification.AbstractNotification) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleChange(org.eclipse.hono.notification.deviceregistry.LifecycleChange) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) JsonObjectSerializer(io.vertx.kafka.client.serialization.JsonObjectSerializer) DeviceChangeNotification(org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) JsonObject(io.vertx.core.json.JsonObject) KafkaClientUnitTestHelper(org.eclipse.hono.kafka.test.KafkaClientUnitTestHelper) AllDevicesOfTenantDeletedNotification(org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification) CredentialsChangeNotification(org.eclipse.hono.notification.deviceregistry.CredentialsChangeNotification) TenantChangeNotification(org.eclipse.hono.notification.deviceregistry.TenantChangeNotification) NotificationConstants(org.eclipse.hono.notification.NotificationConstants) CachingKafkaProducerFactory(org.eclipse.hono.client.kafka.producer.CachingKafkaProducerFactory) Vertx(io.vertx.core.Vertx) ServerErrorException(org.eclipse.hono.client.ServerErrorException) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instant(java.time.Instant) VertxExtension(io.vertx.junit5.VertxExtension) Test(org.junit.jupiter.api.Test) KafkaProducerFactory(org.eclipse.hono.client.kafka.producer.KafkaProducerFactory) MockProducer(org.apache.kafka.clients.producer.MockProducer) Mockito.mock(org.mockito.Mockito.mock) MockProducer(org.apache.kafka.clients.producer.MockProducer) JsonObjectSerializer(io.vertx.kafka.client.serialization.JsonObjectSerializer) JsonObject(io.vertx.core.json.JsonObject) TenantChangeNotification(org.eclipse.hono.notification.deviceregistry.TenantChangeNotification) ServerErrorException(org.eclipse.hono.client.ServerErrorException) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) Test(org.junit.jupiter.api.Test)

Aggregations

Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 VertxExtension (io.vertx.junit5.VertxExtension)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 JsonObjectSerializer (io.vertx.kafka.client.serialization.JsonObjectSerializer)1 Instant (java.time.Instant)1 Map (java.util.Map)1 MockProducer (org.apache.kafka.clients.producer.MockProducer)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1 ServerErrorException (org.eclipse.hono.client.ServerErrorException)1 CachingKafkaProducerFactory (org.eclipse.hono.client.kafka.producer.CachingKafkaProducerFactory)1 KafkaProducerFactory (org.eclipse.hono.client.kafka.producer.KafkaProducerFactory)1 KafkaClientUnitTestHelper (org.eclipse.hono.kafka.test.KafkaClientUnitTestHelper)1 AbstractNotification (org.eclipse.hono.notification.AbstractNotification)1 NotificationConstants (org.eclipse.hono.notification.NotificationConstants)1 AllDevicesOfTenantDeletedNotification (org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification)1 CredentialsChangeNotification (org.eclipse.hono.notification.deviceregistry.CredentialsChangeNotification)1 DeviceChangeNotification (org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification)1