|
12 | 12 | import static org.mockito.internal.matchers.Any.ANY;
|
13 | 13 |
|
14 | 14 | import java.io.File;
|
| 15 | +import java.util.HashMap; |
15 | 16 | import java.util.List;
|
16 | 17 |
|
17 | 18 | import org.apache.commons.lang3.SystemUtils;
|
|
28 | 29 | import com.capgemini.cobigen.extension.to.TemplateTo;
|
29 | 30 | import com.capgemini.cobigen.pluginmanager.PluginRegistry;
|
30 | 31 | import com.capgemini.cobigen.systemtest.common.AbstractApiTest;
|
31 |
| -import com.google.common.collect.ImmutableMap; |
32 | 32 |
|
33 | 33 | /**
|
34 | 34 | * Test suite for template-scan related system tests
|
@@ -62,10 +62,13 @@ public void testCorrectDestinationResoution() throws Exception {
|
62 | 62 | generationRootFolder.getAbsolutePath());
|
63 | 63 | List<TemplateTo> templates = target.getMatchingTemplates(input);
|
64 | 64 | Assert.assertNotNull(templates);
|
65 |
| - Assert.assertEquals(1, templates.size()); |
| 65 | + |
| 66 | + TemplateTo targetTemplate = |
| 67 | + getTemplateById(templates, "prefix_${variables.component#cap_first#replace('1','ONE')}.java"); |
| 68 | + Assert.assertNotNull(targetTemplate); |
66 | 69 |
|
67 | 70 | // Execution
|
68 |
| - target.generate(input, templates.get(0), false); |
| 71 | + target.generate(input, targetTemplate, false); |
69 | 72 |
|
70 | 73 | // Validation
|
71 | 74 | Assert.assertTrue(new File(generationRootFolder.getAbsolutePath() + SystemUtils.FILE_SEPARATOR
|
@@ -95,6 +98,76 @@ public void testScanTemplatesFromArchivFile() throws Exception {
|
95 | 98 | assertThat(templates.size(), equalTo(7));
|
96 | 99 | }
|
97 | 100 |
|
| 101 | + /** |
| 102 | + * Tests the correct destination resolution for resources obtained by template-scans in the case of an |
| 103 | + * empty path element |
| 104 | + * @throws Exception |
| 105 | + * test fails |
| 106 | + * @author mbrunnli (20.12.2015) |
| 107 | + */ |
| 108 | + @Test |
| 109 | + public void testCorrectDestinationResoution_emptyPathElement() throws Exception { |
| 110 | + Object input = createTestInputAndConfigureMock(); |
| 111 | + |
| 112 | + File generationRootFolder = tmpFolder.newFolder("generationRootFolder"); |
| 113 | + // Useful to see generates if necessary, comment the generationRootFolder above then |
| 114 | + // File generationRootFolder = new File(testFileRootPath + "generates"); |
| 115 | + |
| 116 | + // pre-processing |
| 117 | + File templatesFolder = new File(testFileRootPath); |
| 118 | + CobiGen target = new CobiGen(templatesFolder.toURI()); |
| 119 | + target.setContextSetting(ContextSetting.GenerationTargetRootPath, |
| 120 | + generationRootFolder.getAbsolutePath()); |
| 121 | + List<TemplateTo> templates = target.getMatchingTemplates(input); |
| 122 | + Assert.assertNotNull(templates); |
| 123 | + |
| 124 | + TemplateTo targetTemplate = getTemplateById(templates, "prefix_Test.java"); |
| 125 | + Assert.assertNotNull(targetTemplate); |
| 126 | + |
| 127 | + // Execution |
| 128 | + target.generate(input, targetTemplate, false); |
| 129 | + |
| 130 | + // Validation |
| 131 | + Assert.assertTrue(new File(generationRootFolder.getAbsolutePath() + SystemUtils.FILE_SEPARATOR |
| 132 | + + "src" + SystemUtils.FILE_SEPARATOR + "main" + SystemUtils.FILE_SEPARATOR + "java" |
| 133 | + + SystemUtils.FILE_SEPARATOR + "base" + SystemUtils.FILE_SEPARATOR + "Test.java").exists()); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Tests the correct destination resolution for resources obtained by template-scans in the case of |
| 138 | + * multiple empty path elements |
| 139 | + * @throws Exception |
| 140 | + * test fails |
| 141 | + * @author mbrunnli (20.12.2015) |
| 142 | + */ |
| 143 | + @Test |
| 144 | + public void testCorrectDestinationResoution_emptyPathElements() throws Exception { |
| 145 | + Object input = createTestInputAndConfigureMock(); |
| 146 | + |
| 147 | + File generationRootFolder = tmpFolder.newFolder("generationRootFolder"); |
| 148 | + // Useful to see generates if necessary, comment the generationRootFolder above then |
| 149 | + // File generationRootFolder = new File(testFileRootPath + "generates"); |
| 150 | + |
| 151 | + // pre-processing |
| 152 | + File templatesFolder = new File(testFileRootPath); |
| 153 | + CobiGen target = new CobiGen(templatesFolder.toURI()); |
| 154 | + target.setContextSetting(ContextSetting.GenerationTargetRootPath, |
| 155 | + generationRootFolder.getAbsolutePath()); |
| 156 | + List<TemplateTo> templates = target.getMatchingTemplates(input); |
| 157 | + Assert.assertNotNull(templates); |
| 158 | + |
| 159 | + TemplateTo targetTemplate = getTemplateById(templates, "prefix_MultiEmpty.java"); |
| 160 | + Assert.assertNotNull(targetTemplate); |
| 161 | + |
| 162 | + // Execution |
| 163 | + target.generate(input, targetTemplate, false); |
| 164 | + |
| 165 | + // Validation |
| 166 | + Assert.assertTrue(new File(generationRootFolder.getAbsolutePath() + SystemUtils.FILE_SEPARATOR |
| 167 | + + "src" + SystemUtils.FILE_SEPARATOR + "main" + SystemUtils.FILE_SEPARATOR + "java" |
| 168 | + + SystemUtils.FILE_SEPARATOR + "base" + SystemUtils.FILE_SEPARATOR + "MultiEmpty.java").exists()); |
| 169 | + } |
| 170 | + |
98 | 171 | /**
|
99 | 172 | * Creates simple to debug test data, which includes only one object as input. A
|
100 | 173 | * {@link ITriggerInterpreter TriggerInterpreter} will be mocked with all necessary supplier classes to
|
@@ -140,16 +213,19 @@ public String toString() {
|
140 | 213 | .thenReturn(true);
|
141 | 214 |
|
142 | 215 | // Simulate variable resolving of any plug-in
|
| 216 | + HashMap<String, String> variables = new HashMap<>(3); |
| 217 | + variables.put("rootPackage", "com.capgemini"); |
| 218 | + variables.put("component", "comp1"); |
| 219 | + variables.put("detail", null); |
| 220 | + |
143 | 221 | when(
|
144 | 222 | matcher.resolveVariables(
|
145 | 223 | argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))),
|
146 | 224 | argThat(hasItemsInList(
|
147 | 225 | //
|
148 | 226 | new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"), equalTo("1")),
|
149 | 227 | new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"), equalTo("3"))))))
|
150 |
| - .thenReturn( |
151 |
| - ImmutableMap.<String, String> builder().put("rootPackage", "com.capgemini") |
152 |
| - .put("component", "comp1").build()); |
| 228 | + .thenReturn(variables); |
153 | 229 |
|
154 | 230 | PluginRegistry.registerTriggerInterpreter(triggerInterpreter);
|
155 | 231 |
|
|
0 commit comments