Search in sources :

Example 11 with GeneratedFile

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

the class AbstractPersistenceGeneratorTest method persistenceGeneratorSanityCheck.

@ParameterizedTest
@MethodSource("persistenceTestContexts")
void persistenceGeneratorSanityCheck(KogitoBuildContext context) {
    context.setApplicationProperty(KOGITO_PERSISTENCE_TYPE, persistenceType());
    ReflectionProtoGenerator protoGenerator = ReflectionProtoGenerator.builder().build(Collections.singleton(GeneratedPOJO.class));
    PersistenceGenerator persistenceGenerator = new PersistenceGenerator(context, protoGenerator, new ReflectionMarshallerGenerator(context, null));
    Collection<GeneratedFile> generatedFiles = persistenceGenerator.generate();
    int expectedDataIndexProto = hasDataIndexProto(context) ? 2 : 0;
    int expectedListDataIndexProto = hasDataIndexProto(context) ? 1 : 0;
    assertThat(generatedFiles.stream().filter(gf -> gf.type().equals(ProtoGenerator.PROTO_TYPE)).count()).isEqualTo(expectedDataIndexProto);
    assertThat(generatedFiles.stream().filter(gf -> gf.type().equals(ProtoGenerator.PROTO_TYPE) && gf.relativePath().endsWith(".json")).count()).isEqualTo(expectedListDataIndexProto);
    int expectedProtoMarshaller = hasProtoMarshaller(context) ? 10 : 0;
    assertThat(generatedFiles.stream().filter(gf -> gf.type().equals(GeneratedFileType.SOURCE) && gf.relativePath().endsWith("Marshaller.java"))).hasSize(expectedProtoMarshaller);
}
Also used : AddonsConfig(org.kie.kogito.codegen.api.AddonsConfig) ReflectionProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ReflectionProtoGenerator) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) KogitoContextTestUtils.contextBuilders(org.kie.kogito.codegen.api.utils.KogitoContextTestUtils.contextBuilders) PersistenceGenerator.hasDataIndexProto(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.hasDataIndexProto) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReflectionMarshallerGenerator(org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator) Arguments(org.junit.jupiter.params.provider.Arguments) GeneratedPOJO(org.kie.kogito.codegen.data.GeneratedPOJO) KOGITO_PERSISTENCE_DATA_INDEX_PROTO_GENERATION(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.KOGITO_PERSISTENCE_DATA_INDEX_PROTO_GENERATION) ProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ProtoGenerator) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) PersistenceGenerator.hasProtoMarshaller(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.hasProtoMarshaller) KOGITO_PERSISTENCE_TYPE(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.KOGITO_PERSISTENCE_TYPE) KOGITO_PERSISTENCE_PROTO_MARSHALLER(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.KOGITO_PERSISTENCE_PROTO_MARSHALLER) Collections(java.util.Collections) GeneratedFile(org.drools.codegen.common.GeneratedFile) GeneratedFileType(org.drools.codegen.common.GeneratedFileType) MethodSource(org.junit.jupiter.params.provider.MethodSource) ReflectionProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ReflectionProtoGenerator) ReflectionMarshallerGenerator(org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator) GeneratedPOJO(org.kie.kogito.codegen.data.GeneratedPOJO) GeneratedFile(org.drools.codegen.common.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with GeneratedFile

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

the class InfinispanPersistenceGeneratorTest method test.

@ParameterizedTest
@MethodSource("persistenceTestContexts")
void test(KogitoBuildContext context) {
    context.setApplicationProperty(KOGITO_PERSISTENCE_TYPE, persistenceType());
    ReflectionProtoGenerator protoGenerator = ReflectionProtoGenerator.builder().build(Collections.singleton(GeneratedPOJO.class));
    PersistenceGenerator persistenceGenerator = new PersistenceGenerator(context, protoGenerator, new ReflectionMarshallerGenerator(context));
    Collection<GeneratedFile> generatedFiles = persistenceGenerator.generate();
    if (context.hasDI()) {
        if (hasDataIndexProto(context)) {
            List<GeneratedFile> marshallerFiles = generatedFiles.stream().filter(gf -> gf.relativePath().endsWith("MessageMarshaller.java")).collect(Collectors.toList());
            String expectedMarshaller = "PersonMessageMarshaller";
            assertThat(marshallerFiles.size()).isEqualTo(1);
            assertThat(marshallerFiles.get(0).relativePath()).endsWith(expectedMarshaller + ".java");
        }
    }
    int marshallerFiles = hasProtoMarshaller(context) ? 14 : 0;
    int dataIndexFiles = hasDataIndexProto(context) ? 2 : 0;
    int expectedNumberOfFiles = marshallerFiles + dataIndexFiles;
    assertThat(generatedFiles).hasSize(expectedNumberOfFiles);
}
Also used : ReflectionProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ReflectionProtoGenerator) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) PersistenceGenerator.hasDataIndexProto(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.hasDataIndexProto) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReflectionMarshallerGenerator(org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator) GeneratedPOJO(org.kie.kogito.codegen.data.GeneratedPOJO) Collectors(java.util.stream.Collectors) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) PersistenceGenerator.hasProtoMarshaller(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.hasProtoMarshaller) KOGITO_PERSISTENCE_TYPE(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.KOGITO_PERSISTENCE_TYPE) INFINISPAN_PERSISTENCE_TYPE(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.INFINISPAN_PERSISTENCE_TYPE) Collections(java.util.Collections) GeneratedFile(org.drools.codegen.common.GeneratedFile) MethodSource(org.junit.jupiter.params.provider.MethodSource) ReflectionProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ReflectionProtoGenerator) ReflectionMarshallerGenerator(org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator) GeneratedPOJO(org.kie.kogito.codegen.data.GeneratedPOJO) GeneratedFile(org.drools.codegen.common.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with GeneratedFile

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

the class KafkaPersistenceGeneratorTest method test.

@ParameterizedTest
@MethodSource("persistenceTestContexts")
void test(KogitoBuildContext context) {
    context.setApplicationProperty(KOGITO_PERSISTENCE_TYPE, persistenceType());
    ReflectionProtoGenerator protoGenerator = ReflectionProtoGenerator.builder().build(Collections.singleton(GeneratedPOJO.class));
    PersistenceGenerator persistenceGenerator = new PersistenceGenerator(context, protoGenerator, new ReflectionMarshallerGenerator(context));
    Collection<GeneratedFile> generatedFiles = persistenceGenerator.generate();
    if (context.hasDI()) {
        if (hasProtoMarshaller(context)) {
            List<GeneratedFile> marshallerFiles = generatedFiles.stream().filter(gf -> gf.relativePath().endsWith("MessageMarshaller.java")).collect(Collectors.toList());
            String expectedMarshaller = "PersonMessageMarshaller";
            assertThat(marshallerFiles.size()).isEqualTo(1);
            assertThat(marshallerFiles.get(0).relativePath()).endsWith(expectedMarshaller + ".java");
        }
    }
    int marshallerFiles = hasProtoMarshaller(context) ? 14 : 0;
    int dataIndexFiles = hasDataIndexProto(context) ? 2 : 0;
    int expectedNumberOfFiles = marshallerFiles + dataIndexFiles;
    assertThat(generatedFiles).hasSize(expectedNumberOfFiles);
}
Also used : ReflectionProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ReflectionProtoGenerator) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) PersistenceGenerator.hasDataIndexProto(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.hasDataIndexProto) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReflectionMarshallerGenerator(org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator) GeneratedPOJO(org.kie.kogito.codegen.data.GeneratedPOJO) KAFKA_PERSISTENCE_TYPE(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.KAFKA_PERSISTENCE_TYPE) Collectors(java.util.stream.Collectors) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) PersistenceGenerator.hasProtoMarshaller(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.hasProtoMarshaller) KOGITO_PERSISTENCE_TYPE(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.KOGITO_PERSISTENCE_TYPE) Collections(java.util.Collections) GeneratedFile(org.drools.codegen.common.GeneratedFile) MethodSource(org.junit.jupiter.params.provider.MethodSource) ReflectionProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ReflectionProtoGenerator) ReflectionMarshallerGenerator(org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator) GeneratedPOJO(org.kie.kogito.codegen.data.GeneratedPOJO) GeneratedFile(org.drools.codegen.common.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with GeneratedFile

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

the class MongoDBPersistenceGeneratorTest method test.

@ParameterizedTest
@MethodSource("persistenceTestContexts")
void test(KogitoBuildContext context) {
    context.setApplicationProperty(KOGITO_PERSISTENCE_TYPE, persistenceType());
    ReflectionProtoGenerator protoGenerator = ReflectionProtoGenerator.builder().build(Collections.singleton(GeneratedPOJO.class));
    PersistenceGenerator persistenceGenerator = new PersistenceGenerator(context, protoGenerator, new ReflectionMarshallerGenerator(context));
    Collection<GeneratedFile> generatedFiles = persistenceGenerator.generate();
    int marshallerFiles = hasProtoMarshaller(context) ? 14 : 0;
    int dataIndexFiles = hasDataIndexProto(context) ? 2 : 0;
    int expectedNumberOfFiles = marshallerFiles + dataIndexFiles;
    assertThat(generatedFiles).hasSize(expectedNumberOfFiles);
}
Also used : ReflectionProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ReflectionProtoGenerator) ReflectionMarshallerGenerator(org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator) GeneratedPOJO(org.kie.kogito.codegen.data.GeneratedPOJO) GeneratedFile(org.drools.codegen.common.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with GeneratedFile

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

the class RuleCodegenTest method elapsedTimeMonitoringIsWrappingEveryMethod.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void elapsedTimeMonitoringIsWrappingEveryMethod(KogitoBuildContext.Builder contextBuilder) {
    contextBuilder.withAddonsConfig(AddonsConfig.builder().withPrometheusMonitoring(true).withMonitoring(true).build()).build();
    RuleCodegen incrementalRuleCodegen = getIncrementalRuleCodegenFromFiles(contextBuilder, new File(RESOURCE_PATH + "/org/kie/kogito/codegen/unit/RuleUnitQuery.drl"));
    Collection<GeneratedFile> generatedFiles = incrementalRuleCodegen.withHotReloadMode().generate();
    List<String> endpointClasses = generatedFiles.stream().filter(x -> x.relativePath().contains("Endpoint")).map(x -> new String(x.contents())).collect(Collectors.toList());
    for (String endpointClass : endpointClasses) {
        assertMonitoringEndpoints(endpointClass);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DecisionTableProvider(org.drools.drl.extensions.DecisionTableProvider) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DISABLED_DOMAIN_DASHBOARDS(org.kie.kogito.grafana.utils.GrafanaDashboardUtils.DISABLED_DOMAIN_DASHBOARDS) DecisionTableFactory(org.drools.drl.extensions.DecisionTableFactory) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Path(java.nio.file.Path) MethodSource(org.junit.jupiter.params.provider.MethodSource) AddonsConfig(org.kie.kogito.codegen.api.AddonsConfig) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) KieService(org.kie.api.internal.utils.KieService) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) File(java.io.File) KogitoContextTestUtils.withLegacyApi(org.kie.kogito.codegen.api.utils.KogitoContextTestUtils.withLegacyApi) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) StaticJavaParser(com.github.javaparser.StaticJavaParser) DISABLED_OPERATIONAL_DASHBOARDS(org.kie.kogito.grafana.utils.GrafanaDashboardUtils.DISABLED_OPERATIONAL_DASHBOARDS) Paths(java.nio.file.Paths) DashboardGeneratedFileUtils(org.kie.kogito.codegen.core.DashboardGeneratedFileUtils) CollectedResourceProducer(org.kie.kogito.codegen.core.io.CollectedResourceProducer) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) GeneratedFile(org.drools.codegen.common.GeneratedFile) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) 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)

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