use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.
the class RuleCodegenTest method generateGrafanaDashboards.
@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void generateGrafanaDashboards(KogitoBuildContext.Builder contextBuilder) {
contextBuilder.withAddonsConfig(AddonsConfig.builder().withPrometheusMonitoring(true).withMonitoring(true).build());
RuleCodegen incrementalRuleCodegen = getIncrementalRuleCodegenFromFiles(contextBuilder, new File(RESOURCE_PATH + "/org/kie/kogito/codegen/unit/RuleUnitQuery.drl"));
// The domain dashboard to monitor the RuleUnit is always generated.
int expectedDashboards = contextBuilder.build().hasRESTForGenerator(incrementalRuleCodegen) ? 3 : 1;
Collection<GeneratedFile> generatedFiles = incrementalRuleCodegen.withHotReloadMode().generate();
assertThat(generatedFiles.stream().filter(x -> x.type().equals(DashboardGeneratedFileUtils.DASHBOARD_TYPE))).hasSize(expectedDashboards);
}
use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.
the class RuleCodegenTest method generateGrafanaDashboardsExcluded.
@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void generateGrafanaDashboardsExcluded(KogitoBuildContext.Builder contextBuilder) {
contextBuilder.withAddonsConfig(AddonsConfig.builder().withPrometheusMonitoring(true).withMonitoring(true).build());
KogitoBuildContext context = contextBuilder.build();
context.setApplicationProperty(DISABLED_OPERATIONAL_DASHBOARDS, "find-adults,find-adults-age");
context.setApplicationProperty(DISABLED_DOMAIN_DASHBOARDS, "AdultUnit");
RuleCodegen incrementalRuleCodegen = getIncrementalRuleCodegenFromFiles(context, new File(RESOURCE_PATH + "/org/kie/kogito/codegen/unit/RuleUnitQuery.drl"));
Collection<GeneratedFile> generatedFiles = incrementalRuleCodegen.withHotReloadMode().generate();
assertThat(generatedFiles.stream().filter(x -> x.type().equals(DashboardGeneratedFileUtils.DASHBOARD_TYPE))).isEmpty();
}
use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.
the class AbstractProtoGeneratorTest method checkGeneratedProtoBufAndListing.
@Test
void checkGeneratedProtoBufAndListing() throws IOException {
AbstractProtoGenerator<T> generator = protoGeneratorBuilder().build(null);
List<GeneratedFile> generatedFiles = new ArrayList<>();
for (int i = 0; i < 5; i++) {
final Proto proto = new Proto("org.acme.test");
generatedFiles.add(generator.generateProtoFiles("protofile." + i, proto));
}
generator.generateProtoListingFile(generatedFiles).ifPresent(generatedFiles::add);
GeneratedFile listFile = generatedFiles.stream().filter(x -> x.relativePath().endsWith("list.json")).findFirst().get();
byte[] list = listFile.contents();
final ObjectMapper mapper = new ObjectMapper();
List<String> files = mapper.readValue(list, List.class);
assertThat(files).isNotEmpty();
assertThat(files).hasAtLeastOneElementOfType(String.class).contains("protofile.0.proto").hasSize(5);
}
use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.
the class DroolsModelBuilder method generateInternalResource.
private List<GeneratedFile> generateInternalResource(KogitoPackageSources pkgSources) {
List<GeneratedFile> modelFiles = new ArrayList<>();
org.drools.modelcompiler.builder.GeneratedFile reflectConfigSource = pkgSources.getReflectConfigSource();
if (reflectConfigSource != null) {
modelFiles.add(new GeneratedFile(GeneratedFileType.INTERNAL_RESOURCE, reflectConfigSource.getPath(), reflectConfigSource.getData()));
}
return modelFiles;
}
use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.
the class SampleCodegenTest method generate.
@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
void generate(KogitoBuildContext.Builder contextBuilder) {
KogitoBuildContext context = contextBuilder.build();
Collection<CollectedResource> resources = Arrays.asList(CollectedResourcesTestUtils.toCollectedResource("/sampleFile1.txt"), CollectedResourcesTestUtils.toCollectedResource("/sampleFile2.txt"));
SampleCodegen codeGenerator = SampleCodegen.ofCollectedResources(context, resources);
Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
if (contextBuilder.build().hasRESTForGenerator(codeGenerator)) {
assertThat(generatedFiles).hasSize(1);
List<GeneratedFile> generatedRests = generatedFiles.stream().filter(gf -> gf.type() == REST_TYPE).collect(Collectors.toList());
assertThat(generatedRests).hasSize(1);
CompilationUnit compilationUnit = StaticJavaParser.parse(new String(generatedRests.get(0).contents()));
Optional<FieldDeclaration> optionalFieldDeclaration = compilationUnit.findFirst(FieldDeclaration.class, SampleCodegen::isSampleRuntimeField);
assertThat(optionalFieldDeclaration).isNotEmpty();
FieldDeclaration fieldDeclaration = optionalFieldDeclaration.get();
if (context.hasDI()) {
assertThat(fieldDeclaration.getAnnotations()).isNotEmpty();
} else {
assertThat(fieldDeclaration.getVariable(0).getInitializer()).isNotEmpty();
}
} else {
assertThat(generatedFiles).isEmpty();
}
}
Aggregations