From f4c96b720eba2ffe494f8feb1d0f773d58fb9089 Mon Sep 17 00:00:00 2001 From: Tako Schotanus Date: Wed, 16 Mar 2022 23:26:54 +0100 Subject: [PATCH] test: added tests for issue #1309 --- src/test/java/dev/jbang/cli/TestAlias.java | 40 +++++++++++++++++++ src/test/java/dev/jbang/cli/TestTemplate.java | 40 +++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/test/java/dev/jbang/cli/TestAlias.java b/src/test/java/dev/jbang/cli/TestAlias.java index 861382978..867668d24 100644 --- a/src/test/java/dev/jbang/cli/TestAlias.java +++ b/src/test/java/dev/jbang/cli/TestAlias.java @@ -355,4 +355,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 fd9b5fccd..18dda3c30 100644 --- a/src/test/java/dev/jbang/cli/TestTemplate.java +++ b/src/test/java/dev/jbang/cli/TestTemplate.java @@ -283,4 +283,44 @@ void testAddWithMultipleComplexProperties() throws IOException { new AbstractMap.SimpleEntry<>("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()); + } }