From b6324823c6d1e539525197c3796aa3f6d6232693 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Thu, 22 Apr 2021 13:36:59 +0200 Subject: [PATCH] Make devtools-testing test independent from platform --- .../devtools/codestarts/utils/NestedMaps.java | 14 +- .../codestarts/utils/NestedMapsTest.java | 38 +- .../src/test/resources/nested-map-1.yml | 2 + .../jbang/QuarkusJBangCodestartCatalog.java | 8 + .../quarkus/QuarkusCodestartCatalog.java | 18 +- .../testing/PlatformAwareTestBase.java | 16 +- .../devtools/testing/RegistryClientTest.java | 18 + .../codestarts/QuarkusCodestartTest.java | 12 +- .../QuarkusCodestartTestBuilder.java | 14 + ...arkusExtensionCodestartGenerationTest.java | 3 +- .../QuarkusJBangCodestartGenerationTest.java | 5 +- .../quarkus/FakeExtensionCatalog.java | 39 +++ .../quarkus/QuarkusCodestartCatalogTest.java | 6 +- .../QuarkusCodestartGenerationTest.java | 9 +- .../quarkus/RESTEasyCodestartTest.java | 4 + .../RESTEasyReactiveCodestartTest.java | 4 + .../quarkus/SpringWebCodestartTest.java | 4 + .../src/test/resources/fake-catalog.json | 325 ++++++++++++++++++ 18 files changed, 493 insertions(+), 46 deletions(-) create mode 100644 independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/RegistryClientTest.java create mode 100644 independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/FakeExtensionCatalog.java create mode 100644 independent-projects/tools/devtools-testing/src/test/resources/fake-catalog.json diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/utils/NestedMaps.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/utils/NestedMaps.java index b664ce3deba75c..535ed649dc1afb 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/utils/NestedMaps.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/utils/NestedMaps.java @@ -46,10 +46,22 @@ public static void deepMerge(Map left, Map right) { c.addAll((Collection) leftValue); c.addAll((Collection) rightValue); left.put(key, c); - } else { + } else if (rightValue instanceof Map) { + final Map map = new HashMap(); + deepMerge(map, (Map) rightValue); + left.put(key, map); + } else if (rightValue instanceof Collection) { + left.put(key, new LinkedHashSet((Collection) rightValue)); + } else if (rightValue instanceof Integer + || rightValue instanceof Boolean + || rightValue instanceof Float + || rightValue instanceof Long + || rightValue instanceof Double + || rightValue instanceof String) { // Override left.put(key, rightValue); } + // else ignore } } diff --git a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/utils/NestedMapsTest.java b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/utils/NestedMapsTest.java index f970487572e3ab..55b6a977ddb0e2 100644 --- a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/utils/NestedMapsTest.java +++ b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/utils/NestedMapsTest.java @@ -21,22 +21,6 @@ class NestedMapsTest { private static final Map NESTED_MAP_1 = readTestYamlMap("/nested-map-1.yml"); private static final Map NESTED_MAP_2 = readTestYamlMap("/nested-map-2.yml"); - @Test - void testGetValue() { - assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.baz")).hasValue("baz"); - assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.foo")).hasValue("bar"); - assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.bar.baz")).isEmpty(); - assertThat(NestedMaps.getValue(NESTED_MAP_1, "baa")).isEmpty(); - assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.bar.foo")).hasValue("bar"); - assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.bar.bar")).hasValue("foo"); - assertThat(NestedMaps.getValue(NESTED_MAP_1, "bar.foo.bar.foo")).hasValue("baz"); - assertThat((Collection) NestedMaps.getValue(NESTED_MAP_1, "list").get()).containsExactly("foo", "bar"); - assertThat(NestedMaps.getValue(NESTED_MAP_1, "bar.foo.bar")).hasValueSatisfying(v -> { - assertThat(v).isInstanceOf(Map.class); - assertThat((Map) v).hasFieldOrPropertyWithValue("foo", "baz"); - }); - } - @Test void testDeepMerge() { final HashMap target = new HashMap<>(); @@ -54,10 +38,30 @@ void testDeepMergeStream() { checkTargetMap(target); } + @Test + void testGetValue() { + assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.baz")).hasValue("baz"); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.int")).hasValue(1); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.bool")).hasValue(false); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.foo")).hasValue("bar"); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.bar.baz")).isEmpty(); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "baa")).isEmpty(); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.bar.foo")).hasValue("bar"); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "foo.bar.bar")).hasValue("foo"); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "bar.foo.bar.foo")).hasValue("baz"); + assertThat((Collection) NestedMaps.getValue(NESTED_MAP_1, "list").get()).containsExactly("foo", "bar"); + assertThat(NestedMaps.getValue(NESTED_MAP_1, "bar.foo.bar")).hasValueSatisfying(v -> { + assertThat(v).isInstanceOf(Map.class); + assertThat((Map) v).hasFieldOrPropertyWithValue("foo", "baz"); + }); + } + private void checkTargetMap(Map target) { assertThat(NestedMaps.getValue(target, "foo.baz")).hasValue("baz"); assertThat(NestedMaps.getValue(target, "foo.foo")).hasValue("bar"); assertThat(NestedMaps.getValue(target, "foo.bar")).hasValue("foo"); + assertThat(NestedMaps.getValue(target, "foo.int")).hasValue(1); + assertThat(NestedMaps.getValue(target, "foo.bool")).hasValue(false); assertThat(NestedMaps.getValue(target, "foo.bar.baz")).isEmpty(); assertThat(NestedMaps.getValue(target, "baz")).hasValue("bar"); @@ -73,6 +77,8 @@ void testUnflatten() { data.put("foo.baz", "baz"); data.put("foo.foo", "bar"); data.put("foo.bar", "foo"); + data.put("foo.int", 1); + data.put("foo.bool", false); data.put("baz", "bar"); data.put("bar.foo.bar.foo", "bar"); data.put("bar.foo.bar.baz", "foo"); diff --git a/independent-projects/tools/codestarts/src/test/resources/nested-map-1.yml b/independent-projects/tools/codestarts/src/test/resources/nested-map-1.yml index 7e73e29f876f25..5aa33972efb4e4 100644 --- a/independent-projects/tools/codestarts/src/test/resources/nested-map-1.yml +++ b/independent-projects/tools/codestarts/src/test/resources/nested-map-1.yml @@ -2,6 +2,8 @@ foo: baz: baz foo: bar + int: 1 + bool: false bar: foo: bar bar: foo diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartCatalog.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartCatalog.java index cabd9b483ce8ec..ddac5bca8b347a 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartCatalog.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartCatalog.java @@ -1,6 +1,7 @@ package io.quarkus.devtools.codestarts.jbang; import static io.quarkus.devtools.codestarts.CodestartResourceLoader.loadCodestartsFromResources; +import static io.quarkus.devtools.project.QuarkusProjectHelper.getBaseCodestartResourceLoaders; import io.quarkus.devtools.codestarts.Codestart; import io.quarkus.devtools.codestarts.DataKey; @@ -46,6 +47,13 @@ private QuarkusJBangCodestartCatalog(Collection codestarts) { super(codestarts); } + public static QuarkusJBangCodestartCatalog fromBaseCodestartsResources() + throws IOException { + final Map codestarts = loadCodestartsFromResources(getBaseCodestartResourceLoaders(), + QUARKUS_JBANG_CODESTARTS_DIR); + return new QuarkusJBangCodestartCatalog(codestarts.values()); + } + public static QuarkusJBangCodestartCatalog fromResourceLoaders(List resourceLoaders) throws IOException { final Map codestarts = loadCodestartsFromResources(resourceLoaders, QUARKUS_JBANG_CODESTARTS_DIR); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalog.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalog.java index 6ffc8b3ae17696..513f159fffa6b2 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalog.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalog.java @@ -3,6 +3,7 @@ import static io.quarkus.devtools.codestarts.CodestartResourceLoader.loadCodestartsFromResources; import static io.quarkus.devtools.codestarts.core.CodestartCatalogs.findLanguageName; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.AppContent.CODE; +import static io.quarkus.devtools.project.QuarkusProjectHelper.getBaseCodestartResourceLoaders; import static io.quarkus.devtools.project.QuarkusProjectHelper.getCodestartResourceLoaders; import static io.quarkus.platform.catalog.processor.ExtensionProcessor.getCodestartName; import static io.quarkus.platform.catalog.processor.ExtensionProcessor.getGuide; @@ -23,6 +24,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -76,7 +78,19 @@ private QuarkusCodestartCatalog(Collection codestarts, this.extensionsMapping = extensionsMapping; } - public static QuarkusCodestartCatalog fromQuarkusPlatformDescriptorAndDirectories( + public static QuarkusCodestartCatalog fromBaseCodestartsResources(Map extensionsMapping) + throws IOException { + final Map codestarts = loadCodestartsFromResources(getBaseCodestartResourceLoaders(), + QUARKUS_CODESTARTS_DIR); + return new QuarkusCodestartCatalog(codestarts.values(), extensionsMapping); + } + + public static QuarkusCodestartCatalog fromBaseCodestartsResources() + throws IOException { + return fromBaseCodestartsResources(Collections.emptyMap()); + } + + public static QuarkusCodestartCatalog fromExtensionsCatalogAndDirectories( ExtensionCatalog catalog, Collection directories) throws IOException { final Map codestarts = loadCodestartsFromResources(getCodestartResourceLoaders(catalog), @@ -220,7 +234,7 @@ public static boolean isExample(Codestart codestart) { return codestart.getType() == CodestartType.CODE && codestart.containsTag(Tag.EXAMPLE.key()); } - private static Map buildExtensionsMapping( + public static Map buildExtensionsMapping( Collection extensions) { final Map map = new HashMap<>(extensions.size()); extensions.forEach(e -> { diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/PlatformAwareTestBase.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/PlatformAwareTestBase.java index b182a3f11e5f65..0d00441aac728f 100644 --- a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/PlatformAwareTestBase.java +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/PlatformAwareTestBase.java @@ -6,24 +6,16 @@ import io.quarkus.registry.catalog.ExtensionCatalog; import java.util.List; import java.util.Properties; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.extension.RegisterExtension; public class PlatformAwareTestBase { + @RegisterExtension + static final RegistryClientTest registryClientTest = new RegistryClientTest(); + private ExtensionCatalog catalog; private Properties quarkusProps; - @BeforeAll - static void enableDevToolsTestConfig() { - RegistryClientTestHelper.enableRegistryClientTestConfig(); - } - - @AfterAll - static void disableDevToolsTestConfig() { - RegistryClientTestHelper.disableRegistryClientTestConfig(); - } - protected List getCodestartsResourceLoaders() { return QuarkusProjectHelper.getCodestartResourceLoaders(getExtensionsCatalog()); } diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/RegistryClientTest.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/RegistryClientTest.java new file mode 100644 index 00000000000000..a1e2fb82ff6abd --- /dev/null +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/RegistryClientTest.java @@ -0,0 +1,18 @@ +package io.quarkus.devtools.testing; + +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class RegistryClientTest implements BeforeAllCallback, AfterAllCallback { + + @Override + public void beforeAll(ExtensionContext extensionContext) throws Exception { + RegistryClientTestHelper.enableRegistryClientTestConfig(); + } + + @Override + public void afterAll(ExtensionContext extensionContext) throws Exception { + RegistryClientTestHelper.disableRegistryClientTestConfig(); + } +} diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java index e263d0b178617e..96aa297597c12f 100644 --- a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java @@ -47,6 +47,7 @@ public class QuarkusCodestartTest implements BeforeAllCallback, AfterAllCallback private final BuildTool buildTool; private final Set hasGeneratedProjectsWithMockedData = new HashSet<>(); private final Set hasGeneratedProjectsWithRealData = new HashSet<>(); + private final boolean enableRegistryClient; private Path targetDir; private ExtensionCatalog extensionCatalog; private QuarkusCodestartCatalog quarkusCodestartCatalog; @@ -55,6 +56,9 @@ public class QuarkusCodestartTest implements BeforeAllCallback, AfterAllCallback this.codestarts = builder.codestarts; this.languages = builder.languages; this.buildTool = builder.buildTool; + this.quarkusCodestartCatalog = builder.quarkusCodestartCatalog; + this.extensionCatalog = builder.extensionCatalog; + this.enableRegistryClient = builder.extensionCatalog == null; this.data = builder.data; } @@ -64,7 +68,9 @@ public static QuarkusCodestartTestBuilder builder() { @Override public void beforeAll(ExtensionContext extensionContext) throws Exception { - enableRegistryClientTestConfig(); + if (enableRegistryClient) { + enableRegistryClientTestConfig(); + } targetDir = Paths.get("target/quarkus-codestart-test/" + getTestId()); SnapshotTesting.deleteTestDirectory(targetDir.toFile()); } @@ -200,7 +206,9 @@ private Path getProjectWithMockedDataDir(Language language) throws IOException { @Override public void afterAll(ExtensionContext extensionContext) throws Exception { - disableRegistryClientTestConfig(); + if (enableRegistryClient) { + disableRegistryClientTestConfig(); + } } protected List getCodestartsResourceLoaders() { diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTestBuilder.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTestBuilder.java index 40004b3cae59f2..66ca512ad0e143 100644 --- a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTestBuilder.java +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTestBuilder.java @@ -1,8 +1,10 @@ package io.quarkus.devtools.testing.codestarts; import io.quarkus.devtools.codestarts.DataKey; +import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog; import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language; import io.quarkus.devtools.project.BuildTool; +import io.quarkus.registry.catalog.ExtensionCatalog; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -14,6 +16,8 @@ public class QuarkusCodestartTestBuilder { BuildTool buildTool; Set codestarts; Set languages; + QuarkusCodestartCatalog quarkusCodestartCatalog; + ExtensionCatalog extensionCatalog; public QuarkusCodestartTestBuilder codestarts(String... codestarts) { this.codestarts = new HashSet<>(Arrays.asList(codestarts)); @@ -40,6 +44,16 @@ public QuarkusCodestartTestBuilder putData(DataKey key, Object value) { return this; } + public QuarkusCodestartTestBuilder quarkusCodestartCatalog(QuarkusCodestartCatalog quarkusCodestartCatalog) { + this.quarkusCodestartCatalog = quarkusCodestartCatalog; + return this; + } + + public QuarkusCodestartTestBuilder extensionCatalog(ExtensionCatalog extensionCatalog) { + this.extensionCatalog = extensionCatalog; + return this; + } + public QuarkusCodestartTest build() { return new QuarkusCodestartTest(this); } diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/extension/QuarkusExtensionCodestartGenerationTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/extension/QuarkusExtensionCodestartGenerationTest.java index 4138384b2f1b70..5a2e6f4eca0e0d 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/extension/QuarkusExtensionCodestartGenerationTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/extension/QuarkusExtensionCodestartGenerationTest.java @@ -3,7 +3,6 @@ import static io.quarkus.devtools.testing.SnapshotTesting.assertThatDirectoryTreeMatchSnapshots; import io.quarkus.devtools.codestarts.extension.QuarkusExtensionCodestartCatalog.QuarkusExtensionData; -import io.quarkus.devtools.testing.PlatformAwareTestBase; import io.quarkus.devtools.testing.SnapshotTesting; import java.io.IOException; import java.nio.file.Path; @@ -12,7 +11,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; -class QuarkusExtensionCodestartGenerationTest extends PlatformAwareTestBase { +class QuarkusExtensionCodestartGenerationTest { private static final Path testDirPath = Paths.get("target/extension-codestart-gen-test"); diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartGenerationTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartGenerationTest.java index fcbbf385b7c056..24b0f63139babf 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartGenerationTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/jbang/QuarkusJBangCodestartGenerationTest.java @@ -6,7 +6,6 @@ import static io.quarkus.devtools.testing.SnapshotTesting.assertThatDirectoryTreeMatchSnapshots; import static io.quarkus.devtools.testing.SnapshotTesting.assertThatMatchSnapshot; -import io.quarkus.devtools.testing.PlatformAwareTestBase; import io.quarkus.devtools.testing.SnapshotTesting; import java.io.IOException; import java.nio.file.Path; @@ -15,7 +14,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; -class QuarkusJBangCodestartGenerationTest extends PlatformAwareTestBase { +class QuarkusJBangCodestartGenerationTest { private static final Path testDirPath = Paths.get("target/jbang-codestart-gen-test"); @@ -52,7 +51,7 @@ void generatePicocliProject(TestInfo testInfo) throws Throwable { } private QuarkusJBangCodestartCatalog getCatalog() throws IOException { - return QuarkusJBangCodestartCatalog.fromResourceLoaders(getCodestartsResourceLoaders()); + return QuarkusJBangCodestartCatalog.fromBaseCodestartsResources(); } } diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/FakeExtensionCatalog.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/FakeExtensionCatalog.java new file mode 100644 index 00000000000000..6b35bfc923e22d --- /dev/null +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/FakeExtensionCatalog.java @@ -0,0 +1,39 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import io.quarkus.registry.catalog.ExtensionCatalog; +import io.quarkus.registry.catalog.json.JsonCatalogMapperHelper; +import io.quarkus.registry.catalog.json.JsonExtensionCatalog; +import java.io.IOException; +import java.io.InputStream; +import java.io.UncheckedIOException; + +public final class FakeExtensionCatalog { + + private static final String FAKE_EXTENSION_CATALOG_PATH = "/fake-catalog.json"; + public static final ExtensionCatalog FAKE_EXTENSION_CATALOG = getFakeExtensionCatalog(); + public static final QuarkusCodestartCatalog FAKE_QUARKUS_CODESTART_CATALOG = getQuarkusCodestartCatalog(); + + private FakeExtensionCatalog() { + } + + private static QuarkusCodestartCatalog getQuarkusCodestartCatalog() { + try { + return QuarkusCodestartCatalog.fromBaseCodestartsResources( + QuarkusCodestartCatalog.buildExtensionsMapping(FAKE_EXTENSION_CATALOG.getExtensions())); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private static ExtensionCatalog getFakeExtensionCatalog() { + InputStream inputString = FakeExtensionCatalog.class.getResourceAsStream(FAKE_EXTENSION_CATALOG_PATH); + if (inputString == null) { + throw new IllegalStateException("Failed to locate " + FAKE_EXTENSION_CATALOG_PATH + " on the classpath"); + } + try { + return JsonCatalogMapperHelper.deserialize(inputString, JsonExtensionCatalog.class); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } +} diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalogTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalogTest.java index 4d48844378eec0..e918f3f2774d44 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalogTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartCatalogTest.java @@ -1,12 +1,12 @@ package io.quarkus.devtools.codestarts.quarkus; +import static io.quarkus.devtools.codestarts.quarkus.FakeExtensionCatalog.FAKE_QUARKUS_CODESTART_CATALOG; import static org.assertj.core.api.Assertions.assertThat; import io.quarkus.devtools.codestarts.Codestart; import io.quarkus.devtools.codestarts.CodestartProjectDefinition; import io.quarkus.devtools.codestarts.CodestartType; import io.quarkus.devtools.project.BuildTool; -import io.quarkus.devtools.testing.PlatformAwareTestBase; import io.quarkus.devtools.testing.SnapshotTesting; import io.quarkus.maven.ArtifactKey; import java.io.IOException; @@ -15,7 +15,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class QuarkusCodestartCatalogTest extends PlatformAwareTestBase { +class QuarkusCodestartCatalogTest { private final Path projectPath = Paths.get("target/quarkus-codestart-catalog-test"); @@ -140,7 +140,7 @@ void prepareProjectTestResteasy() throws IOException { } private QuarkusCodestartCatalog getCatalog() throws IOException { - return QuarkusCodestartCatalog.fromExtensionsCatalog(getExtensionsCatalog(), getCodestartsResourceLoaders()); + return FAKE_QUARKUS_CODESTART_CATALOG; } } diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java index 7ae5b598208523..4a174f8b91c2a5 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java @@ -1,5 +1,6 @@ package io.quarkus.devtools.codestarts.quarkus; +import static io.quarkus.devtools.codestarts.quarkus.FakeExtensionCatalog.FAKE_QUARKUS_CODESTART_CATALOG; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.PROJECT_PACKAGE_NAME; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.RESTEASY_CODESTART_RESOURCE_CLASS_NAME; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.RESTEASY_CODESTART_RESOURCE_PATH; @@ -8,12 +9,10 @@ import static org.assertj.core.api.Assertions.assertThat; import io.quarkus.devtools.project.BuildTool; -import io.quarkus.devtools.testing.PlatformAwareTestBase; import io.quarkus.devtools.testing.SnapshotTesting; import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTesting; import io.quarkus.maven.ArtifactCoords; import io.quarkus.maven.ArtifactKey; -import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; @@ -22,7 +21,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; -class QuarkusCodestartGenerationTest extends PlatformAwareTestBase { +class QuarkusCodestartGenerationTest { private static final Path testDirPath = Paths.get("target/quarkus-codestart-gen-test"); @@ -364,8 +363,8 @@ private void checkGradleWithKotlinDsl(Path projectDir) { .satisfies(checkContains("rootProject.name=\"test-codestart\"")); } - private QuarkusCodestartCatalog getCatalog() throws IOException { - return QuarkusCodestartCatalog.fromExtensionsCatalog(getExtensionsCatalog(), getCodestartsResourceLoaders()); + private QuarkusCodestartCatalog getCatalog() { + return FAKE_QUARKUS_CODESTART_CATALOG; } } diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTEasyCodestartTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTEasyCodestartTest.java index c75a848b601d75..67d8e57a77501a 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTEasyCodestartTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTEasyCodestartTest.java @@ -1,5 +1,7 @@ package io.quarkus.devtools.codestarts.quarkus; +import static io.quarkus.devtools.codestarts.quarkus.FakeExtensionCatalog.FAKE_EXTENSION_CATALOG; +import static io.quarkus.devtools.codestarts.quarkus.FakeExtensionCatalog.FAKE_QUARKUS_CODESTART_CATALOG; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.SCALA; @@ -12,6 +14,8 @@ class RESTEasyCodestartTest { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .quarkusCodestartCatalog(FAKE_QUARKUS_CODESTART_CATALOG) + .extensionCatalog(FAKE_EXTENSION_CATALOG) .codestarts("resteasy") .languages(JAVA, KOTLIN, SCALA) .build(); diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTEasyReactiveCodestartTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTEasyReactiveCodestartTest.java index aa5cbd29b07e5c..43c8e4dc2ae8db 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTEasyReactiveCodestartTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTEasyReactiveCodestartTest.java @@ -1,5 +1,7 @@ package io.quarkus.devtools.codestarts.quarkus; +import static io.quarkus.devtools.codestarts.quarkus.FakeExtensionCatalog.FAKE_EXTENSION_CATALOG; +import static io.quarkus.devtools.codestarts.quarkus.FakeExtensionCatalog.FAKE_QUARKUS_CODESTART_CATALOG; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.SCALA; @@ -12,6 +14,8 @@ class RESTEasyReactiveCodestartTest { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .quarkusCodestartCatalog(FAKE_QUARKUS_CODESTART_CATALOG) + .extensionCatalog(FAKE_EXTENSION_CATALOG) .codestarts("resteasy-reactive") .languages(JAVA, KOTLIN, SCALA) .build(); diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/SpringWebCodestartTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/SpringWebCodestartTest.java index 88441b439ae614..9c6bf6c96952c9 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/SpringWebCodestartTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/SpringWebCodestartTest.java @@ -1,5 +1,7 @@ package io.quarkus.devtools.codestarts.quarkus; +import static io.quarkus.devtools.codestarts.quarkus.FakeExtensionCatalog.FAKE_EXTENSION_CATALOG; +import static io.quarkus.devtools.codestarts.quarkus.FakeExtensionCatalog.FAKE_QUARKUS_CODESTART_CATALOG; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN; import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.SCALA; @@ -12,6 +14,8 @@ class SpringWebCodestartTest { @RegisterExtension public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .quarkusCodestartCatalog(FAKE_QUARKUS_CODESTART_CATALOG) + .extensionCatalog(FAKE_EXTENSION_CATALOG) .codestarts("spring-web") .languages(JAVA, KOTLIN, SCALA) .build(); diff --git a/independent-projects/tools/devtools-testing/src/test/resources/fake-catalog.json b/independent-projects/tools/devtools-testing/src/test/resources/fake-catalog.json new file mode 100644 index 00000000000000..801fd9dea3fae7 --- /dev/null +++ b/independent-projects/tools/devtools-testing/src/test/resources/fake-catalog.json @@ -0,0 +1,325 @@ +{ + "id": "io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT", + "platform": true, + "bom": "io.quarkus:quarkus-bom::pom:999-SNAPSHOT", + "derived-from": [], + "extensions": [ + { + "name": "RESTEasy Reactive", + "description": "Reactive implementation of JAX-RS with additional features. This extension is not compatible with the quarkus-resteasy extension, or any of the extensions that depend on it.", + "metadata": { + "short-name": "resteasy-reactive", + "keywords": [ + "jaxrs", + "web", + "rest" + ], + "categories": [ + "web", + "reactive" + ], + "status": "experimental", + "codestart": { + "name": "resteasy-reactive", + "languages": [ + "java", + "kotlin", + "scala" + ], + "artifact": "io.quarkus:quarkus-descriptor-json" + }, + "built-with-quarkus-core": "999-SNAPSHOT" + }, + "artifact": "io.quarkus:quarkus-resteasy-reactive::jar:999-SNAPSHOT", + "origins": [ + "io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT" + ] + }, + { + "name": "YAML Configuration", + "description": "Use YAML to configure your Quarkus application", + "metadata": { + "keywords": [ + "config", + "configuration", + "yaml" + ], + "categories": [ + "core" + ], + "status": "stable", + "guide": "https://quarkus.io/guides/config#yaml", + "codestart": { + "name": "config-yaml", + "kind": "core", + "languages": [ + "java", + "kotlin" + ], + "artifact": "io.quarkus:quarkus-descriptor-json" + }, + "built-with-quarkus-core": "999-SNAPSHOT" + }, + "artifact": "io.quarkus:quarkus-config-yaml::jar:999-SNAPSHOT", + "origins": [ + "io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT" + ] + }, + { + "name": "RESTEasy JAX-RS", + "description": "REST endpoint framework implementing JAX-RS and more", + "metadata": { + "short-name": "jax-rs", + "keywords": [ + "resteasy", + "jaxrs", + "web", + "rest" + ], + "guide": "https://quarkus.io/guides/rest-json", + "categories": [ + "web" + ], + "status": "stable", + "codestart": { + "name": "resteasy", + "languages": [ + "java", + "kotlin", + "scala" + ], + "artifact": "io.quarkus:quarkus-descriptor-json" + }, + "built-with-quarkus-core": "999-SNAPSHOT" + }, + "artifact": "io.quarkus:quarkus-resteasy::jar:999-SNAPSHOT", + "origins": [ + "io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT" + ] + }, + { + "name": "Quarkus Extension for Spring Web API", + "description": "Use Spring Web annotations to create your REST services", + "metadata": { + "keywords": [ + "spring-web", + "spring" + ], + "guide": "https://quarkus.io/guides/spring-web", + "categories": [ + "compatibility" + ], + "status": "preview", + "codestart": { + "name": "spring-web", + "languages": [ + "java", + "kotlin", + "scala" + ], + "artifact": "io.quarkus:quarkus-descriptor-json" + }, + "built-with-quarkus-core": "999-SNAPSHOT" + }, + "artifact": "io.quarkus:quarkus-spring-web::jar:999-SNAPSHOT", + "origins": [ + "io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT" + ] + }, + { + "name": "Kotlin", + "description": "Write your services in Kotlin", + "metadata": { + "keywords": [ + "kotlin" + ], + "guide": "https://quarkus.io/guides/kotlin", + "categories": [ + "alt-languages" + ], + "status": "preview", + "codestart": { + "name": "kotlin", + "kind": "core", + "artifact": "io.quarkus:quarkus-descriptor-json" + }, + "built-with-quarkus-core": "999-SNAPSHOT" + }, + "artifact": "io.quarkus:quarkus-kotlin::jar:999-SNAPSHOT", + "origins": [ + "io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT" + ] + }, + { + "name": "Scala", + "description": "Write your services in Scala", + "metadata": { + "keywords": [ + "scala" + ], + "categories": [ + "alt-languages" + ], + "status": "preview", + "codestart": { + "name": "scala", + "kind": "core", + "artifact": "io.quarkus:quarkus-descriptor-json" + }, + "built-with-quarkus-core": "999-SNAPSHOT" + }, + "artifact": "io.quarkus:quarkus-scala::jar:999-SNAPSHOT", + "origins": [ + "io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT" + ] + } + ], + "categories": [ + { + "id": "web", + "name": "Web", + "description": "Everything you need for REST endpoints, HTTP and web formats like JSON", + "metadata": { + "pinned": [ + "io.quarkus:quarkus-resteasy", + "io.quarkus:quarkus-resteasy-jackson", + "io.quarkus:quarkus-resteasy-jsonb" + ] + } + }, + { + "id": "data", + "name": "Data", + "description": "Accessing and managing your data (RDBMS, NoSQL, caching, transaction management, etc)", + "metadata": { + "pinned": [ + "io.quarkus:quarkus-hibernate-orm", + "io.quarkus:quarkus-hibernate-orm-panache", + "io.quarkus:quarkus-jdbc-postgresql", + "io.quarkus:quarkus-jdbc-mariadb", + "io.quarkus:quarkus-jdbc-mysql", + "io.quarkus:quarkus-jdbc-mssql", + "io.quarkus:quarkus-jdbc-db2", + "io.quarkus:quarkus-jdbc-h2", + "io.quarkus:quarkus-jdbc-derby" + ] + } + }, + { + "id": "messaging", + "name": "Messaging", + "description": "Send and receives message to various messaging systems (AMQP, KAfka etc)", + "metadata": { + "pinned": [ + "io.quarkus:quarkus-smallrye-reactive-messaging", + "io.quarkus:quarkus-smallrye-reactive-messaging-amqp", + "io.quarkus:quarkus-smallrye-reactive-messaging-kafka", + "io.quarkus:quarkus-smallrye-reactive-messaging-mqtt" + ] + } + }, + { + "id": "core", + "name": "Core", + "description": "Core Quarkus components: engine, logging, etc.", + "metadata": { + "pinned": [ + "io.quarkus:quarkus-config-yaml", + "io.quarkus:quarkus-logging-json" + ] + } + }, + { + "id": "reactive", + "name": "Reactive", + "description": "Non blocking stack and connectors", + "metadata": { + "pinned": [ + "io.quarkus:quarkus-vertx", + "io.quarkus:quarkus-mutiny" + ] + } + }, + { + "id": "cloud", + "name": "Cloud", + "description": "Useful for Cloud Native deployments platforms like Kubernetes and cloud providers", + "metadata": { + "pinned": [ + "io.quarkus:quarkus-kubernetes", + "io.quarkus:quarkus-openshift", + "io.quarkus:quarkus-smallrye-health", + "io.quarkus:quarkus-smallrye-fault-tolerance" + ] + } + }, + { + "id": "observability", + "name": "Observability", + "description": "Metrics, tracing, etc", + "metadata": {} + }, + { + "id": "security", + "name": "Security", + "description": "Everything you need to secure your application", + "metadata": { + "pinned": [ + "io.quarkus:quarkus-oidc", + "io.quarkus:quarkus-smallrye-jwt" + ] + } + }, + { + "id": "serialization", + "name": "Serialization", + "description": "Serializing and deserializing various formats", + "metadata": {} + }, + { + "id": "miscellaneous", + "name": "Miscellaneous", + "description": "Mixed bag of good stuff", + "metadata": {} + }, + { + "id": "compatibility", + "name": "Compatibility", + "description": "Support for alternative programming models on Quarkus", + "metadata": {} + }, + { + "id": "alt-languages", + "name": "Alternative languages", + "description": "Support for other JVM based languages", + "metadata": {} + } + ], + "metadata": { + "project": { + "properties": { + "doc-root": "https://quarkus.io", + "rest-assured-version": "4.3.2", + "compiler-plugin-version": "3.8.1", + "surefire-plugin-version": "3.0.0-M5", + "kotlin-version": "1.4.31", + "scala-version": "2.12.13", + "scala-plugin-version": "4.4.0", + "quarkus-core-version": "999-SNAPSHOT", + "maven-plugin-groupId": "io.quarkus", + "maven-plugin-artifactId": "quarkus-maven-plugin", + "maven-plugin-version": "999-SNAPSHOT", + "gradle-plugin-id": "io.quarkus", + "gradle-plugin-version": "999-SNAPSHOT", + "supported-maven-versions": "[3.6.2,)", + "proposed-maven-version": "3.6.3", + "maven-wrapper-version": "0.7.7", + "gradle-wrapper-version": "6.8.3" + } + }, + "codestarts-artifacts": [ + "io.quarkus:quarkus-platform-descriptor-json::jar:999-SNAPSHOT" + ] + }, + "quarkus-core-version": "999-SNAPSHOT" +} \ No newline at end of file