Search in sources :

Example 16 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class RuleCodegenTest method generateGrafanaDashboards.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void generateGrafanaDashboards(KogitoBuildContext.Builder contextBuilder) {
    contextBuilder.withAddonsConfig(AddonsConfig.builder().withPrometheusMonitoring(true).withMonitoring(true).build());
    RuleCodegen incrementalRuleCodegen = getIncrementalRuleCodegenFromFiles(contextBuilder, new File(RESOURCE_PATH + "/org/kie/kogito/codegen/unit/RuleUnitQuery.drl"));
    // The domain dashboard to monitor the RuleUnit is always generated.
    int expectedDashboards = contextBuilder.build().hasRESTForGenerator(incrementalRuleCodegen) ? 3 : 1;
    Collection<GeneratedFile> generatedFiles = incrementalRuleCodegen.withHotReloadMode().generate();
    assertThat(generatedFiles.stream().filter(x -> x.type().equals(DashboardGeneratedFileUtils.DASHBOARD_TYPE))).hasSize(expectedDashboards);
}
Also used : File(java.io.File) GeneratedFile(org.drools.codegen.common.GeneratedFile) GeneratedFile(org.drools.codegen.common.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class RuleCodegenTest method generateGrafanaDashboardsExcluded.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void generateGrafanaDashboardsExcluded(KogitoBuildContext.Builder contextBuilder) {
    contextBuilder.withAddonsConfig(AddonsConfig.builder().withPrometheusMonitoring(true).withMonitoring(true).build());
    KogitoBuildContext context = contextBuilder.build();
    context.setApplicationProperty(DISABLED_OPERATIONAL_DASHBOARDS, "find-adults,find-adults-age");
    context.setApplicationProperty(DISABLED_DOMAIN_DASHBOARDS, "AdultUnit");
    RuleCodegen incrementalRuleCodegen = getIncrementalRuleCodegenFromFiles(context, new File(RESOURCE_PATH + "/org/kie/kogito/codegen/unit/RuleUnitQuery.drl"));
    Collection<GeneratedFile> generatedFiles = incrementalRuleCodegen.withHotReloadMode().generate();
    assertThat(generatedFiles.stream().filter(x -> x.type().equals(DashboardGeneratedFileUtils.DASHBOARD_TYPE))).isEmpty();
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) File(java.io.File) GeneratedFile(org.drools.codegen.common.GeneratedFile) GeneratedFile(org.drools.codegen.common.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class AbstractProtoGeneratorTest method checkGeneratedProtoBufAndListing.

@Test
void checkGeneratedProtoBufAndListing() throws IOException {
    AbstractProtoGenerator<T> generator = protoGeneratorBuilder().build(null);
    List<GeneratedFile> generatedFiles = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        final Proto proto = new Proto("org.acme.test");
        generatedFiles.add(generator.generateProtoFiles("protofile." + i, proto));
    }
    generator.generateProtoListingFile(generatedFiles).ifPresent(generatedFiles::add);
    GeneratedFile listFile = generatedFiles.stream().filter(x -> x.relativePath().endsWith("list.json")).findFirst().get();
    byte[] list = listFile.contents();
    final ObjectMapper mapper = new ObjectMapper();
    List<String> files = mapper.readValue(list, List.class);
    assertThat(files).isNotEmpty();
    assertThat(files).hasAtLeastOneElementOfType(String.class).contains("protofile.0.proto").hasSize(5);
}
Also used : ArrayList(java.util.ArrayList) GeneratedFile(org.drools.codegen.common.GeneratedFile) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 19 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class DroolsModelBuilder method generateInternalResource.

private List<GeneratedFile> generateInternalResource(KogitoPackageSources pkgSources) {
    List<GeneratedFile> modelFiles = new ArrayList<>();
    org.drools.modelcompiler.builder.GeneratedFile reflectConfigSource = pkgSources.getReflectConfigSource();
    if (reflectConfigSource != null) {
        modelFiles.add(new GeneratedFile(GeneratedFileType.INTERNAL_RESOURCE, reflectConfigSource.getPath(), reflectConfigSource.getData()));
    }
    return modelFiles;
}
Also used : ArrayList(java.util.ArrayList) GeneratedFile(org.drools.codegen.common.GeneratedFile)

Example 20 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class SampleCodegenTest method generate.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
void generate(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.build();
    Collection<CollectedResource> resources = Arrays.asList(CollectedResourcesTestUtils.toCollectedResource("/sampleFile1.txt"), CollectedResourcesTestUtils.toCollectedResource("/sampleFile2.txt"));
    SampleCodegen codeGenerator = SampleCodegen.ofCollectedResources(context, resources);
    Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
    if (contextBuilder.build().hasRESTForGenerator(codeGenerator)) {
        assertThat(generatedFiles).hasSize(1);
        List<GeneratedFile> generatedRests = generatedFiles.stream().filter(gf -> gf.type() == REST_TYPE).collect(Collectors.toList());
        assertThat(generatedRests).hasSize(1);
        CompilationUnit compilationUnit = StaticJavaParser.parse(new String(generatedRests.get(0).contents()));
        Optional<FieldDeclaration> optionalFieldDeclaration = compilationUnit.findFirst(FieldDeclaration.class, SampleCodegen::isSampleRuntimeField);
        assertThat(optionalFieldDeclaration).isNotEmpty();
        FieldDeclaration fieldDeclaration = optionalFieldDeclaration.get();
        if (context.hasDI()) {
            assertThat(fieldDeclaration.getAnnotations()).isNotEmpty();
        } else {
            assertThat(fieldDeclaration.getVariable(0).getInitializer()).isNotEmpty();
        }
    } else {
        assertThat(generatedFiles).isEmpty();
    }
}
Also used : Arrays(java.util.Arrays) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) JavaKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) StaticJavaParser(com.github.javaparser.StaticJavaParser) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) REST_TYPE(org.kie.kogito.codegen.api.Generator.REST_TYPE) CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) Optional(java.util.Optional) CollectedResourcesTestUtils(org.kie.kogito.codegen.api.utils.CollectedResourcesTestUtils) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Collections(java.util.Collections) GeneratedFile(org.drools.codegen.common.GeneratedFile) MethodSource(org.junit.jupiter.params.provider.MethodSource) CompilationUnit(com.github.javaparser.ast.CompilationUnit) CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) JavaKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext) GeneratedFile(org.drools.codegen.common.GeneratedFile) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

GeneratedFile (org.drools.codegen.common.GeneratedFile)79 KogitoBuildContext (org.kie.kogito.codegen.api.context.KogitoBuildContext)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 MethodSource (org.junit.jupiter.params.provider.MethodSource)36 CompilationUnit (com.github.javaparser.ast.CompilationUnit)21 Collection (java.util.Collection)20 ArrayList (java.util.ArrayList)19 List (java.util.List)19 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)15 Collectors (java.util.stream.Collectors)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)15 File (java.io.File)13 Test (org.junit.jupiter.api.Test)12 Paths (java.nio.file.Paths)11 Collections (java.util.Collections)10 GeneratedFileType (org.drools.codegen.common.GeneratedFileType)10 CollectedResourceProducer (org.kie.kogito.codegen.core.io.CollectedResourceProducer)10 Path (java.nio.file.Path)9 Optional (java.util.Optional)9 CollectedResource (org.kie.kogito.codegen.api.io.CollectedResource)8