Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagodolphine committed Nov 16, 2020
1 parent d9340a6 commit ffc0c0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<GeneratedFile> generatedFiles = codeGenerator.generate();
assertThat(generatedFiles.size()).isGreaterThanOrEqualTo(6);
Expand All @@ -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());
Expand All @@ -71,10 +75,7 @@ private List<String> fileNames(List<GeneratedFile> 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<GeneratedFile> generatedFiles = codeGenerator.generate();
assertThat(generatedFiles.size()).isGreaterThanOrEqualTo(3);
Expand Down Expand Up @@ -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<GeneratedFile> generatedFiles = codeGenerator.generate();
assertThat(generatedFiles.size()).isGreaterThanOrEqualTo(3);
Expand All @@ -128,15 +129,15 @@ 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();
});
assertEquals("Model name should not be empty", re.getMessage());
}

private List<GeneratedFile> 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<GeneratedFile> generatedFiles = codeGenerator.generate();
Expand All @@ -155,9 +156,7 @@ private List<GeneratedFile> 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;
Expand All @@ -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<GeneratedFile> generatedFiles = codeGenerator.generate();
assertThat(generatedFiles).anyMatch(x -> x.relativePath().endsWith("InputSet.java"));
Expand Down

0 comments on commit ffc0c0c

Please sign in to comment.