use of org.kie.kogito.codegen.process.persistence.proto.ProtoGenerator 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);
}
use of org.kie.kogito.codegen.process.persistence.proto.ProtoGenerator in project kogito-runtimes by kiegroup.
the class AbstractMarshallerGeneratorTest method testEnumMarshallers.
@Test
void testEnumMarshallers() {
Stream.of(Answer.class, AnswerWithAnnotations.class).forEach(e -> {
ProtoGenerator generator = protoGeneratorBuilder().withDataClasses(convertTypes(e)).build(null);
Proto proto = generator.protoOfDataClasses("org.kie.kogito.test");
assertThat(proto).isNotNull();
assertThat(proto.getEnums()).hasSize(1);
MarshallerGenerator marshallerGenerator = withGenerator(e);
List<CompilationUnit> classes = null;
try {
classes = marshallerGenerator.generate(proto.serialize());
} catch (IOException ex) {
fail("Error generating marshaller for " + e.getName(), e);
}
assertThat(classes).isNotNull();
assertThat(classes).hasSize(1);
Optional<ClassOrInterfaceDeclaration> marshallerClass = classes.get(0).getClassByName(e.getSimpleName() + "EnumMarshaller");
assertThat(marshallerClass).isPresent();
});
}
use of org.kie.kogito.codegen.process.persistence.proto.ProtoGenerator in project kogito-runtimes by kiegroup.
the class AbstractMarshallerGeneratorTest method testEnumInPojosMarshallers.
@Test
void testEnumInPojosMarshallers() {
Stream.of(Question.class, QuestionWithAnnotatedEnum.class).forEach(c -> {
ProtoGenerator generator = protoGeneratorBuilder().withDataClasses(convertTypes(c)).build(null);
Proto proto = generator.protoOfDataClasses("org.kie.kogito.test");
assertThat(proto).isNotNull();
assertThat(proto.getMessages()).hasSize(1);
MarshallerGenerator marshallerGenerator = withGenerator(c);
List<CompilationUnit> classes = null;
try {
classes = marshallerGenerator.generate(proto.serialize());
} catch (IOException e) {
fail("Error generating marshaller for " + c.getName(), e);
}
assertThat(classes).isNotNull();
assertThat(classes).hasSize(2);
Optional<ClassOrInterfaceDeclaration> marshallerClass = classes.get(0).getClassByName(c.getSimpleName() + "MessageMarshaller");
assertThat(marshallerClass).isPresent();
String answerType = null;
try {
answerType = c.getDeclaredField("answer").getType().getSimpleName();
} catch (NoSuchFieldException e) {
fail("Unable to get answer field type for " + c.getName(), e);
}
marshallerClass = classes.get(1).getClassByName(answerType + "EnumMarshaller");
assertThat(marshallerClass).isPresent();
});
}
use of org.kie.kogito.codegen.process.persistence.proto.ProtoGenerator in project kogito-runtimes by kiegroup.
the class AbstractMarshallerGeneratorTest method testPersonWithListMarshallers.
@Test
void testPersonWithListMarshallers() throws Exception {
ProtoGenerator generator = protoGeneratorBuilder().withDataClasses(convertTypes(PersonWithList.class)).build(null);
Proto proto = generator.protoOfDataClasses("org.kie.kogito.test");
assertThat(proto).isNotNull();
assertThat(proto.getMessages()).hasSize(1);
MarshallerGenerator marshallerGenerator = withGenerator(PersonWithList.class);
List<CompilationUnit> classes = marshallerGenerator.generate(proto.serialize());
assertThat(classes).isNotNull();
assertThat(classes).hasSize(1);
Optional<ClassOrInterfaceDeclaration> marshallerClass = classes.get(0).getClassByName("PersonWithListMessageMarshaller");
assertThat(marshallerClass).isPresent();
}
use of org.kie.kogito.codegen.process.persistence.proto.ProtoGenerator in project kogito-runtimes by kiegroup.
the class AbstractMarshallerGeneratorTest method testPersonWithAddressMarshallers.
@Test
void testPersonWithAddressMarshallers() throws Exception {
ProtoGenerator generator = protoGeneratorBuilder().withDataClasses(convertTypes(PersonWithAddress.class)).build(null);
Proto proto = generator.protoOfDataClasses("org.kie.kogito.test");
assertThat(proto).isNotNull();
assertThat(proto.getMessages()).hasSize(2);
MarshallerGenerator marshallerGenerator = withGenerator(PersonWithAddresses.class);
List<CompilationUnit> classes = marshallerGenerator.generate(proto.serialize());
assertThat(classes).isNotNull();
assertThat(classes).hasSize(2);
Optional<ClassOrInterfaceDeclaration> marshallerClass = classes.get(0).getClassByName("AddressMessageMarshaller");
assertThat(marshallerClass).isPresent();
marshallerClass = classes.get(1).getClassByName("PersonWithAddressMessageMarshaller");
assertThat(marshallerClass).isPresent();
}
Aggregations