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