Search in sources :

Example 1 with TemplateFile

use of com.devonfw.cobigen.impl.config.entity.TemplateFile in project cobigen by devonfw.

the class TemplatePathTest method verifyChildren.

private static void verifyChildren(TemplateFolder folder, TemplatePath... children) {
    assertThat(folder.getChildren()).containsOnly(children);
    if (children.length == 0) {
        return;
    }
    List<TemplateFolder> childFolders = new ArrayList<>();
    List<TemplateFile> childFiles = new ArrayList<>();
    for (TemplatePath child : children) {
        if (child.isFolder()) {
            assertThat(child.isFile()).isFalse();
            childFolders.add((TemplateFolder) child);
        } else {
            assertThat(child.isFile()).isTrue();
            childFiles.add((TemplateFile) child);
        }
    }
}
Also used : TemplatePath(com.devonfw.cobigen.impl.config.entity.TemplatePath) ArrayList(java.util.ArrayList) TemplateFolder(com.devonfw.cobigen.impl.config.entity.TemplateFolder) TemplateFile(com.devonfw.cobigen.impl.config.entity.TemplateFile)

Example 2 with TemplateFile

use of com.devonfw.cobigen.impl.config.entity.TemplateFile in project cobigen by devonfw.

the class TemplatePathTest method testFolderTree.

/**
 * Test {@link TemplateFolder#create(Path)} for folder tree with property overloading.
 */
@Test
public void testFolderTree() {
    String filename = "tree";
    String emptyFile = "empty-file";
    Path path = Paths.get(TEST_FILES_ROOT_PATH + filename);
    TemplateFolder folder = TemplateFolder.create(path);
    verifyRootFolder(folder, path);
    assertThat(folder).isNotNull();
    assertThat(folder.getVariables().asMap()).isEmpty();
    TemplateFolder having = verifyChildFolder(folder, path, "having");
    TemplateFolder or = verifyChildFolder(folder, path, "or");
    verifyChildren(folder, having, or);
    assertThat(having.getVariables().asMap()).isEmpty();
    TemplateFolder property = verifyChildFolder(having, having.getPath(), "property");
    verifyChildren(having, property);
    assertThat(property.getChild("cobigen.properties")).isNull();
    assertThat(property.getChild("COBIGEN.PROPERTIES")).isNull();
    assertThat(property.getVariables().asMap()).hasSize(2).containsEntry("foo", "foo").containsEntry("bar", "bar");
    TemplateFolder override = verifyChildFolder(property, property.getPath(), "override");
    verifyChildren(property, override);
    assertThat(override.getVariables().asMap()).hasSize(2).containsEntry("foo", "bar").containsEntry("bar", "bar");
    TemplateFile emptyFileInOverride = verifyChildFile(override, override.getPath(), emptyFile);
    verifyChildren(override, emptyFileInOverride);
    TemplateFolder not = verifyChildFolder(or, or.getPath(), "not");
    assertThat(not.getVariables().asMap()).isEmpty();
    TemplateFile emptyFileInNot = verifyChildFile(not, not.getPath(), emptyFile);
    verifyChildren(not, emptyFileInNot);
}
Also used : TemplatePath(com.devonfw.cobigen.impl.config.entity.TemplatePath) Path(java.nio.file.Path) TemplateFolder(com.devonfw.cobigen.impl.config.entity.TemplateFolder) TemplateFile(com.devonfw.cobigen.impl.config.entity.TemplateFile) Test(org.junit.Test) AbstractUnitTest(com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)

Aggregations

TemplateFile (com.devonfw.cobigen.impl.config.entity.TemplateFile)2 TemplateFolder (com.devonfw.cobigen.impl.config.entity.TemplateFolder)2 TemplatePath (com.devonfw.cobigen.impl.config.entity.TemplatePath)2 AbstractUnitTest (com.devonfw.cobigen.unittest.config.common.AbstractUnitTest)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1