BAEL-702 - Intro to Vert.x formatting changes
This commit is contained in:
parent
c071c59ada
commit
5294e7d425
|
@ -10,6 +10,11 @@ import io.vertx.core.Vertx;
|
|||
public class HelloVerticle extends AbstractVerticle {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HelloVerticle.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
Vertx vertx = Vertx.vertx();
|
||||
vertx.deployVerticle(new HelloVerticle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Future<Void> future) {
|
||||
LOGGER.info("Welcome to Vertx");
|
||||
|
@ -19,10 +24,5 @@ public class HelloVerticle extends AbstractVerticle {
|
|||
public void stop() {
|
||||
LOGGER.info("Shutting down application");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Vertx vertx = Vertx.vertx();
|
||||
vertx.deployVerticle(new HelloVerticle());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,21 +4,21 @@ import io.vertx.core.AbstractVerticle;
|
|||
import io.vertx.core.Future;
|
||||
|
||||
public class SimpleServerVerticle extends AbstractVerticle {
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Future<Void> future) {
|
||||
vertx.createHttpServer()
|
||||
.requestHandler(request -> {
|
||||
request.response()
|
||||
.end("Welcome to Vert.x Intro");
|
||||
})
|
||||
.listen(config().getInteger("http.port", 8080), result -> {
|
||||
if (result.succeeded()) {
|
||||
future.complete();
|
||||
} else {
|
||||
future.fail(result.cause());
|
||||
}
|
||||
});
|
||||
.requestHandler(request -> {
|
||||
request.response()
|
||||
.end("Welcome to Vert.x Intro");
|
||||
})
|
||||
.listen(config().getInteger("http.port", 8080), result -> {
|
||||
if (result.succeeded()) {
|
||||
future.complete();
|
||||
} else {
|
||||
future.fail(result.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,28 +14,28 @@ public class RestServiceVerticle extends AbstractVerticle {
|
|||
|
||||
Router router = Router.router(vertx);
|
||||
router.get("/api/baeldung/articles/article/:id")
|
||||
.handler(this::getArticles);
|
||||
.handler(this::getArticles);
|
||||
|
||||
vertx.createHttpServer()
|
||||
.requestHandler(router::accept)
|
||||
.listen(config().getInteger("http.port", 8080), result -> {
|
||||
if (result.succeeded()) {
|
||||
future.complete();
|
||||
} else {
|
||||
future.fail(result.cause());
|
||||
}
|
||||
});
|
||||
.requestHandler(router::accept)
|
||||
.listen(config().getInteger("http.port", 8080), result -> {
|
||||
if (result.succeeded()) {
|
||||
future.complete();
|
||||
} else {
|
||||
future.fail(result.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getArticles(RoutingContext routingContext) {
|
||||
String articleId = routingContext.request()
|
||||
.getParam("id");
|
||||
.getParam("id");
|
||||
Article article = new Article(articleId, "This is an intro to vertx", "baeldung", "01-02-2017", 1578);
|
||||
|
||||
routingContext.response()
|
||||
.putHeader("content-type", "application/json")
|
||||
.setStatusCode(200)
|
||||
.end(Json.encodePrettily(article));
|
||||
.putHeader("content-type", "application/json")
|
||||
.setStatusCode(200)
|
||||
.end(Json.encodePrettily(article));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,13 +34,13 @@ public class RestServiceVerticleTest {
|
|||
final Async async = testContext.async();
|
||||
|
||||
vertx.createHttpClient()
|
||||
.getNow(8080, "localhost", "/api/baeldung/articles/article/12345", response -> {
|
||||
response.handler(responseBody -> {
|
||||
testContext.assertTrue(responseBody.toString()
|
||||
.contains("\"id\" : \"12345\""));
|
||||
async.complete();
|
||||
.getNow(8080, "localhost", "/api/baeldung/articles/article/12345", response -> {
|
||||
response.handler(responseBody -> {
|
||||
testContext.assertTrue(responseBody.toString()
|
||||
.contains("\"id\" : \"12345\""));
|
||||
async.complete();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ public class SimpleServerVerticleTest {
|
|||
public void setup(TestContext testContext) {
|
||||
vertx = Vertx.vertx();
|
||||
|
||||
vertx.deployVerticle(SimpleServerVerticle.class.getName(),
|
||||
testContext.asyncAssertSuccess());
|
||||
vertx.deployVerticle(SimpleServerVerticle.class.getName(),
|
||||
testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -34,13 +34,13 @@ public class SimpleServerVerticleTest {
|
|||
final Async async = testContext.async();
|
||||
|
||||
vertx.createHttpClient()
|
||||
.getNow(8080, "localhost", "/", response -> {
|
||||
response.handler(responseBody -> {
|
||||
testContext.assertTrue(responseBody.toString()
|
||||
.contains("Welcome"));
|
||||
async.complete();
|
||||
.getNow(8080, "localhost", "/", response -> {
|
||||
response.handler(responseBody -> {
|
||||
testContext.assertTrue(responseBody.toString()
|
||||
.contains("Welcome"));
|
||||
async.complete();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue