16
16
17
17
package org .springframework .sbm .mule .actions .javadsl .translators .dwl ;
18
18
19
+ import com .fasterxml .jackson .annotation .JsonIgnore ;
19
20
import freemarker .cache .FileTemplateLoader ;
20
21
import freemarker .template .Configuration ;
21
22
import freemarker .template .Version ;
22
23
import freemarker .template .Template ;
24
+ import lombok .Setter ;
23
25
import org .mulesoft .schema .mule .ee .dw .TransformMessageType ;
26
+ import org .springframework .beans .factory .annotation .Autowired ;
24
27
import org .springframework .sbm .java .util .Helper ;
25
28
import org .springframework .sbm .mule .actions .javadsl .translators .DslSnippet ;
26
29
import org .springframework .sbm .mule .actions .javadsl .translators .MuleComponentToSpringIntegrationDslTranslator ;
@@ -38,6 +41,11 @@ public class DwlTransformTranslator implements MuleComponentToSpringIntegrationD
38
41
public static final String TRANSFORM_STATEMENT_CONTENT = ".transform($CLASSNAME::transform)" ;
39
42
public static final String externalPackageName = "com.example.javadsl" ;
40
43
44
+ @ Autowired
45
+ @ Setter
46
+ @ JsonIgnore
47
+ private Configuration templateConfiguration ;
48
+
41
49
/* Define the stubs for adding the transformation as a comment to be addressed */
42
50
private static final String externalClassContentPrefixTemplate = "package " + externalPackageName + ";\n \n " +
43
51
"public class $CLASSNAME {\n " +
@@ -137,8 +145,12 @@ private DslSnippet formTriggerMeshDWLBasedDSLSnippet(TransformMessageType compon
137
145
138
146
StringWriter sw = new StringWriter ();
139
147
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
+
142
154
Template template = templateConfiguration .getTemplate ("triggermesh-dw-transformation-template.ftl" );
143
155
template .process (templateParams , sw );
144
156
} catch (Exception e ) {
0 commit comments