use of org.kie.kogito.codegen.api.Generator.REST_TYPE 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