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