Search in sources :

Example 6 with VertxProject

use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.

the class AnalyticsTest method projectPersisted.

@Test
void projectPersisted(Vertx vertx, VertxTestContext testContext) {
    Instant createdOn = Instant.now().truncatedTo(MINUTES);
    VertxProject vertxProject = new VertxProject().setId("should-not-persist").setGroupId("should-not-persist").setArtifactId("should-not-persist").setPackageName("should-not-persist").setCreatedOn(createdOn).setOperatingSystem("Other");
    vertx.eventBus().publish(Topics.PROJECT_CREATED, vertxProject);
    Checkpoint checkpoint = testContext.laxCheckpoint();
    vertx.setPeriodic(20, id -> {
        JsonObject query = new JsonObject();
        client.find(AnalyticsService.COLLECTION_NAME, query, testContext.succeeding(list -> {
            testContext.verify(() -> {
                assertTrue(list.size() <= 1);
                if (list.size() == 1) {
                    JsonObject document = list.get(0);
                    assertFalse(Stream.of("id", "groupId", "artifactId", "packageName").anyMatch(document::containsKey));
                    assertEquals(createdOn, document.getJsonObject("createdOn").getInstant("$date"));
                    assertEquals(vertxProject.getOperatingSystem(), document.getString("operatingSystem"));
                    checkpoint.flag();
                    assertTrue(vertx.cancelTimer(id));
                }
            });
        }));
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) AnalyticsVerticle(io.vertx.starter.AnalyticsVerticle) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) Vertx(io.vertx.core.Vertx) MongoClient(io.vertx.ext.mongo.MongoClient) IOException(java.io.IOException) VertxExtension(io.vertx.junit5.VertxExtension) Instant(java.time.Instant) VertxProjectCodec(io.vertx.starter.VertxProjectCodec) MongoDBContainer(org.testcontainers.containers.MongoDBContainer) Test(org.junit.jupiter.api.Test) Topics(io.vertx.starter.config.Topics) AfterEach(org.junit.jupiter.api.AfterEach) Stream(java.util.stream.Stream) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DeploymentOptions(io.vertx.core.DeploymentOptions) MINUTES(java.time.temporal.ChronoUnit.MINUTES) Assertions(org.junit.jupiter.api.Assertions) JsonObject(io.vertx.core.json.JsonObject) Checkpoint(io.vertx.junit5.Checkpoint) VertxProject(io.vertx.starter.model.VertxProject) Container(org.testcontainers.junit.jupiter.Container) Checkpoint(io.vertx.junit5.Checkpoint) VertxProject(io.vertx.starter.model.VertxProject) Instant(java.time.Instant) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 7 with VertxProject

use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.

the class GeneratorTest method testProject.

private void testProject(VertxProject project, Vertx vertx, VertxTestContext testContext) {
    vertx.eventBus().<Buffer>request(Topics.PROJECT_REQUESTED, project, testContext.succeeding(msg -> {
        unpack(vertx, testContext, workdir, msg.body(), testContext.succeeding(unpacked -> {
            testContext.verify(() -> {
                verifyBaseFiles();
                BuildTool buildTool = project.getBuildTool();
                Language language = project.getLanguage();
                if (buildTool == MAVEN) {
                    verifyMavenFiles();
                } else if (buildTool == GRADLE) {
                    verifyGradleFiles(language);
                } else {
                    testContext.failNow(new NoStackTraceThrowable(unsupported(buildTool)));
                    return;
                }
                try {
                    verifySourceFiles(language);
                } catch (IOException e) {
                    throw new AssertionError(e);
                }
                if (Utils.isWindows()) {
                    testContext.completeNow();
                } else {
                    buildProject(vertx, buildTool, testContext.succeeding(projectBuilt -> {
                        testContext.verify(() -> {
                            if (buildTool == MAVEN) {
                                try {
                                    verifyMavenOutputFiles();
                                } catch (IOException e) {
                                    throw new AssertionError(e);
                                }
                            } else if (buildTool == GRADLE) {
                                try {
                                    verifyGradleOutputFiles();
                                } catch (IOException e) {
                                    throw new AssertionError(e);
                                }
                            } else {
                                testContext.failNow(new NoStackTraceThrowable(unsupported(buildTool)));
                            }
                            runDevMode(vertx, buildTool, testContext.succeeding(devModeRan -> testContext.completeNow()));
                        });
                    }));
                }
            });
        }));
    }));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) VertxTestContext(io.vertx.junit5.VertxTestContext) java.util(java.util) io.vertx.core(io.vertx.core) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Process(com.julienviet.childprocess.Process) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JdkVersion(io.vertx.starter.model.JdkVersion) KOTLIN(io.vertx.starter.model.Language.KOTLIN) GeneratorVerticle(io.vertx.starter.GeneratorVerticle) VertxProjectCodec(io.vertx.starter.VertxProjectCodec) Utils(io.vertx.core.impl.Utils) Timeout(io.vertx.junit5.Timeout) MAVEN(io.vertx.starter.model.BuildTool.MAVEN) JAVA(io.vertx.starter.model.Language.JAVA) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) GRADLE(io.vertx.starter.model.BuildTool.GRADLE) RecordParser(io.vertx.core.parsetools.RecordParser) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) BuildTool(io.vertx.starter.model.BuildTool) Path(java.nio.file.Path) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) MethodSource(org.junit.jupiter.params.provider.MethodSource) OutputStream(java.io.OutputStream) AssumptionViolatedException(org.junit.AssumptionViolatedException) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Files(java.nio.file.Files) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable) TGZ(io.vertx.starter.model.ArchiveFormat.TGZ) IOUtils(org.apache.commons.compress.utils.IOUtils) IOException(java.io.IOException) VertxExtension(io.vertx.junit5.VertxExtension) Util(io.vertx.starter.Util) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Topics(io.vertx.starter.config.Topics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) Language(io.vertx.starter.model.Language) org.junit.jupiter.api(org.junit.jupiter.api) ProcessOptions(com.julienviet.childprocess.ProcessOptions) VertxProject(io.vertx.starter.model.VertxProject) Language(io.vertx.starter.model.Language) BuildTool(io.vertx.starter.model.BuildTool) IOException(java.io.IOException) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 8 with VertxProject

use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.

the class AnalyticsService method onProjectCreated.

public void onProjectCreated(Message<VertxProject> message) {
    log.debug("Building analytics with on new project created");
    VertxProject project = message.body();
    JsonObject document = toDocument(project);
    mongoClient.save(COLLECTION_NAME, document, res -> {
        if (res.failed()) {
            log.error("Failed to save document", res.cause());
        }
    });
}
Also used : VertxProject(io.vertx.starter.model.VertxProject) JsonObject(io.vertx.core.json.JsonObject)

Example 9 with VertxProject

use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.

the class GeneratorService method onProjectRequested.

public Buffer onProjectRequested(VertxProject project) throws Exception {
    ArchiveOutputStreamFactory factory;
    ArchiveFormat archiveFormat = project.getArchiveFormat();
    if (archiveFormat == ArchiveFormat.TGZ) {
        factory = baos -> new TarArchiveOutputStream(new GzipCompressorOutputStream(baos));
    } else if (archiveFormat == ArchiveFormat.ZIP) {
        factory = baos -> new ZipArchiveOutputStream(baos);
    } else {
        throw new IllegalArgumentException("Unsupported archive format: " + archiveFormat.getFileExtension());
    }
    try (TempDir tempDir = TempDir.create();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ArchiveOutputStream out = factory.create(baos)) {
        createProject(project, tempDir);
        generateArchive(tempDir, out);
        out.finish();
        out.close();
        return Buffer.buffer(baos.toByteArray());
    }
}
Also used : ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) java.util(java.util) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) LoggerFactory(org.slf4j.LoggerFactory) ArchiveFormat(io.vertx.starter.model.ArchiveFormat) KOTLIN(io.vertx.starter.model.Language.KOTLIN) CompletableFuture(java.util.concurrent.CompletableFuture) MAVEN(io.vertx.starter.model.BuildTool.MAVEN) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) GRADLE(io.vertx.starter.model.BuildTool.GRADLE) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Vertx(io.vertx.core.Vertx) IOUtils(org.apache.commons.compress.utils.IOUtils) IOException(java.io.IOException) Collectors.joining(java.util.stream.Collectors.joining) ExecutionException(java.util.concurrent.ExecutionException) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) FreeMarkerTemplateEngine(io.vertx.ext.web.templ.freemarker.FreeMarkerTemplateEngine) Language(io.vertx.starter.model.Language) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) Pattern(java.util.regex.Pattern) VertxProject(io.vertx.starter.model.VertxProject) InputStream(java.io.InputStream) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) ArchiveFormat(io.vertx.starter.model.ArchiveFormat) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream)

Example 10 with VertxProject

use of io.vertx.starter.model.VertxProject in project vertx-starter by vert-x3.

the class GeneratorVerticle method onProjectRequested.

private void onProjectRequested(Message<VertxProject> msg) {
    VertxProject project = msg.body();
    vertx.executeBlocking(fut -> {
        try {
            fut.complete(generatorService.onProjectRequested(project));
        } catch (Exception e) {
            fut.fail(e);
        }
    }, false, ar -> {
        if (ar.succeeded()) {
            msg.reply(ar.result());
        } else {
            log.error("Failed to generate project " + project.getId(), ar.cause());
            msg.fail(-1, ar.cause().getMessage());
        }
    });
}
Also used : VertxProject(io.vertx.starter.model.VertxProject)

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