Skip to content

Commit

Permalink
Test key elements of compatibility of the devtools code with the plat…
Browse files Browse the repository at this point in the history
…form catalog
  • Loading branch information
ia3andy committed Oct 13, 2021
1 parent cf544ba commit 63d3557
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public Extension getExtension() {
return extension;
}

public Optional<ArtifactCoords> getBom() {
return ExtensionProcessor.getBom(extension);
}

public Optional<ArtifactCoords> getNonQuarkusBomOnly() {
return ExtensionProcessor.getNonQuarkusBomOnly(extension);
}

public String getBuiltWithQuarkusCore() {
return getBuiltWithQuarkusCore(extension);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package io.quarkus.platform.catalog;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.List;

import org.junit.jupiter.api.Test;

import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog;
import io.quarkus.devtools.project.CodestartResourceLoadersBuilder;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.platform.catalog.processor.CatalogProcessor;
import io.quarkus.platform.catalog.processor.ExtensionProcessor;
import io.quarkus.platform.catalog.processor.ProcessedCategory;
import io.quarkus.platform.descriptor.loader.json.ResourceLoader;
import io.quarkus.registry.Constants;
import io.quarkus.registry.ExtensionCatalogResolver;
import io.quarkus.registry.RegistryResolutionException;
import io.quarkus.registry.catalog.Extension;
import io.quarkus.registry.catalog.ExtensionCatalog;
import io.quarkus.registry.catalog.Platform;
import io.quarkus.registry.catalog.PlatformCatalog;
import io.quarkus.registry.catalog.PlatformRelease;
import io.quarkus.registry.catalog.PlatformStream;

public class CatalogCompatibilityTest {

private final ExtensionCatalogResolver catalogResolver = QuarkusProjectHelper.getCatalogResolver();

public CatalogCompatibilityTest() throws RegistryResolutionException {
}

@Test
public void testRegistryPlatformCatalog() throws RegistryResolutionException, IOException {
final PlatformCatalog platformCatalog = getRegistryPlatformCatalog();
assertThat(platformCatalog.getMetadata().get(Constants.LAST_UPDATED)).isNotNull();
testPlatformCatalog(catalogResolver, platformCatalog, "io.quarkus.platform");
}

static void testPlatformCatalog(ExtensionCatalogResolver catalogResolver, PlatformCatalog platformCatalog,
String expectedPlatformKey)
throws RegistryResolutionException, IOException {
assertThat(platformCatalog.getPlatforms())
.extracting(Platform::getPlatformKey)
.isNotEmpty()
.contains(expectedPlatformKey);
final Platform platform = platformCatalog.getPlatform(expectedPlatformKey);
assertThat(platform).isNotNull();
assertThat(platform.getStreams()).isNotEmpty();
for (PlatformStream s : platform.getStreams()) {
for (PlatformRelease r : s.getReleases()) {
checkPlatformRelease(catalogResolver, r);
}

}
}

private static void checkPlatformRelease(ExtensionCatalogResolver catalogResolver, PlatformRelease r)
throws RegistryResolutionException, IOException {
assertThat(r).isNotNull();
final ExtensionCatalog extensionCatalog = catalogResolver.resolveExtensionCatalog(r.getMemberBoms());
final CatalogProcessor processed = CatalogProcessor.of(extensionCatalog);
for (ProcessedCategory cat : processed.getProcessedCategoriesInOrder()) {
for (Extension e : cat.getSortedExtensions()) {
checkExtensionProcessor(e);
}
}
checkCodestarts(extensionCatalog, processed);
}

private static void checkCodestarts(ExtensionCatalog extensionCatalog, CatalogProcessor processed) throws IOException {
final List<ResourceLoader> codestartResourceLoaders = CodestartResourceLoadersBuilder
.getCodestartResourceLoaders(extensionCatalog);
final QuarkusCodestartCatalog quarkusCodestartCatalog = QuarkusCodestartCatalog
.fromExtensionsCatalog(extensionCatalog, codestartResourceLoaders);
assertThat(quarkusCodestartCatalog.getCodestarts()).isNotNull();
assertThat(processed.getCodestartArtifacts()).isNotEmpty();
}

private static void checkExtensionProcessor(Extension e) {
final ExtensionProcessor extensionProcessor = ExtensionProcessor.of(e);
assertThat(extensionProcessor.getCategories()).isNotNull();
assertThat(extensionProcessor.getExtendedKeywords()).isNotNull();
assertThat(extensionProcessor.getCodestartLanguages()).isNotNull();
assertThat(extensionProcessor.getTags()).isNotNull();
assertThat(extensionProcessor.getKeywords()).isNotNull();

// Just check that no exception is thrown
extensionProcessor.getBuiltWithQuarkusCore();
extensionProcessor.getGuide();
extensionProcessor.getCodestartArtifact();
extensionProcessor.getCodestartKind();
extensionProcessor.getCodestartName();
extensionProcessor.getShortName();
extensionProcessor.isUnlisted();
extensionProcessor.providesCode();
extensionProcessor.getBom();
extensionProcessor.getNonQuarkusBomOnly();
}

private PlatformCatalog getRegistryPlatformCatalog() throws RegistryResolutionException {
return catalogResolver.resolvePlatformCatalog();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.platform.catalog;

import java.io.IOException;

import org.junit.jupiter.api.Test;

import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.testing.PlatformAwareTestBase;
import io.quarkus.registry.ExtensionCatalogResolver;
import io.quarkus.registry.RegistryResolutionException;

public class SnapshotCatalogCompatibilityTest extends PlatformAwareTestBase {

@Test
void testSnapshotPlatformCatalog() throws RegistryResolutionException, IOException {
final ExtensionCatalogResolver catalogResolver = QuarkusProjectHelper.getCatalogResolver();
CatalogCompatibilityTest.testPlatformCatalog(catalogResolver, catalogResolver.resolvePlatformCatalog(), "io.quarkus");
}
}

0 comments on commit 63d3557

Please sign in to comment.