use of org.kie.kogito.codegen.api.io.CollectedResource in project kogito-runtimes by kiegroup.
the class ProcessGenerationIT method testProcessGeneration.
@ParameterizedTest
@MethodSource("processesProvider")
public void testProcessGeneration(String processFile) throws Exception {
// for some tests this needs to be set to true
System.setProperty("jbpm.enable.multi.con", "true");
ProcessCodegen processCodeGen = ProcessCodegen.ofCollectedResources(newContext(), Collections.singletonList(new CollectedResource(BASE_PATH, new FileSystemResource(new File(BASE_PATH.toString(), processFile)))));
RuleFlowProcess expected = (RuleFlowProcess) processCodeGen.processes().iterator().next();
Application app = generateCodeProcessesOnly(processFile);
AbstractProcess<? extends Model> process = (AbstractProcess<? extends Model>) app.get(Processes.class).processById(expected.getId());
assertThat(process).isNotNull().isSameAs(app.get(Processes.class).processById(expected.getId()));
RuleFlowProcess current = (RuleFlowProcess) process.get();
assertNotNull(current);
assertEquals(expected.getId(), current.getId(), "Id");
assertEquals(expected.getName(), current.getName(), "Name");
assertEquals(expected.getPackageName(), current.getPackageName(), "PackageName");
assertEquals(expected.getVisibility(), current.getVisibility(), "Visibility");
assertEquals(expected.getType(), current.getType(), "Type");
assertEquals(expected.isAutoComplete(), current.isAutoComplete(), "AutoComplete");
assertEquals(expected.isDynamic(), current.isDynamic(), "Dynamic");
if (expected.getVersion() != null) {
assertEquals(expected.getVersion(), current.getVersion());
} else {
assertEquals("1.0", current.getVersion());
}
assertEquals(expected.getImports(), current.getImports(), "Imports");
assertEquals(expected.getFunctionImports(), current.getFunctionImports(), "FunctionImports");
assertMetadata(expected.getMetaData(), current.getMetaData(), IGNORED_PROCESS_META);
assertNodes(expected.getNodes(), current.getNodes());
System.clearProperty("jbpm.enable.multi.con");
}
use of org.kie.kogito.codegen.api.io.CollectedResource 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();
}
}
use of org.kie.kogito.codegen.api.io.CollectedResource in project kogito-runtimes by kiegroup.
the class SampleCodegenTest method isEmpty.
@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void isEmpty(KogitoBuildContext.Builder contextBuilder) {
KogitoBuildContext context = contextBuilder.build();
SampleCodegen emptyCodeGenerator = SampleCodegen.ofCollectedResources(context, Collections.emptyList());
assertThat(emptyCodeGenerator.isEmpty()).isTrue();
assertThat(emptyCodeGenerator.isEnabled()).isFalse();
Collection<GeneratedFile> emptyGeneratedFiles = emptyCodeGenerator.generate();
assertThat(emptyGeneratedFiles.size()).isEqualTo(0);
Collection<CollectedResource> resources = Arrays.asList(CollectedResourcesTestUtils.toCollectedResource("/sampleFile1.txt"), CollectedResourcesTestUtils.toCollectedResource("/sampleFile2.txt"));
SampleCodegen codeGenerator = SampleCodegen.ofCollectedResources(context, resources);
assertThat(codeGenerator.isEmpty()).isFalse();
assertThat(codeGenerator.isEnabled()).isTrue();
Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
int minNumberOfResources = context.hasRESTForGenerator(codeGenerator) ? 1 : 0;
assertThat(generatedFiles.size()).isGreaterThanOrEqualTo(minNumberOfResources);
}
use of org.kie.kogito.codegen.api.io.CollectedResource in project kogito-runtimes by kiegroup.
the class CodegenSvgTest method testWithoutSVGAddonNoRenamedAndMoved.
@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void testWithoutSVGAddonNoRenamedAndMoved(KogitoBuildContext.Builder contextBuilder) {
KogitoBuildContext context = contextBuilder.withAddonsConfig(AddonsConfig.builder().withProcessSVG(false).build()).build();
Collection<CollectedResource> collectedResources = CollectedResourceProducer.fromPaths(BASE_PATH);
assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(TEST_PROCESS_SOURCE))).isTrue();
assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(TEST_PROCESS_GENERATED_SVG_SOURCE))).isTrue();
ProcessCodegen codeGenerator = ProcessCodegen.ofCollectedResources(context, collectedResources);
Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
assertThat(generatedFiles).isNotEmpty();
List<GeneratedFile> resources = generatedFiles.stream().filter(generatedFile -> generatedFile.type().equals(GeneratedFileType.INTERNAL_RESOURCE)).collect(Collectors.toList());
assertThat(resources.size()).isZero();
}
use of org.kie.kogito.codegen.api.io.CollectedResource in project kogito-runtimes by kiegroup.
the class CodegenSvgTest method testExportedSVGRenamedAndMoved.
@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void testExportedSVGRenamedAndMoved(KogitoBuildContext.Builder contextBuilder) {
KogitoBuildContext context = contextBuilder.withAddonsConfig(AddonsConfig.builder().withProcessSVG(true).build()).build();
Collection<CollectedResource> collectedResources = CollectedResourceProducer.fromPaths(BASE_PATH);
assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(TEST_PROCESS_SOURCE))).isTrue();
assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(TEST_PROCESS_GENERATED_SVG_SOURCE))).isTrue();
assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(String.format(ProcessCodegen.SVG_EXPORT_NAME_EXPRESION, "hiring")))).isTrue();
ProcessCodegen codeGenerator = ProcessCodegen.ofCollectedResources(context, collectedResources);
Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
assertThat(generatedFiles).isNotEmpty();
List<GeneratedFile> resources = generatedFiles.stream().filter(generatedFile -> generatedFile.type().equals(GeneratedFileType.INTERNAL_RESOURCE)).collect(Collectors.toList());
assertThat(resources.size()).isEqualTo(1);
assertThat("META-INF/processSVG/" + TEST_PROCESS_ID + ".svg").isEqualTo(resources.get(0).relativePath());
}
Aggregations