Skip to content

Commit ed16540

Browse files
committed
Re-add autowired template configuration and if case to work around unit test scenario
1 parent ab03c1b commit ed16540

File tree

1 file changed

+14
-2
lines changed
  • components/sbm-recipes-mule-to-boot/src/main/java/org/springframework/sbm/mule/actions/javadsl/translators/dwl

1 file changed

+14
-2
lines changed

components/sbm-recipes-mule-to-boot/src/main/java/org/springframework/sbm/mule/actions/javadsl/translators/dwl/DwlTransformTranslator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616

1717
package org.springframework.sbm.mule.actions.javadsl.translators.dwl;
1818

19+
import com.fasterxml.jackson.annotation.JsonIgnore;
1920
import freemarker.cache.FileTemplateLoader;
2021
import freemarker.template.Configuration;
2122
import freemarker.template.Version;
2223
import freemarker.template.Template;
24+
import lombok.Setter;
2325
import org.mulesoft.schema.mule.ee.dw.TransformMessageType;
26+
import org.springframework.beans.factory.annotation.Autowired;
2427
import org.springframework.sbm.java.util.Helper;
2528
import org.springframework.sbm.mule.actions.javadsl.translators.DslSnippet;
2629
import org.springframework.sbm.mule.actions.javadsl.translators.MuleComponentToSpringIntegrationDslTranslator;
@@ -38,6 +41,11 @@ public class DwlTransformTranslator implements MuleComponentToSpringIntegrationD
3841
public static final String TRANSFORM_STATEMENT_CONTENT = ".transform($CLASSNAME::transform)";
3942
public static final String externalPackageName = "com.example.javadsl";
4043

44+
@Autowired
45+
@Setter
46+
@JsonIgnore
47+
private Configuration templateConfiguration;
48+
4149
/* Define the stubs for adding the transformation as a comment to be addressed */
4250
private static final String externalClassContentPrefixTemplate = "package " + externalPackageName + ";\n\n" +
4351
"public class $CLASSNAME {\n" +
@@ -137,8 +145,12 @@ private DslSnippet formTriggerMeshDWLBasedDSLSnippet(TransformMessageType compon
137145

138146
StringWriter sw = new StringWriter();
139147
try {
140-
Configuration templateConfiguration = new Configuration(new Version("2.3.0"));
141-
templateConfiguration.setTemplateLoader(new FileTemplateLoader(new File("./src/main/resources/templates")));
148+
// In cases where the template library is not initialized (unit testing)
149+
if (templateConfiguration == null) {
150+
templateConfiguration = new Configuration(new Version("2.3.0"));
151+
templateConfiguration.setTemplateLoader(new FileTemplateLoader(new File("./src/main/resources/templates")));
152+
}
153+
142154
Template template = templateConfiguration.getTemplate("triggermesh-dw-transformation-template.ftl");
143155
template.process(templateParams, sw);
144156
} catch (Exception e) {

0 commit comments

Comments
 (0)