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"))));
}
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"));
}
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"))));
}
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"));
}
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"))));
}
Aggregations