diff --git a/kogito-codegen/src/main/java/org/kie/kogito/codegen/decision/DecisionRestResourceGenerator.java b/kogito-codegen/src/main/java/org/kie/kogito/codegen/decision/DecisionRestResourceGenerator.java index a958d97408f..cfdc81b43a5 100644 --- a/kogito-codegen/src/main/java/org/kie/kogito/codegen/decision/DecisionRestResourceGenerator.java +++ b/kogito-codegen/src/main/java/org/kie/kogito/codegen/decision/DecisionRestResourceGenerator.java @@ -89,7 +89,7 @@ public DecisionRestResourceGenerator(DMNModel model, String appCanonicalName) { String classPrefix = StringUtils.ucFirst(decisionName); this.resourceClazzName = classPrefix + "Resource"; this.relativePath = packageName.replace(".", "/") + "/" + resourceClazzName + ".java"; - generator = new TemplatedGenerator(packageName, "DecisionRestResource",CDI_TEMPLATE, SPRING_TEMPLATE); + generator = new TemplatedGenerator(packageName, "DecisionRestResource",CDI_TEMPLATE, SPRING_TEMPLATE, CDI_TEMPLATE); } public String generate() { diff --git a/kogito-codegen/src/main/java/org/kie/kogito/codegen/prediction/PMMLRestResourceGenerator.java b/kogito-codegen/src/main/java/org/kie/kogito/codegen/prediction/PMMLRestResourceGenerator.java index 25541d410da..e7580a36fbe 100644 --- a/kogito-codegen/src/main/java/org/kie/kogito/codegen/prediction/PMMLRestResourceGenerator.java +++ b/kogito-codegen/src/main/java/org/kie/kogito/codegen/prediction/PMMLRestResourceGenerator.java @@ -57,7 +57,7 @@ public PMMLRestResourceGenerator(KiePMMLModel model, String appCanonicalName) { this.appCanonicalName = appCanonicalName; this.resourceClazzName = classPrefix + "Resource"; this.relativePath = packageName.replace(".", "/") + "/" + resourceClazzName + ".java"; - this.generator = new TemplatedGenerator(packageName, "DecisionRestResource",CDI_TEMPLATE, SPRING_TEMPLATE); + this.generator = new TemplatedGenerator(packageName, "DecisionRestResource",CDI_TEMPLATE, SPRING_TEMPLATE, CDI_TEMPLATE); } public String generate() { diff --git a/kogito-codegen/src/main/resources/class-templates/events/CloudEventsListenerResource.java b/kogito-codegen/src/main/resources/class-templates/events/CloudEventsListenerResource.java index 3f6cd2a2393..85e1791677b 100644 --- a/kogito-codegen/src/main/resources/class-templates/events/CloudEventsListenerResource.java +++ b/kogito-codegen/src/main/resources/class-templates/events/CloudEventsListenerResource.java @@ -1,5 +1,4 @@ -package org.kie.kogito.app;sudo dnf upgrade --refresh - +package org.kie.kogito.app; import com.fasterxml.jackson.databind.ObjectMapper; import io.cloudevents.CloudEvent; diff --git a/kogito-codegen/src/test/java/org/kie/kogito/codegen/decision/DecisionCodegenTest.java b/kogito-codegen/src/test/java/org/kie/kogito/codegen/decision/DecisionCodegenTest.java index b72fa933307..105df25bb8e 100644 --- a/kogito-codegen/src/test/java/org/kie/kogito/codegen/decision/DecisionCodegenTest.java +++ b/kogito-codegen/src/test/java/org/kie/kogito/codegen/decision/DecisionCodegenTest.java @@ -28,6 +28,7 @@ import org.kie.kogito.codegen.AddonsConfig; import org.kie.kogito.codegen.GeneratedFile; import org.kie.kogito.codegen.GeneratorContext; +import org.kie.kogito.codegen.di.CDIDependencyInjectionAnnotator; import org.kie.kogito.codegen.io.CollectedResource; import org.kie.kogito.grafana.JGrafana; @@ -39,11 +40,7 @@ public class DecisionCodegenTest { @Test public void generateAllFiles() throws Exception { - - GeneratorContext context = stronglyTypedContext(); - - DecisionCodegen codeGenerator = DecisionCodegen.ofCollectedResources(CollectedResource.fromPaths(Paths.get("src/test/resources/decision/models/vacationDays").toAbsolutePath())); - codeGenerator.setContext(context); + DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision/models/vacationDays"); List generatedFiles = codeGenerator.generate(); assertThat(generatedFiles.size()).isGreaterThanOrEqualTo(6); @@ -59,6 +56,13 @@ public void generateAllFiles() throws Exception { assertNotNull(classDeclaration); } + public DecisionCodegen getDecisionCodegen(String s) { + GeneratorContext context = stronglyTypedContext(); + DecisionCodegen codeGenerator = DecisionCodegen.ofCollectedResources(CollectedResource.fromPaths(Paths.get(s).toAbsolutePath())); + codeGenerator.setContext(context); + return codeGenerator; + } + private GeneratorContext stronglyTypedContext() { Properties properties = new Properties(); properties.put(DecisionCodegen.STRONGLY_TYPED_CONFIGURATION_KEY, Boolean.TRUE.toString()); @@ -71,10 +75,7 @@ private List fileNames(List generatedFiles) { @Test public void doNotGenerateTypesafeInfo() throws Exception { - GeneratorContext context = stronglyTypedContext(); - - DecisionCodegen codeGenerator = DecisionCodegen.ofCollectedResources(CollectedResource.fromPaths(Paths.get("src/test/resources/decision/alltypes/").toAbsolutePath())); - codeGenerator.setContext(context); + DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision/alltypes/"); List generatedFiles = codeGenerator.generate(); assertThat(generatedFiles.size()).isGreaterThanOrEqualTo(3); @@ -117,7 +118,7 @@ public void givenADMNModelWhenMonitoringAndTracingAreActiveThenTheGrafanaDashboa @Test public void resilientToDuplicateDMNIDs() throws Exception { - DecisionCodegen codeGenerator = DecisionCodegen.ofCollectedResources(CollectedResource.fromPaths(Paths.get("src/test/resources/decision-test20200507").toAbsolutePath())); + DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision-test20200507"); List generatedFiles = codeGenerator.generate(); assertThat(generatedFiles.size()).isGreaterThanOrEqualTo(3); @@ -128,7 +129,7 @@ public void resilientToDuplicateDMNIDs() throws Exception { @Test public void emptyName() throws Exception { - DecisionCodegen codeGenerator = DecisionCodegen.ofCollectedResources(CollectedResource.fromPaths(Paths.get("src/test/resources/decision-empty-name").toAbsolutePath())); + DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision-empty-name"); RuntimeException re = Assertions.assertThrows(RuntimeException.class, () -> { codeGenerator.generate(); }); @@ -136,7 +137,7 @@ public void emptyName() throws Exception { } private List generateTestDashboards(AddonsConfig addonsConfig) throws IOException { - DecisionCodegen codeGenerator = DecisionCodegen.ofCollectedResources(CollectedResource.fromPaths(Paths.get("src/test/resources/decision/models/vacationDays").toAbsolutePath())) + DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision/models/vacationDays") .withAddons(addonsConfig); List generatedFiles = codeGenerator.generate(); @@ -155,9 +156,7 @@ private List generateTestDashboards(AddonsConfig addonsConfig) th @Test public void testNSEW_positive() throws Exception { // This test is meant to check that IFF Eclipse MP OpenAPI annotations are available on Build/CP of Kogito application, annotation is used with codegen - DecisionCodegen codeGenerator = DecisionCodegen.ofCollectedResources(CollectedResource.fromPaths(Paths.get("src/test/resources/decision-NSEW").toAbsolutePath())); - GeneratorContext context = stronglyTypedContext(); - codeGenerator.setContext(context); + DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision-NSEW"); codeGenerator.withClassLoader(new ClassLoader() { public Class loadClass(String name) throws ClassNotFoundException { return Object.class; @@ -172,9 +171,7 @@ public Class loadClass(String name) throws ClassNotFoundException { @Test public void testNSEW_negative() throws Exception { - DecisionCodegen codeGenerator = DecisionCodegen.ofCollectedResources(CollectedResource.fromPaths(Paths.get("src/test/resources/decision-NSEW").toAbsolutePath())); - GeneratorContext context = stronglyTypedContext(); - codeGenerator.setContext(context); + DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision-NSEW"); List generatedFiles = codeGenerator.generate(); assertThat(generatedFiles).anyMatch(x -> x.relativePath().endsWith("InputSet.java"));