Search in sources :

Example 1 with VertxProject

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());
        }
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) VertxProject(io.vertx.starter.model.VertxProject)

Example 2 with VertxProject

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());
        }
    });
}
Also used : Topics(io.vertx.starter.config.Topics) Logger(org.slf4j.Logger) AbstractVerticle(io.vertx.core.AbstractVerticle) Promise(io.vertx.core.Promise) LoggerFactory(org.slf4j.LoggerFactory) Message(io.vertx.core.eventbus.Message) Set(java.util.Set) GeneratorService(io.vertx.starter.service.GeneratorService) Pattern(java.util.regex.Pattern) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) VertxProject(io.vertx.starter.model.VertxProject) Collectors.toSet(java.util.stream.Collectors.toSet) VertxProject(io.vertx.starter.model.VertxProject) GeneratorService(io.vertx.starter.service.GeneratorService)

Example 3 with VertxProject

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();
        });
    });
}
Also used : VertxProject(io.vertx.starter.model.VertxProject)

Example 4 with VertxProject

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);
}
Also used : VertxProject(io.vertx.starter.model.VertxProject) Test(org.junit.jupiter.api.Test)

Example 5 with VertxProject

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));
    }));
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) VertxTestContext(io.vertx.junit5.VertxTestContext) ZIP(io.vertx.starter.model.ArchiveFormat.ZIP) BeforeEach(org.junit.jupiter.api.BeforeEach) Json(io.vertx.core.json.Json) HttpResponse(io.vertx.ext.web.client.HttpResponse) WebClient(io.vertx.ext.web.client.WebClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultiMap(io.vertx.core.MultiMap) Vertx(io.vertx.core.Vertx) Router(io.vertx.ext.web.Router) IOException(java.io.IOException) ProjectConstants(io.vertx.starter.config.ProjectConstants) VertxExtension(io.vertx.junit5.VertxExtension) HttpRequest(io.vertx.ext.web.client.HttpRequest) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) Buffer(io.vertx.core.buffer.Buffer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) HttpServerOptions(io.vertx.core.http.HttpServerOptions) JsonObject(io.vertx.core.json.JsonObject) Handler(io.vertx.core.Handler) Collections(java.util.Collections) VertxProject(io.vertx.starter.model.VertxProject) HttpRequest(io.vertx.ext.web.client.HttpRequest) WebClientOptions(io.vertx.ext.web.client.WebClientOptions) VertxProject(io.vertx.starter.model.VertxProject) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.ext.web.Router) WebClient(io.vertx.ext.web.client.WebClient)

Aggregations

VertxProject (io.vertx.starter.model.VertxProject)11 Buffer (io.vertx.core.buffer.Buffer)5 JsonObject (io.vertx.core.json.JsonObject)5 IOException (java.io.IOException)5 VertxExtension (io.vertx.junit5.VertxExtension)4 VertxTestContext (io.vertx.junit5.VertxTestContext)4 Topics (io.vertx.starter.config.Topics)4 Stream (java.util.stream.Stream)4 Vertx (io.vertx.core.Vertx)3 VertxProjectCodec (io.vertx.starter.VertxProjectCodec)3 GRADLE (io.vertx.starter.model.BuildTool.GRADLE)3 MAVEN (io.vertx.starter.model.BuildTool.MAVEN)3 Language (io.vertx.starter.model.Language)3 KOTLIN (io.vertx.starter.model.Language.KOTLIN)3 Files (java.nio.file.Files)3 Path (java.nio.file.Path)3 java.util (java.util)3 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)3 IOUtils (org.apache.commons.compress.utils.IOUtils)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3