-
Notifications
You must be signed in to change notification settings - Fork 5
/
GenerateThroughEventBusTest.java
61 lines (55 loc) · 2.34 KB
/
GenerateThroughEventBusTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package io.vertx.markdown.eventbus;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.eventbus.ReplyException;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.markdown.MarkdownServiceVerticle;
import io.vertx.markdown.MarkdownServiceVertxEBProxy;
import org.junit.Test;
public class GenerateThroughEventBusTest extends MarkdownServiceTestBase {
@Test
public void simpleParagraphThroughEB(TestContext context) throws Exception {
String notFormated = "Happiness is a warm puppy";
Async async = context.async();
JsonObject message = new JsonObject();
message.put("markdown", notFormated);
DeliveryOptions options = new DeliveryOptions();
options.addHeader("action", "generateHtml");
vertx.eventBus().send("vertx.markdown", message, options, reply -> {
context.assertTrue(reply.succeeded(), "No error while parsing markdown");
context.assertNotNull(reply.result(), "Reply should not be null");
context.assertTrue(reply.result().body() instanceof String, "A String was returned");
context.assertEquals(reply.result().body(), "<p>" + notFormated + "</p>", "The generated html is the same as the sent String");
async.complete();
});
}
@Test
public void simpleParagraphThroughProxy(TestContext context) throws Exception {
String notFormated = "Happiness is a warm puppy";
Async async = context.async();
MarkdownServiceVertxEBProxy proxy = new MarkdownServiceVertxEBProxy(vertx, MarkdownServiceVerticle.ADDRESS);
proxy.generateHtml(notFormated, res -> {
context.assertTrue(res.succeeded());
context.assertEquals(res.result(), "<p>" + notFormated + "</p>", "The generated html is the same as the sent String");
async.complete();
});
}
@Test
public void unknownAction(TestContext context) throws Exception {
String action = "generateXml";
Async async = context.async();
String notFormated = "Happiness is a warm puppy";
JsonObject message = new JsonObject();
message.put("markdown", notFormated);
DeliveryOptions options = new DeliveryOptions();
options.addHeader("action", action);
options.setSendTimeout(500);
vertx.eventBus().send("vertx.markdown", message, options, ar -> {
context.assertTrue(ar.failed());
Throwable t = ar.cause();
context.assertTrue(t instanceof ReplyException);
async.complete();
});
}
}