Search in sources :

Example 66 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class CloudEventProductionTest method testWithCloudEventDisabled.

@Test
public void testWithCloudEventDisabled() {
    String address = UUID.randomUUID().toString();
    new MapBasedConfig().with("mp.messaging.outgoing.amqp.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.amqp.address", address).with("mp.messaging.outgoing.amqp.host", host).with("mp.messaging.outgoing.amqp.port", port).with("mp.messaging.outgoing.amqp.tracing-enabled", false).with("mp.messaging.outgoing.amqp.cloud-events", false).with("amqp-username", username).with("amqp-password", password).write();
    weld.addBeanClass(AmqpSender.class);
    container = weld.initialize();
    AmqpSender bean = container.getBeanManager().createInstance().select(AmqpSender.class).get();
    Emitter<JsonObject> emitter = bean.get();
    List<io.vertx.mutiny.amqp.AmqpMessage> list = new ArrayList<>();
    usage.consume(address, list::add);
    Message<JsonObject> msg = Message.of(new JsonObject().put("message", "hello")).addMetadata(OutgoingCloudEventMetadata.builder().withSource(URI.create("test://test")).withId("some id").build());
    emitter.send(msg);
    await().until(() -> list.size() == 1);
    AmqpMessage message = list.get(0);
    assertThat(message.address()).isEqualTo(address);
    assertThat(message.contentType()).isEqualTo("application/json");
    JsonObject app = message.applicationProperties();
    assertThat(app).isNull();
    JsonObject body = message.bodyAsJsonObject();
    assertThat(body.getString("message")).isEqualTo("hello");
}
Also used : ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) AmqpMessage(io.vertx.mutiny.amqp.AmqpMessage) Test(org.junit.jupiter.api.Test)

Example 67 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class CloudEventProductionTest method testSendingStructuredCloudEventFromBeanWithDefault.

@Test
public void testSendingStructuredCloudEventFromBeanWithDefault() {
    String address = UUID.randomUUID().toString();
    new MapBasedConfig().with("mp.messaging.outgoing.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.source.address", address).with("mp.messaging.outgoing.source.host", host).with("mp.messaging.outgoing.source.port", port).with("mp.messaging.outgoing.source.tracing-enabled", false).with("mp.messaging.outgoing.source.cloud-events-mode", "structured").with("mp.messaging.outgoing.source.cloud-events-type", "greetings").with("mp.messaging.outgoing.source.cloud-events-source", "source://me").with("mp.messaging.outgoing.source.cloud-events-subject", "test").with("amqp-username", username).with("amqp-password", password).write();
    List<io.vertx.mutiny.amqp.AmqpMessage> list = new ArrayList<>();
    usage.consume(address, list::add);
    weld.addBeanClasses(Source.class);
    container = weld.initialize();
    await().until(() -> list.size() >= 10);
    assertThat(list).allSatisfy(message -> {
        assertThat(message.address()).isEqualTo(address);
        JsonObject json = message.bodyAsJsonObject();
        assertThat(json.getString("specversion")).isEqualTo("1.0");
        assertThat(json.getString("type")).isEqualTo("greetings");
        assertThat(json.getString("source")).isEqualTo("source://me");
        assertThat(json.getString("subject")).isEqualTo("test");
        assertThat(json.getString("id")).isNotNull();
        assertThat(json.getInstant("time")).isNotNull();
        assertThat(json.getString("data")).startsWith("hello-");
    });
}
Also used : ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) AmqpMessage(io.vertx.mutiny.amqp.AmqpMessage) Test(org.junit.jupiter.api.Test)

Example 68 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class CloudEventProductionTest method testSendingStructuredCloudEvents.

@Test
public void testSendingStructuredCloudEvents() {
    String address = UUID.randomUUID().toString();
    new MapBasedConfig().with("mp.messaging.outgoing.amqp.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.amqp.address", address).with("mp.messaging.outgoing.amqp.host", host).with("mp.messaging.outgoing.amqp.port", port).with("mp.messaging.outgoing.amqp.tracing-enabled", false).with("mp.messaging.outgoing.amqp.cloud-events-mode", "structured").with("amqp-username", username).with("amqp-password", password).write();
    weld.addBeanClass(AmqpSender.class);
    container = weld.initialize();
    AmqpSender bean = container.getBeanManager().createInstance().select(AmqpSender.class).get();
    Emitter<JsonObject> emitter = bean.get();
    List<io.vertx.mutiny.amqp.AmqpMessage> list = new ArrayList<>();
    usage.consume(address, list::add);
    Message<JsonObject> msg = Message.of(new JsonObject().put("message", "hello")).addMetadata(OutgoingCloudEventMetadata.builder().withSource(URI.create("test://test")).withType("type").withId("some id").build());
    emitter.send(msg);
    await().until(() -> list.size() == 1);
    AmqpMessage message = list.get(0);
    assertThat(message.address()).isEqualTo(address);
    assertThat(message.contentType()).isEqualTo(AmqpCloudEventHelper.STRUCTURED_CONTENT_TYPE);
    JsonObject json = message.bodyAsJsonObject();
    assertThat(json.getString("specversion")).isEqualTo("1.0");
    assertThat(json.getString("type")).isEqualTo("type");
    assertThat(json.getString("source")).isEqualTo("test://test");
    assertThat(json.getString("id")).isEqualTo("some id");
    assertThat(json.getJsonObject("data").getString("message")).isEqualTo("hello");
}
Also used : ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) AmqpMessage(io.vertx.mutiny.amqp.AmqpMessage) Test(org.junit.jupiter.api.Test)

Example 69 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class CloudEventProductionTest method testSendingStructuredCloudEventsWithTimestampAndSubject.

@Test
public void testSendingStructuredCloudEventsWithTimestampAndSubject() {
    String address = UUID.randomUUID().toString();
    new MapBasedConfig().with("mp.messaging.outgoing.amqp.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.amqp.address", address).with("mp.messaging.outgoing.amqp.host", host).with("mp.messaging.outgoing.amqp.port", port).with("mp.messaging.outgoing.amqp.tracing-enabled", false).with("mp.messaging.outgoing.amqp.cloud-events-mode", "structured").with("amqp-username", username).with("amqp-password", password).write();
    weld.addBeanClass(AmqpSender.class);
    container = weld.initialize();
    AmqpSender bean = container.getBeanManager().createInstance().select(AmqpSender.class).get();
    Emitter<JsonObject> emitter = bean.get();
    List<io.vertx.mutiny.amqp.AmqpMessage> list = new ArrayList<>();
    usage.consume(address, list::add);
    ZonedDateTime time = ZonedDateTime.now();
    Message<JsonObject> msg = Message.of(new JsonObject().put("message", "hello")).addMetadata(OutgoingCloudEventMetadata.builder().withSource(URI.create("test://test")).withType("type").withId("some id").withTimestamp(time).withSubject("subject").build());
    emitter.send(msg);
    await().until(() -> list.size() == 1);
    AmqpMessage message = list.get(0);
    assertThat(message.address()).isEqualTo(address);
    assertThat(message.contentType()).isEqualTo(AmqpCloudEventHelper.STRUCTURED_CONTENT_TYPE);
    JsonObject json = message.bodyAsJsonObject();
    assertThat(json.getString("specversion")).isEqualTo("1.0");
    assertThat(json.getString("type")).isEqualTo("type");
    assertThat(json.getString("source")).isEqualTo("test://test");
    assertThat(json.getString("id")).isEqualTo("some id");
    assertThat(json.getJsonObject("data").getString("message")).isEqualTo("hello");
    assertThat(json.getString("subject")).isEqualTo("subject");
    assertThat(json.getInstant("time")).isNotNull();
    assertThat(json.getInstant("time").getEpochSecond()).isEqualTo(time.toEpochSecond());
}
Also used : ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) AmqpMessage(io.vertx.mutiny.amqp.AmqpMessage) ZonedDateTime(java.time.ZonedDateTime) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Test(org.junit.jupiter.api.Test)

Example 70 with MapBasedConfig

use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.

the class CloudEventProductionTest method testSendingBinaryCloudEventsWithExtensions.

@Test
public void testSendingBinaryCloudEventsWithExtensions() {
    String address = UUID.randomUUID().toString();
    new MapBasedConfig().with("mp.messaging.outgoing.amqp.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.amqp.address", address).with("mp.messaging.outgoing.amqp.host", host).with("mp.messaging.outgoing.amqp.port", port).with("mp.messaging.outgoing.amqp.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
    weld.addBeanClass(AmqpSender.class);
    container = weld.initialize();
    AmqpSender bean = container.getBeanManager().createInstance().select(AmqpSender.class).get();
    Emitter<JsonObject> emitter = bean.get();
    List<io.vertx.mutiny.amqp.AmqpMessage> list = new ArrayList<>();
    usage.consume(address, list::add);
    Message<JsonObject> msg = Message.of(new JsonObject().put("message", "hello")).addMetadata(OutgoingCloudEventMetadata.builder().withSource(URI.create("test://test")).withType("type").withId("some id").withExtension("ext", 124).withExtension("ext2", "bonjour").build());
    emitter.send(msg);
    await().until(() -> list.size() == 1);
    AmqpMessage message = list.get(0);
    assertThat(message.address()).isEqualTo(address);
    assertThat(message.contentType()).isEqualTo("application/json");
    JsonObject app = message.applicationProperties();
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_SPEC_VERSION)).isEqualTo("1.0");
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_TYPE)).isEqualTo("type");
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_SOURCE)).isEqualTo("test://test");
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_ID)).isEqualTo("some id");
    assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_CONTENT_TYPE)).isEqualTo("application/json");
    assertThat(app.getInteger(AmqpCloudEventHelper.CE_HEADER_PREFIX + "ext")).isEqualTo(124);
    assertThat(app.getString(AmqpCloudEventHelper.CE_HEADER_PREFIX + "ext2")).isEqualTo("bonjour");
    JsonObject body = message.bodyAsJsonObject();
    assertThat(body.getString("message")).isEqualTo("hello");
}
Also used : ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) AmqpMessage(io.vertx.mutiny.amqp.AmqpMessage) Test(org.junit.jupiter.api.Test)

Aggregations

MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)272 Test (org.junit.jupiter.api.Test)223 Message (org.eclipse.microprofile.reactive.messaging.Message)69 JsonObject (io.vertx.core.json.JsonObject)63 ArrayList (java.util.ArrayList)61 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)57 TopicPartition (org.apache.kafka.common.TopicPartition)43 Awaitility.await (org.awaitility.Awaitility.await)38 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)37 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)34 Weld (org.jboss.weld.environment.se.Weld)32 KafkaMapBasedConfig (io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)31 HashMap (java.util.HashMap)29 AfterEach (org.junit.jupiter.api.AfterEach)29 Collectors (java.util.stream.Collectors)28 HealthReport (io.smallrye.reactive.messaging.health.HealthReport)26 KafkaSource (io.smallrye.reactive.messaging.kafka.impl.KafkaSource)26 IntegerDeserializer (org.apache.kafka.common.serialization.IntegerDeserializer)25 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)23 Duration (java.time.Duration)22