diff --git a/src/test/java/dev/jbang/cli/TestAlias.java b/src/test/java/dev/jbang/cli/TestAlias.java index 727bdab4c..71572b7db 100644 --- a/src/test/java/dev/jbang/cli/TestAlias.java +++ b/src/test/java/dev/jbang/cli/TestAlias.java @@ -543,4 +543,44 @@ void testGetAliasLoop() throws IOException { } + @Test + void testGetAliasFromLocalCatalog() throws IOException { + Path aliasesFile = jbangTempDir.resolve("aliases.json"); + Files.write(aliasesFile, aliases.getBytes()); + + String cat = "{\n" + + " \"catalogs\": {\n" + + " \"local\": {\n" + + " \"catalog-ref\": \"" + aliasesFile + "\"\n" + + " }\n" + + " }\n" + + "}"; + Path catFile = jbangTempDir.resolve(Catalog.JBANG_CATALOG_JSON); + Files.write(catFile, cat.getBytes()); + + assertThat(Alias.get("one@local"), notNullValue()); + assertThat(Alias.get("one"), notNullValue()); + } + + @Test + void testGetAliasFromImplicitCatalog() throws IOException { + Path catFile = jbangTempDir.resolve(Catalog.JBANG_CATALOG_JSON); + Util.deletePath(catFile, true); + Path aliasesFile = jbangTempDir.resolve("aliases.json"); + Files.write(aliasesFile, aliases.getBytes()); + + String cat = "{\n" + + " \"catalogs\": {\n" + + " \"local\": {\n" + + " \"catalog-ref\": \"" + aliasesFile + "\"\n" + + " }\n" + + " }\n" + + "}"; + Path implicitCatFile = Settings.getUserImplicitCatalogFile(); + Files.write(implicitCatFile, cat.getBytes()); + + assertThat(Alias.get("one@local"), notNullValue()); + assertThat(Alias.get("one"), nullValue()); + } + } diff --git a/src/test/java/dev/jbang/cli/TestTemplate.java b/src/test/java/dev/jbang/cli/TestTemplate.java index f30162a32..da10a248a 100644 --- a/src/test/java/dev/jbang/cli/TestTemplate.java +++ b/src/test/java/dev/jbang/cli/TestTemplate.java @@ -305,4 +305,44 @@ void testAddWithMultipleComplexProperties() throws IOException { entry("second-test-key", new TemplateProperty( "This is another description for the second property key", "Non-Blocker")))); } + + @Test + void testGetTemplateFromLocalCatalog() throws IOException { + Path templatesFile = jbangTempDir.resolve("templates.json"); + Files.write(templatesFile, templates.getBytes()); + + String cat = "{\n" + + " \"catalogs\": {\n" + + " \"local\": {\n" + + " \"catalog-ref\": \"" + templatesFile + "\"\n" + + " }\n" + + " }\n" + + "}"; + Path catFile = jbangTempDir.resolve(Catalog.JBANG_CATALOG_JSON); + Files.write(catFile, cat.getBytes()); + + assertThat(Template.get("one@local"), notNullValue()); + assertThat(Template.get("one"), notNullValue()); + } + + @Test + void testGetAliasFromImplicitCatalog() throws IOException { + Path catFile = jbangTempDir.resolve(Catalog.JBANG_CATALOG_JSON); + Util.deletePath(catFile, true); + Path templatesFile = jbangTempDir.resolve("templates.json"); + Files.write(templatesFile, templates.getBytes()); + + String cat = "{\n" + + " \"catalogs\": {\n" + + " \"local\": {\n" + + " \"catalog-ref\": \"" + templatesFile + "\"\n" + + " }\n" + + " }\n" + + "}"; + Path implicitCatFile = Settings.getUserImplicitCatalogFile(); + Files.write(implicitCatFile, cat.getBytes()); + + assertThat(Template.get("one@local"), notNullValue()); + assertThat(Template.get("one"), nullValue()); + } }