pibizza commented on code in PR #3671:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3671#discussion_r1764614420


##########
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:
   Add the last three elements as parameters in the test. In general you do not 
want to see cases and ifs in a test - if you have an if it is two tests 
conflated. this reduces clarity and betrays the single purpose rule of a test.



-- 
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]

Reply via email to