Search in sources :

Example 1 with TemplateProperty

use of dev.jbang.catalog.TemplateProperty 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 TemplateProperty

use of dev.jbang.catalog.TemplateProperty 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 3 with TemplateProperty

use of dev.jbang.catalog.TemplateProperty 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)

Example 4 with TemplateProperty

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

the class TestTemplate method testAddWithSingleProperty.

@Test
void testAddWithSingleProperty() 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-property", "-d", "Description of the template", "-P", "new-test-key", testFile.toString());
    assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)), is(true));
    Template name = Template.get("template-with-single-property");
    assertThat(name.properties.entrySet(), hasItems(new AbstractMap.SimpleEntry<>("new-test-key", new TemplateProperty(null, null))));
}
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)4 Template (dev.jbang.catalog.Template)4 TemplateProperty (dev.jbang.catalog.TemplateProperty)4 Test (org.junit.jupiter.api.Test)4 Path (java.nio.file.Path)3 CommandLine (picocli.CommandLine)3