use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class GenerationHandler method handle.
@Override
public void handle(RoutingContext rc) {
VertxProject project = rc.get(WebVerticle.VERTX_PROJECT_KEY);
rc.vertx().eventBus().<Buffer>request(PROJECT_REQUESTED, project, reply -> {
if (reply.succeeded()) {
rc.vertx().eventBus().publish(PROJECT_CREATED, project);
Buffer content = reply.result().body();
String filename = project.getArtifactId() + "." + project.getArchiveFormat().getFileExtension();
rc.response().putHeader("Content-Type", project.getArchiveFormat().getContentType()).putHeader("Content-Disposition", "attachment; filename=" + filename).end(content);
} else {
log.error("Failed to create project " + project.getId(), reply.cause());
WebVerticle.fail(rc, 500, "Failed to create project: " + project.getId());
}
});
}
use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class GeneratorVerticle method start.
@Override
public void start(Promise<Void> startPromise) {
vertx.fileSystem().readFile("keywords", kar -> {
if (kar.succeeded()) {
Set<String> keywords = NEWLINE_REGEX.splitAsStream(kar.result().toString()).map(String::trim).filter(s -> !s.isEmpty()).collect(toSet());
generatorService = new GeneratorService(vertx, keywords);
MessageConsumer<VertxProject> consumer = vertx.eventBus().consumer(Topics.PROJECT_REQUESTED);
consumer.handler(this::onProjectRequested).completionHandler(ar -> {
if (ar.succeeded()) {
log.info("\n----------------------------------------------------------\n\t" + "{} is running!\n" + "----------------------------------------------------------", GeneratorVerticle.class.getSimpleName());
startPromise.complete();
} else {
startPromise.fail(ar.cause());
}
});
} else {
startPromise.fail(kar.cause());
}
});
}
use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class ValidationHandlerTest method expectSuccess.
private void expectSuccess(Vertx vertx, VertxTestContext testContext, ValidationHandler validator, MultiMap params, String extension, VertxProject expected) {
doTest(vertx, testContext, validator, params, extension, response -> {
testContext.verify(() -> {
assertThat(response.statusCode()).withFailMessage(response.bodyAsString()).isEqualTo(200);
VertxProject actual = Json.decodeValue(response.body(), VertxProject.class);
assertThat(actual).isEqualToIgnoringGivenFields(expected, "id", "operatingSystem", "createdOn");
testContext.completeNow();
});
});
}
use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class ValidationHandlerTest method testDependencyIncluded.
@Test
void testDependencyIncluded(Vertx vertx, VertxTestContext testContext) {
validator = new ValidationHandler(defaults, versions, stack);
VertxProject expected = defaults.mapTo(VertxProject.class).setVertxDependencies(Collections.singleton("vertx-web"));
expectSuccess(vertx, testContext, validator, params.add(VERTX_DEPENDENCIES, "vertx-web"), ZIP.getFileExtension(), expected);
}
use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.
the class ValidationHandlerTest method doTest.
private void doTest(Vertx vertx, VertxTestContext testContext, ValidationHandler validator, MultiMap params, String extension, Handler<HttpResponse<Buffer>> handler) {
Router router = Router.router(vertx);
router.route().handler(validator).handler(rc -> {
VertxProject vertProject = rc.get(WebVerticle.VERTX_PROJECT_KEY);
rc.response().end(Json.encodePrettily(vertProject));
});
vertx.createHttpServer(new HttpServerOptions().setPort(0)).requestHandler(router).listen(testContext.succeeding(server -> {
WebClientOptions options = new WebClientOptions().setDefaultPort(server.actualPort());
WebClient webClient = WebClient.create(vertx, options);
HttpRequest<Buffer> request = webClient.get("/starter" + extension);
request.queryParams().addAll(params);
request.send(testContext.succeeding(handler));
}));
}
Aggregations