|
17 | 17 |
|
18 | 18 | package io.cloudevents.http.vertx;
|
19 | 19 |
|
| 20 | +import static io.cloudevents.core.test.Data.DATACONTENTTYPE_JSON; |
| 21 | +import static io.cloudevents.core.test.Data.DATACONTENTTYPE_TEXT; |
| 22 | +import static io.cloudevents.core.test.Data.DATACONTENTTYPE_XML; |
| 23 | +import static io.cloudevents.core.test.Data.DATASCHEMA; |
| 24 | +import static io.cloudevents.core.test.Data.DATA_JSON_SERIALIZED; |
| 25 | +import static io.cloudevents.core.test.Data.DATA_TEXT_SERIALIZED; |
| 26 | +import static io.cloudevents.core.test.Data.DATA_XML_SERIALIZED; |
| 27 | +import static io.cloudevents.core.test.Data.ID; |
| 28 | +import static io.cloudevents.core.test.Data.SOURCE; |
| 29 | +import static io.cloudevents.core.test.Data.SUBJECT; |
| 30 | +import static io.cloudevents.core.test.Data.TIME; |
| 31 | +import static io.cloudevents.core.test.Data.TYPE; |
| 32 | +import static io.cloudevents.core.test.Data.V03_MIN; |
| 33 | +import static io.cloudevents.core.test.Data.V03_WITH_JSON_DATA; |
| 34 | +import static io.cloudevents.core.test.Data.V03_WITH_JSON_DATA_WITH_EXT_STRING; |
| 35 | +import static io.cloudevents.core.test.Data.V03_WITH_TEXT_DATA; |
| 36 | +import static io.cloudevents.core.test.Data.V03_WITH_XML_DATA; |
| 37 | +import static io.cloudevents.core.test.Data.V1_MIN; |
| 38 | +import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA; |
| 39 | +import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT_STRING; |
| 40 | +import static io.cloudevents.core.test.Data.V1_WITH_TEXT_DATA; |
| 41 | +import static io.cloudevents.core.test.Data.V1_WITH_XML_DATA; |
| 42 | +import static org.assertj.core.api.Assertions.assertThat; |
| 43 | +import static org.assertj.core.api.Assertions.assertThatCode; |
| 44 | + |
20 | 45 | import io.cloudevents.CloudEvent;
|
21 | 46 | import io.cloudevents.SpecVersion;
|
22 | 47 | import io.cloudevents.core.message.Encoding;
|
|
25 | 50 | import io.cloudevents.rw.CloudEventRWException;
|
26 | 51 | import io.cloudevents.types.Time;
|
27 | 52 | import io.vertx.core.MultiMap;
|
| 53 | +import io.vertx.core.Vertx; |
28 | 54 | import io.vertx.core.buffer.Buffer;
|
| 55 | +import io.vertx.ext.web.client.WebClient; |
| 56 | +import io.vertx.junit5.Timeout; |
| 57 | +import io.vertx.junit5.VertxExtension; |
| 58 | +import io.vertx.junit5.VertxTestContext; |
| 59 | +import java.util.concurrent.CountDownLatch; |
| 60 | +import java.util.concurrent.TimeUnit; |
| 61 | +import java.util.stream.Stream; |
29 | 62 | import org.junit.jupiter.api.Test;
|
| 63 | +import org.junit.jupiter.api.extension.ExtendWith; |
30 | 64 | import org.junit.jupiter.params.ParameterizedTest;
|
31 | 65 | import org.junit.jupiter.params.provider.Arguments;
|
32 | 66 | import org.junit.jupiter.params.provider.MethodSource;
|
33 | 67 |
|
34 |
| -import java.util.stream.Stream; |
35 |
| - |
36 |
| -import static io.cloudevents.core.test.Data.*; |
37 |
| -import static org.assertj.core.api.Assertions.assertThat; |
38 |
| -import static org.assertj.core.api.Assertions.assertThatCode; |
39 |
| - |
| 68 | +@ExtendWith(VertxExtension.class) |
40 | 69 | public class VertxMessageFactoryTest {
|
41 | 70 |
|
42 | 71 | @Test
|
@@ -78,6 +107,36 @@ public void readStructured(CloudEvent event) {
|
78 | 107 | .isEqualTo(event);
|
79 | 108 | }
|
80 | 109 |
|
| 110 | + @Test |
| 111 | + @Timeout(timeUnit = TimeUnit.SECONDS, value = 2) |
| 112 | + public void shouldCatchAllExceptions(final Vertx vertx, final VertxTestContext context) throws InterruptedException { |
| 113 | + |
| 114 | + final int port = 4200; |
| 115 | + |
| 116 | + final CountDownLatch cd = new CountDownLatch(1); |
| 117 | + |
| 118 | + vertx.createHttpServer() |
| 119 | + .exceptionHandler(context::failNow) |
| 120 | + .requestHandler(r -> VertxMessageFactory.createReader(r) |
| 121 | + .onFailure(cause -> context.completeNow()) |
| 122 | + .onSuccess(reader -> context.failNow("Expected failed future")) |
| 123 | + ) |
| 124 | + .listen(port, context.succeeding(s -> cd.countDown())); |
| 125 | + |
| 126 | + cd.await(2, TimeUnit.SECONDS); |
| 127 | + |
| 128 | + WebClient.create(vertx) |
| 129 | + .post(port, "127.0.0.1", "") |
| 130 | + .putHeader("Content-Type", "application/cloudevents+json; charset=UTF-8") |
| 131 | + .putHeader("ce-specversion", "9000.1") |
| 132 | + .putHeader("ce-type", "type") |
| 133 | + .putHeader("ce-source", "/mysource") |
| 134 | + .send() |
| 135 | + .onFailure(context::failNow) |
| 136 | + .onSuccess(r -> { |
| 137 | + }); |
| 138 | + } |
| 139 | + |
81 | 140 | public static Stream<Arguments> binaryTestArguments() {
|
82 | 141 | return Stream.of(
|
83 | 142 | // V03
|
|
0 commit comments