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);
}
Aggregations