forked from ibm-messaging/kafka-java-vertx-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSocketServerTest.java
More file actions
52 lines (42 loc) · 1.63 KB
/
WebSocketServerTest.java
File metadata and controls
52 lines (42 loc) · 1.63 KB
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
/*
(C) Copyright IBM Corp. 2020 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package kafka.vertx.demo;
import static org.hamcrest.MatcherAssert.assertThat;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.codec.BodyCodec;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
@ExtendWith(VertxExtension.class)
public class WebSocketServerTest {
@BeforeEach
void setup(Vertx vertx, VertxTestContext testContext) {
vertx.deployVerticle(new WebSocketServer())
.onComplete(testContext.succeeding(id -> testContext.completeNow()));
}
@Test
@DisplayName("Templated html contains correct values")
void getTemplateResponse(Vertx vertx, VertxTestContext testContext) {
JsonObject expectedConfig = new JsonObject();
expectedConfig.put("topic", "demo");
expectedConfig.put("producerPath", "/demoproduce");
expectedConfig.put("consumerPath", "/democonsume");
final String EXPECTED = "content=\"" + expectedConfig.toString().replace("\"", """) + "\"";
WebClient client = WebClient.create(vertx);
client.get(8080, "localhost", "/")
.as(BodyCodec.string())
.send()
.onComplete(testContext.succeeding(response -> testContext.verify(() -> {
assertThat(response.body(), CoreMatchers.containsString(EXPECTED));
testContext.completeNow();
})));
}
}