Search in sources :

Example 26 with KogitoBuildContext

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

the class AbstractPersistenceGeneratorTest method initDifferentOptions.

private static Stream<KogitoBuildContext> initDifferentOptions(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext allOptionsContext = contextBuilder.build();
    allOptionsContext.setApplicationProperty(KOGITO_PERSISTENCE_DATA_INDEX_PROTO_GENERATION, "true");
    allOptionsContext.setApplicationProperty(KOGITO_PERSISTENCE_PROTO_MARSHALLER, "true");
    KogitoBuildContext noDataIndexContext = contextBuilder.build();
    noDataIndexContext.setApplicationProperty(KOGITO_PERSISTENCE_DATA_INDEX_PROTO_GENERATION, "false");
    noDataIndexContext.setApplicationProperty(KOGITO_PERSISTENCE_PROTO_MARSHALLER, "true");
    KogitoBuildContext noMarshallerContext = contextBuilder.build();
    noMarshallerContext.setApplicationProperty(KOGITO_PERSISTENCE_DATA_INDEX_PROTO_GENERATION, "true");
    noMarshallerContext.setApplicationProperty(KOGITO_PERSISTENCE_PROTO_MARSHALLER, "false");
    KogitoBuildContext noOptionsContext = contextBuilder.build();
    noOptionsContext.setApplicationProperty(KOGITO_PERSISTENCE_DATA_INDEX_PROTO_GENERATION, "false");
    noOptionsContext.setApplicationProperty(KOGITO_PERSISTENCE_PROTO_MARSHALLER, "false");
    return Stream.of(allOptionsContext, noDataIndexContext, noMarshallerContext, noOptionsContext);
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext)

Example 27 with KogitoBuildContext

use of org.kie.kogito.codegen.api.context.KogitoBuildContext 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()) {
        Optional<GeneratedFile> persistenceFactoryImpl = generatedFiles.stream().filter(gf -> gf.relativePath().equals("org/kie/kogito/persistence/KogitoProcessInstancesFactoryImpl.java")).findFirst();
        if (hasDataIndexProto(context)) {
            List<GeneratedFile> marshallerFiles = generatedFiles.stream().filter(gf -> gf.relativePath().endsWith("MessageMarshaller.java")).collect(Collectors.toList());
            String expectedMarshaller = "PersonMessageMarshaller";
            assertThat(persistenceFactoryImpl).isNotEmpty();
            assertThat(marshallerFiles.size()).isEqualTo(1);
            assertThat(marshallerFiles.get(0).relativePath()).endsWith(expectedMarshaller + ".java");
        }
        final CompilationUnit compilationUnit = parse(new ByteArrayInputStream(persistenceFactoryImpl.get().contents()));
        compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow(() -> new NoSuchElementException("Compilation unit doesn't contain a class or interface declaration!"));
    }
}
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) StaticJavaParser.parse(com.github.javaparser.StaticJavaParser.parse) 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) ByteArrayInputStream(java.io.ByteArrayInputStream) KOGITO_PERSISTENCE_TYPE(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.KOGITO_PERSISTENCE_TYPE) Optional(java.util.Optional) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) CompilationUnit(com.github.javaparser.ast.CompilationUnit) INFINISPAN_PERSISTENCE_TYPE(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.INFINISPAN_PERSISTENCE_TYPE) NoSuchElementException(java.util.NoSuchElementException) Collections(java.util.Collections) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodSource(org.junit.jupiter.params.provider.MethodSource) CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) NoSuchElementException(java.util.NoSuchElementException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 28 with KogitoBuildContext

use of org.kie.kogito.codegen.api.context.KogitoBuildContext 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()) {
        Optional<GeneratedFile> persistenceFactoryImpl = generatedFiles.stream().filter(gf -> gf.relativePath().equals("org/kie/kogito/persistence/KogitoProcessInstancesFactoryImpl.java")).findFirst();
        if (hasProtoMarshaller(context)) {
            List<GeneratedFile> marshallerFiles = generatedFiles.stream().filter(gf -> gf.relativePath().endsWith("MessageMarshaller.java")).collect(Collectors.toList());
            String expectedMarshaller = "PersonMessageMarshaller";
            assertThat(persistenceFactoryImpl).isNotEmpty();
            assertThat(marshallerFiles.size()).isEqualTo(1);
            assertThat(marshallerFiles.get(0).relativePath()).endsWith(expectedMarshaller + ".java");
        }
        final CompilationUnit compilationUnit = parse(new ByteArrayInputStream(persistenceFactoryImpl.get().contents()));
        compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow(() -> new NoSuchElementException("Compilation unit doesn't contain a class or interface declaration!"));
    }
}
Also used : ReflectionProtoGenerator(org.kie.kogito.codegen.process.persistence.proto.ReflectionProtoGenerator) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) Collection(java.util.Collection) StaticJavaParser.parse(com.github.javaparser.StaticJavaParser.parse) 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) ByteArrayInputStream(java.io.ByteArrayInputStream) PersistenceGenerator.hasProtoMarshaller(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.hasProtoMarshaller) KOGITO_PERSISTENCE_TYPE(org.kie.kogito.codegen.process.persistence.PersistenceGenerator.KOGITO_PERSISTENCE_TYPE) Optional(java.util.Optional) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) CompilationUnit(com.github.javaparser.ast.CompilationUnit) NoSuchElementException(java.util.NoSuchElementException) Collections(java.util.Collections) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodSource(org.junit.jupiter.params.provider.MethodSource) CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) NoSuchElementException(java.util.NoSuchElementException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with KogitoBuildContext

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

the class ProcessCodegenTest method isEmpty.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void isEmpty(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.build();
    ProcessCodegen emptyCodeGenerator = ProcessCodegen.ofCollectedResources(context, Collections.emptyList());
    assertThat(emptyCodeGenerator.isEmpty()).isTrue();
    assertThat(emptyCodeGenerator.isEnabled()).isFalse();
    Collection<GeneratedFile> emptyGeneratedFiles = emptyCodeGenerator.generate();
    assertThat(emptyGeneratedFiles.size()).isEqualTo(0);
    ProcessCodegen codeGenerator = ProcessCodegen.ofCollectedResources(context, CollectedResourceProducer.fromFiles(BASE_PATH, MESSAGE_USERTASK_SOURCE_FULL_SOURCE.toFile()));
    assertThat(codeGenerator.isEmpty()).isFalse();
    assertThat(codeGenerator.isEnabled()).isTrue();
    Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
    assertThat(generatedFiles).hasSizeGreaterThanOrEqualTo(10);
}
Also used : KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 30 with KogitoBuildContext

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

the class CodegenUserTaskTest method testRESTApiForMessageStartEvent.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void testRESTApiForMessageStartEvent(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.build();
    ProcessCodegen codeGenerator = ProcessCodegen.ofCollectedResources(context, CollectedResourceProducer.fromFiles(BASE_PATH, MESSAGE_USERTASK_SOURCE_FULL_SOURCE.toFile()));
    Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
    assertThat(generatedFiles).isNotEmpty();
    List<GeneratedFile> resources = generatedFiles.stream().filter(generatedFile -> generatedFile.relativePath().endsWith("org/kie/kogito/test/UserTasksProcessResource.java")).collect(Collectors.toList());
    if (context.hasRESTForGenerator(codeGenerator)) {
        assertThat(resources.size()).isEqualTo(1);
        CompilationUnit parsedResource = StaticJavaParser.parse(new String(resources.get(0).contents()));
        List<MethodDeclaration> completeTaskMethods = parsedResource.findAll(MethodDeclaration.class, md -> md.getNameAsString().startsWith("completeTask"));
        assertThat(completeTaskMethods).hasSize(2);
        completeTaskMethods.forEach(completeTaskMethod -> assertThat(context.getRestAnnotator().getEndpointValue(completeTaskMethod).map(url -> url.contains("/{id}/FirstTask/{taskId}") || url.contains("/{id}/SecondTask/{taskId}")).orElse(true)).isTrue());
    } else {
        assertThat(resources.size()).isZero();
    }
}
Also used : java.util(java.util) ProcessCodegen(org.kie.kogito.codegen.process.ProcessCodegen) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors(java.util.stream.Collectors) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) StaticJavaParser(com.github.javaparser.StaticJavaParser) Paths(java.nio.file.Paths) CollectedResourceProducer(org.kie.kogito.codegen.core.io.CollectedResourceProducer) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Path(java.nio.file.Path) MethodSource(org.junit.jupiter.params.provider.MethodSource) CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ProcessCodegen(org.kie.kogito.codegen.process.ProcessCodegen) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) 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