use of com.devonfw.cobigen.impl.config.entity.Increment in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testIncrementComposition_combiningAllPossibleReferences.
/**
* Tests the correct resolution of references of templates / templateScans / increments.
*/
@Test
public void testIncrementComposition_combiningAllPossibleReferences() {
// given
TemplatesConfigurationReader target = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_increment_composition");
Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// when
Map<String, Template> templates = target.loadTemplates(trigger);
Map<String, Increment> increments = target.loadIncrements(templates, trigger);
// validation
assertThat(templates).containsOnlyKeys("templateDecl", "prefix_scanned", "scanned", "prefix_scanned2", "scanned2");
assertThat(increments).containsOnlyKeys("0", "1", "2");
assertThat(increments.values()).hasSize(3);
assertThat(increments.get("0").getTemplates()).extracting("name").containsOnly("templateDecl");
assertThat(increments.get("1").getTemplates()).extracting("name").containsOnly("templateDecl", "prefix_scanned", "scanned", "scanned2");
assertThat(increments.get("2").getTemplates()).extracting("name").containsOnly("templateDecl", "prefix_scanned", "scanned", "prefix_scanned2");
}
use of com.devonfw.cobigen.impl.config.entity.Increment in project cobigen by devonfw.
the class ConfigurationInterpreterImpl method convertIncrements.
/**
* Converts a {@link List} of {@link Increment}s with their parent {@link Trigger} to a {@link List} of
* {@link IncrementTo}s
*
* @param increments the {@link List} of {@link Increment}s
* @param trigger the parent {@link Trigger}
* @param matchingTriggerIds the {@link List} of matching trigger Id
* @return the {@link List} of {@link IncrementTo}s
*/
// TODO create ToConverter
private List<IncrementTo> convertIncrements(List<Increment> increments, Trigger trigger, List<String> matchingTriggerIds) {
List<IncrementTo> incrementTos = Lists.newLinkedList();
for (Increment increment : increments) {
String triggerId = increment.getTrigger().getId();
if (!triggerId.equals(trigger.getId())) {
// Check if the external trigger also matches
if (!matchingTriggerIds.contains(triggerId)) {
// Abort generation
throw new InvalidConfigurationException("An external incrementRef to " + increment.getTrigger().getId() + "::" + increment.getName() + " is referenced from " + trigger.getId() + " but its trigger does not match");
}
}
List<TemplateTo> templates = Lists.newLinkedList();
for (Template template : increment.getTemplates()) {
templates.add(new TemplateTo(template.getName(), template.getMergeStrategy(), triggerId));
}
incrementTos.add(new IncrementTo(increment.getName(), increment.getDescription(), triggerId, templates, convertIncrements(increment.getDependentIncrements(), trigger, matchingTriggerIds)));
}
return incrementTos;
}
use of com.devonfw.cobigen.impl.config.entity.Increment in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testIncrementRefOutsideCurrentFile.
/**
* Tests the correct resolution of incrementsRef from outside the current templates file. (Issue #678)
*/
@Test
public void testIncrementRefOutsideCurrentFile() {
// given
Trigger trigger = new Trigger("testingTrigger", "asdf", "valid_external_incrementref", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
Path config = Paths.get(new File(testFileRootPath).toURI());
ConfigurationHolder configurationHolder = new ConfigurationHolder(config.toUri());
TemplatesConfiguration templatesConfiguration = configurationHolder.readTemplatesConfiguration(trigger);
Map<String, Increment> increments = templatesConfiguration.getIncrements();
// validation
assertThat(templatesConfiguration.getTrigger().getId()).isEqualTo("testingTrigger");
assertThat(increments).containsOnlyKeys("3", "4", "5");
Increment incrementThree = increments.get("3").getDependentIncrements().get(0);
assertThat(incrementThree.getName()).isEqualTo("0");
assertThat(incrementThree.getTemplates().size()).isEqualTo(1);
Increment incrementFour = increments.get("4").getDependentIncrements().get(0);
assertThat(incrementFour.getName()).isEqualTo("1");
assertThat(incrementFour.getTemplates().size()).isEqualTo(4);
Increment incrementFive = increments.get("5").getDependentIncrements().get(0);
assertThat(incrementFive.getName()).isEqualTo("2");
assertThat(incrementFive.getTemplates().size()).isEqualTo(4);
}
use of com.devonfw.cobigen.impl.config.entity.Increment in project cobigen by devonfw.
the class TemplatesConfigurationReaderTest method testCorrectResolutionOfTemplateScanReferences.
/**
* Tests the correct resolution of template scan references in increments.
*
* @throws InvalidConfigurationException test fails
*/
@Test
public void testCorrectResolutionOfTemplateScanReferences() throws InvalidConfigurationException {
// given
TemplatesConfigurationReader reader = new TemplatesConfigurationReader(new File(testFileRootPath).toPath(), "valid_template_scan_references");
Trigger trigger = new Trigger("", "asdf", "", Charset.forName("UTF-8"), new LinkedList<Matcher>(), new LinkedList<ContainerMatcher>());
// when
Map<String, Template> templates = reader.loadTemplates(trigger);
Map<String, Increment> increments = reader.loadIncrements(templates, trigger);
// validation
assertThat(templates).containsOnlyKeys("prefix_foo_BarClass.java", "prefix_bar_Foo2Class.java", "prefix_foo_FooClass.java");
assertThat(increments).containsOnlyKeys("test");
assertThat(increments.get("test").getTemplates()).extracting("name").containsOnly("prefix_foo_BarClass.java", "prefix_foo_FooClass.java");
}
Aggregations