Search in sources :

Example 1 with Template

use of dev.jbang.catalog.Template in project jbang by jbangdev.

the class TestTemplate method testGetTemplateThreeWithProperties.

@Test
void testGetTemplateThreeWithProperties() throws IOException {
    Template template = Template.get("three-with-properties");
    assertThat(template, notNullValue());
    assertThat(template.description, is("Template 3"));
    assertThat(template.fileRefs, aMapWithSize(2));
    assertThat(template.fileRefs.keySet(), hasItems("src/{filename}", "src/file2.java"));
    assertThat(template.fileRefs.values(), hasItems("tpl2/file2_1.java", "tpl2/file2_2.java"));
    assertThat(template.properties.entrySet(), hasItems(new AbstractMap.SimpleEntry<>("test-key", new TemplateProperty(null, null)), new AbstractMap.SimpleEntry<>("test-key-with-description", new TemplateProperty("This is a test description", null)), new AbstractMap.SimpleEntry<>("test-key-with-description-and-default-value", new TemplateProperty("This is a test description with default value", "2.11")), new AbstractMap.SimpleEntry<>("test-key-with-default-value", new TemplateProperty(null, "3.12"))));
}
Also used : TemplateProperty(dev.jbang.catalog.TemplateProperty) Template(dev.jbang.catalog.Template) Test(org.junit.jupiter.api.Test) BaseTest(dev.jbang.BaseTest)

Example 2 with Template

use of dev.jbang.catalog.Template in project jbang by jbangdev.

the class TestTemplate method testGetTemplateOne.

@Test
void testGetTemplateOne() throws IOException {
    Template template = Template.get("one");
    assertThat(template, notNullValue());
    assertThat(template.description, is("Template 1"));
    assertThat(template.fileRefs, aMapWithSize(3));
    assertThat(template.fileRefs.keySet(), hasItems("{basename}.java", "{basename}Test.java", "file2.java"));
    assertThat(template.fileRefs.values(), hasItems("file1_1.java", "file1_1_test.java", "file1_2.java"));
}
Also used : Template(dev.jbang.catalog.Template) Test(org.junit.jupiter.api.Test) BaseTest(dev.jbang.BaseTest)

Example 3 with Template

use of dev.jbang.catalog.Template in project jbang by jbangdev.

the class TestTemplate method testAddWithSingleComplexProperty.

@Test
void testAddWithSingleComplexProperty() throws IOException {
    Path cwd = Util.getCwd();
    Path testFile = cwd.resolve("test.java");
    Files.write(testFile, "// Test file".getBytes());
    assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)), is(false));
    JBang jbang = new JBang();
    new CommandLine(jbang).execute("template", "add", "-f", cwd.toString(), "--name=template-with-single-complex-property", "-d", "Description of the template", "-P", "new-test-key:This is a description for the property key:3.14", testFile.toString());
    assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)), is(true));
    Template name = Template.get("template-with-single-complex-property");
    assertThat(name.properties.entrySet(), hasItems(new AbstractMap.SimpleEntry<>("new-test-key", new TemplateProperty("This is a description for the property key", "3.14"))));
}
Also used : Path(java.nio.file.Path) CommandLine(picocli.CommandLine) TemplateProperty(dev.jbang.catalog.TemplateProperty) Template(dev.jbang.catalog.Template) Test(org.junit.jupiter.api.Test) BaseTest(dev.jbang.BaseTest)

Example 4 with Template

use of dev.jbang.catalog.Template in project jbang by jbangdev.

the class TestTemplate method testAddPreservesExistingCatalog.

@Test
void testAddPreservesExistingCatalog() throws IOException {
    Path cwd = Util.getCwd();
    Path testFile = cwd.resolve("test.java");
    Files.write(testFile, "// Test file".getBytes());
    JBang jbang = new JBang();
    new CommandLine(jbang).execute("template", "add", "-f", cwd.toString(), "--name=name", testFile.toString());
    Template one = Template.get("one");
    Template name = Template.get("name");
    assertThat(one.fileRefs, aMapWithSize(3));
    assertThat(one.fileRefs.keySet(), hasItems("{basename}.java", "{basename}Test.java", "file2.java"));
    assertThat(one.fileRefs.values(), hasItems("file1_1.java", "file1_1_test.java", "file1_2.java"));
    assertThat(name.fileRefs, aMapWithSize(1));
    assertThat(name.fileRefs.keySet(), hasItems("{basename}.java"));
    assertThat(name.fileRefs.values(), hasItems("test.java"));
}
Also used : Path(java.nio.file.Path) CommandLine(picocli.CommandLine) Template(dev.jbang.catalog.Template) Test(org.junit.jupiter.api.Test) BaseTest(dev.jbang.BaseTest)

Example 5 with Template

use of dev.jbang.catalog.Template in project jbang by jbangdev.

the class TestTemplate method testAddWithMultipleComplexProperties.

@Test
void testAddWithMultipleComplexProperties() throws IOException {
    Path cwd = Util.getCwd();
    Path testFile = cwd.resolve("test.java");
    Files.write(testFile, "// Test file".getBytes());
    assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)), is(false));
    JBang jbang = new JBang();
    new CommandLine(jbang).execute("template", "add", "-f", cwd.toString(), "--name=template-with-complex-properties", "-d", "Description of the template", "-P", "new-test-key:This is a description for the property key:3.14", "--property", "second-test-key:This is another description for the second property key:Non-Blocker", testFile.toString());
    assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)), is(true));
    Template name = Template.get("template-with-complex-properties");
    assertThat(name.properties.entrySet(), hasItems(new AbstractMap.SimpleEntry<>("new-test-key", new TemplateProperty("This is a description for the property key", "3.14")), new AbstractMap.SimpleEntry<>("second-test-key", new TemplateProperty("This is another description for the second property key", "Non-Blocker"))));
}
Also used : Path(java.nio.file.Path) CommandLine(picocli.CommandLine) TemplateProperty(dev.jbang.catalog.TemplateProperty) Template(dev.jbang.catalog.Template) Test(org.junit.jupiter.api.Test) BaseTest(dev.jbang.BaseTest)

Aggregations

BaseTest (dev.jbang.BaseTest)12 Template (dev.jbang.catalog.Template)12 Test (org.junit.jupiter.api.Test)12 Path (java.nio.file.Path)7 CommandLine (picocli.CommandLine)7 TemplateProperty (dev.jbang.catalog.TemplateProperty)4 Catalog (dev.jbang.catalog.Catalog)1