pibizza commented on code in PR #3671:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3671#discussion_r1764797967
##########
kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/ProcessResourceGeneratorTest.java:
##########
@@ -152,31 +162,139 @@ void
testGenerateStartSignalEventNoPayload(KogitoBuildContext.Builder contextBui
.forEach(method -> assertMethodOutputModelType(method,
outputType));
}
- void testOpenApiDocumentation(KogitoBuildContext.Builder contextBuilder,
String fileName, String expectedSummary, String expectedDescription) {
+ @ParameterizedTest
+
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
+ void testTransactionEnabled(KogitoBuildContext.Builder contextBuilder) {
+ String fileName =
"src/test/resources/startsignal/StartSignalEventNoPayload.bpmn2";
+
+ ProcessResourceGenerator processResourceGenerator =
getProcessResourceGenerator(contextBuilder, fileName, true);
+ CompilationUnit compilationUnit =
+
processResourceGenerator.createCompilationUnit(processResourceGenerator.createTemplatedGeneratorBuilder());
+ assertThat(compilationUnit).isNotNull();
+ Optional<ClassOrInterfaceDeclaration>
classOrInterfaceDeclarationOptional = compilationUnit.getChildNodes().stream()
+ .filter(ClassOrInterfaceDeclaration.class::isInstance)
+ .map(ClassOrInterfaceDeclaration.class::cast)
+ .findFirst();
+ assertThat(classOrInterfaceDeclarationOptional).isPresent();
+ ClassOrInterfaceDeclaration classOrInterfaceDeclaration =
classOrInterfaceDeclarationOptional.get();
+ switch (contextBuilder.build().name()) {
+ case QuarkusKogitoBuildContext.CONTEXT_NAME ->
testTransactionEnabled(compilationUnit, classOrInterfaceDeclaration,
JAKARTA_TRANSACTIONAL_IMPORT, TRANSACTIONAL_ANNOTATION,
+ JAKARTA_REST_ANNOTATIONS);
+ case SpringBootKogitoBuildContext.CONTEXT_NAME ->
testTransactionEnabled(compilationUnit, classOrInterfaceDeclaration,
SPRING_TRANSACTIONAL_IMPORT, TRANSACTIONAL_ANNOTATION,
+ SPRING_REST_ANNOTATIONS);
+ case JavaKogitoBuildContext.CONTEXT_NAME ->
testTransactionEnabled(compilationUnit, classOrInterfaceDeclaration,
JAKARTA_TRANSACTIONAL_IMPORT, TRANSACTIONAL_ANNOTATION,
+ JAKARTA_REST_ANNOTATIONS);
+ }
+ processResourceGenerator.manageTransactional(compilationUnit);
+ switch (contextBuilder.build().name()) {
+ case QuarkusKogitoBuildContext.CONTEXT_NAME ->
testTransactionEnabled(compilationUnit, classOrInterfaceDeclaration,
JAKARTA_TRANSACTIONAL_IMPORT, TRANSACTIONAL_ANNOTATION,
+ JAKARTA_REST_ANNOTATIONS);
+ case SpringBootKogitoBuildContext.CONTEXT_NAME ->
testTransactionEnabled(compilationUnit, classOrInterfaceDeclaration,
SPRING_TRANSACTIONAL_IMPORT, TRANSACTIONAL_ANNOTATION,
+ SPRING_REST_ANNOTATIONS);
+ case JavaKogitoBuildContext.CONTEXT_NAME ->
testTransactionEnabled(compilationUnit, classOrInterfaceDeclaration,
JAKARTA_TRANSACTIONAL_IMPORT, TRANSACTIONAL_ANNOTATION,
+ JAKARTA_REST_ANNOTATIONS);
+ }
+ }
+
+ @ParameterizedTest
+
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
+ void testTransactionDisabled(KogitoBuildContext.Builder contextBuilder) {
+ String fileName =
"src/test/resources/startsignal/StartSignalEventNoPayload.bpmn2";
+
+ ProcessResourceGenerator processResourceGenerator =
getProcessResourceGenerator(contextBuilder, fileName,
+ false);
+ CompilationUnit compilationUnit =
+
processResourceGenerator.createCompilationUnit(processResourceGenerator.createTemplatedGeneratorBuilder());
+ assertThat(compilationUnit).isNotNull();
+ Optional<ClassOrInterfaceDeclaration>
classOrInterfaceDeclarationOptional = compilationUnit.getChildNodes().stream()
+ .filter(ClassOrInterfaceDeclaration.class::isInstance)
+ .map(ClassOrInterfaceDeclaration.class::cast)
+ .findFirst();
+ assertThat(classOrInterfaceDeclarationOptional).isPresent();
+ ClassOrInterfaceDeclaration classOrInterfaceDeclaration =
classOrInterfaceDeclarationOptional.get();
+ switch (contextBuilder.build().name()) {
+ case QuarkusKogitoBuildContext.CONTEXT_NAME ->
testTransactionEnabled(compilationUnit, classOrInterfaceDeclaration,
JAKARTA_TRANSACTIONAL_IMPORT, TRANSACTIONAL_ANNOTATION,
Review Comment:
I disagree. The method in question is
public static Stream<Arguments> contextBuilders() {
return Stream.of(
Arguments.of(JavaKogitoBuildContext.builder()),
Arguments.of(QuarkusKogitoBuildContext.builder()),
Arguments.of(SpringBootKogitoBuildContext.builder()));
}
For this test we need something like:
public static Stream<Arguments> contextBuildersWithExtras() { //no idea
about the name
return Stream.of(
Arguments.of(JavaKogitoBuildContext.builder(),
JAKARTA_TRANSACTIONAL_IMPORT, TRANSACTIONAL_ANNOTATION, // and so on
This will completely remove the two switch cases, allow you to inline the
testTransaction that is very opaque and make everything much cleaner and easier
to read.
if you prefer to move this forward, I can provide a PR later once the code
is merged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]