use of org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator in project kogito-runtimes by kiegroup.
the class FileSystemPersistenceGeneratorTest 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 factoryFiles = context.hasRESTForGenerator(persistenceGenerator) ? 1 : 0;
int marshallerFiles = hasProtoMarshaller(context) ? 14 : 0;
int dataIndexFiles = hasDataIndexProto(context) ? 2 : 0;
int expectedNumberOfFiles = factoryFiles + marshallerFiles + dataIndexFiles;
assertThat(generatedFiles).hasSize(expectedNumberOfFiles);
if (context.hasDI()) {
Optional<GeneratedFile> persistenceFactoryImpl = generatedFiles.stream().filter(gf -> gf.relativePath().equals("org/kie/kogito/persistence/KogitoProcessInstancesFactoryImpl.java")).findFirst();
assertThat(persistenceFactoryImpl).isNotEmpty();
final CompilationUnit compilationUnit = parse(new ByteArrayInputStream(persistenceFactoryImpl.get().contents()));
final ClassOrInterfaceDeclaration classDeclaration = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow(() -> new NoSuchElementException("Compilation unit doesn't contain a class or interface declaration!"));
final Optional<MethodDeclaration> methodDeclaration = classDeclaration.findFirst(MethodDeclaration.class, d -> d.getName().getIdentifier().equals(PATH_NAME));
assertThat(methodDeclaration).isNotEmpty();
final Optional<FieldDeclaration> fieldDeclaration = classDeclaration.findFirst(FieldDeclaration.class);
assertThat(fieldDeclaration).isNotEmpty();
assertThat(fieldDeclaration.get().getVariables()).hasSize(1);
assertThat(fieldDeclaration.get().getVariables().get(0).getName().asString()).isEqualTo(PATH_NAME);
}
}
use of org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator in project kogito-runtimes by kiegroup.
the class JDBCPersistenceGeneratorTest 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));
assertEquals(persistenceType(), persistenceGenerator.persistenceType());
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()));
assertThat(compilationUnit.findFirst(ClassOrInterfaceDeclaration.class)).isNotEmpty();
}
}
use of org.kie.kogito.codegen.process.persistence.marshaller.ReflectionMarshallerGenerator in project kogito-runtimes by kiegroup.
the class PostgrePersistenceGeneratorTest method testGeneratedFiles.
@ParameterizedTest
@MethodSource("persistenceTestContexts")
void testGeneratedFiles(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 factoryFiles = context instanceof SpringBootKogitoBuildContext ? 2 : 1;
int marshallerFiles = hasProtoMarshaller(context) ? 14 : 0;
int dataIndexFiles = hasDataIndexProto(context) ? 2 : 0;
int expectedNumberOfFiles = factoryFiles + marshallerFiles + dataIndexFiles;
assertThat(generatedFiles).hasSize(expectedNumberOfFiles);
Optional<GeneratedFile> persistenceFactoryImpl = generatedFiles.stream().filter(gf -> gf.relativePath().equals("org/kie/kogito/persistence/KogitoProcessInstancesFactoryImpl.java")).findFirst();
assertThat(persistenceFactoryImpl).isPresent();
validateClassInCompilationUnit(persistenceFactoryImpl.get().contents());
Optional<GeneratedFile> pgClientProducer = generatedFiles.stream().filter(gf -> gf.relativePath().equals("org/kie/kogito/persistence/PgClientProducer.java")).findFirst();
if (context instanceof SpringBootKogitoBuildContext) {
assertThat(pgClientProducer).isPresent();
validateClassInCompilationUnit(pgClientProducer.get().contents());
} else {
assertThat(pgClientProducer).isEmpty();
}
}
Aggregations