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);
}
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!"));
}
}
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!"));
}
}
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);
}
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();
}
}
Aggregations