Search in sources :

Example 1 with KogitoBuildContext

use of org.kie.kogito.codegen.api.context.KogitoBuildContext in project kogito-runtimes by kiegroup.

the class DecisionCloudEventMetaFactoryGeneratorTest method buildCodegen.

private static DecisionCodegen buildCodegen(boolean withCloudEvents) {
    KogitoBuildContext context = QuarkusKogitoBuildContext.builder().withAddonsConfig(AddonsConfig.builder().withCloudEvents(withCloudEvents).build()).build();
    Collection<CollectedResource> collectedResources = CollectedResourceProducer.fromPaths(Paths.get(MODEL_PATH).toAbsolutePath());
    return DecisionCodegen.ofCollectedResources(context, collectedResources);
}
Also used : CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) QuarkusKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext)

Example 2 with KogitoBuildContext

use of org.kie.kogito.codegen.api.context.KogitoBuildContext in project kogito-runtimes by kiegroup.

the class ApplicationGeneratorTest method compilationUnit.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void compilationUnit(KogitoBuildContext.Builder contextBuilder) {
    final KogitoBuildContext context = contextBuilder.build();
    final ApplicationContainerGenerator appGenerator = new ApplicationContainerGenerator(context);
    assertCompilationUnit(appGenerator.getCompilationUnitOrThrow(), context.hasDI());
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with KogitoBuildContext

use of org.kie.kogito.codegen.api.context.KogitoBuildContext in project kogito-runtimes by kiegroup.

the class ApplicationGeneratorTest method disableRestGenerationOfSpecificGenerator.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void disableRestGenerationOfSpecificGenerator(KogitoBuildContext.Builder contextBuilder) {
    final KogitoBuildContext context = contextBuilder.build();
    final ApplicationGenerator appGenerator = new ApplicationGenerator(context);
    final MockGenerator restGenerator = new MockGenerator(context, true);
    assertThat(appGenerator.registerGeneratorIfEnabled(restGenerator)).isNotEmpty();
    assertThat(appGenerator.getGenerators()).hasSize(1);
    if (context.hasRESTForGenerator(restGenerator)) {
        // disable REST
        context.setApplicationProperty(KogitoBuildContext.generateRESTConfigurationKeyForResource(restGenerator.name()), "false");
        assertThat(appGenerator.generateComponents()).isEmpty();
        // enable REST
        context.setApplicationProperty(KogitoBuildContext.generateRESTConfigurationKeyForResource(restGenerator.name()), "true");
        assertThat(appGenerator.generateComponents()).isNotEmpty().hasSize(1).matches(files -> files.stream().anyMatch(gf -> REST_TYPE.equals(gf.type())));
    } else {
        assertThat(appGenerator.generateComponents()).isEmpty();
    }
}
Also used : NodeList(com.github.javaparser.ast.NodeList) Arrays(java.util.Arrays) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) TypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ApplicationSection(org.kie.kogito.codegen.api.ApplicationSection) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) REST_TYPE(org.kie.kogito.codegen.api.Generator.REST_TYPE) Optional(java.util.Optional) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) Expression(com.github.javaparser.ast.expr.Expression) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Collections(java.util.Collections) MethodSource(org.junit.jupiter.params.provider.MethodSource) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with KogitoBuildContext

use of org.kie.kogito.codegen.api.context.KogitoBuildContext in project kogito-runtimes by kiegroup.

the class ApplicationGeneratorTest method disableGlobalRestGeneration.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void disableGlobalRestGeneration(KogitoBuildContext.Builder contextBuilder) {
    final KogitoBuildContext context = contextBuilder.build();
    final ApplicationGenerator appGenerator = new ApplicationGenerator(context);
    final MockGenerator restGenerator = new MockGenerator(context, true);
    assertThat(appGenerator.registerGeneratorIfEnabled(restGenerator)).isNotEmpty();
    assertThat(appGenerator.getGenerators()).hasSize(1);
    if (context.hasRESTForGenerator(restGenerator)) {
        // globally disable REST
        context.setApplicationProperty(KogitoBuildContext.KOGITO_GENERATE_REST, "false");
        assertThat(appGenerator.generateComponents()).isEmpty();
        // globally enable REST
        context.setApplicationProperty(KogitoBuildContext.KOGITO_GENERATE_REST, "true");
        assertThat(appGenerator.generateComponents()).isNotEmpty().hasSize(1).matches(files -> files.stream().anyMatch(gf -> REST_TYPE.equals(gf.type())));
    } else {
        assertThat(appGenerator.generateComponents()).isEmpty();
    }
}
Also used : NodeList(com.github.javaparser.ast.NodeList) Arrays(java.util.Arrays) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) TypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ApplicationSection(org.kie.kogito.codegen.api.ApplicationSection) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) REST_TYPE(org.kie.kogito.codegen.api.Generator.REST_TYPE) Optional(java.util.Optional) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) Expression(com.github.javaparser.ast.expr.Expression) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Collections(java.util.Collections) MethodSource(org.junit.jupiter.params.provider.MethodSource) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with KogitoBuildContext

use of org.kie.kogito.codegen.api.context.KogitoBuildContext in project kogito-runtimes by kiegroup.

the class ApplicationGeneratorTest method compilationUnitWithCDI.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void compilationUnitWithCDI(KogitoBuildContext.Builder contextBuilder) {
    final KogitoBuildContext context = contextBuilder.build();
    final ApplicationContainerGenerator appGenerator = new ApplicationContainerGenerator(context);
    assertCompilationUnit(appGenerator.getCompilationUnitOrThrow(), context.hasDI());
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

KogitoBuildContext (org.kie.kogito.codegen.api.context.KogitoBuildContext)83 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)53 MethodSource (org.junit.jupiter.params.provider.MethodSource)51 GeneratedFile (org.kie.kogito.codegen.api.GeneratedFile)41 Collection (java.util.Collection)20 Test (org.junit.jupiter.api.Test)19 List (java.util.List)17 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)17 QuarkusKogitoBuildContext (org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext)17 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)16 CompilationUnit (com.github.javaparser.ast.CompilationUnit)15 Collectors (java.util.stream.Collectors)14 Collections (java.util.Collections)11 Optional (java.util.Optional)11 Paths (java.nio.file.Paths)10 Path (java.nio.file.Path)9 GeneratedFileType (org.kie.kogito.codegen.api.GeneratedFileType)9 SpringBootKogitoBuildContext (org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext)9 CollectedResource (org.kie.kogito.codegen.api.io.CollectedResource)9 ReflectionMarshallerGenerator (org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator)8