-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Non-core platform member dependency analysis tests
- Loading branch information
1 parent
013a56a
commit 70a7e35
Showing
4 changed files
with
260 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
domino/api/src/test/java/io/quarkus/domino/NonCorePlatformMemberDependenciesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
package io.quarkus.domino; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import io.quarkus.bom.decomposer.ReleaseId; | ||
import io.quarkus.bom.decomposer.ReleaseIdFactory; | ||
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; | ||
import io.quarkus.domino.test.repo.TestArtifactRepo; | ||
import io.quarkus.domino.test.repo.TestProject; | ||
import io.quarkus.maven.dependency.ArtifactCoords; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
public class NonCorePlatformMemberDependenciesTest { | ||
|
||
@TempDir | ||
static Path testRepoDir; | ||
static MavenArtifactResolver artifactResolver; | ||
static Map<ReleaseId, Consumer<ReleaseRepo>> releaseAssertions; | ||
|
||
@BeforeAll | ||
static void prepareRepo() { | ||
var testRepo = TestArtifactRepo.of(testRepoDir); | ||
artifactResolver = testRepo.getArtifactResolver(); | ||
|
||
var byteUtilsProject = TestProject.of("org.bytes", "1.0") | ||
.setRepoUrl("https://bytes.org/code") | ||
.setTag("1.0"); | ||
var byteUtilsLib = byteUtilsProject.createMainModule("byte-utils"); | ||
|
||
var commonsIoProject = TestProject.of("org.commons.io", "1.0") | ||
.setRepoUrl("https://commons.org/code/io") | ||
.setTag("1.0"); | ||
var commonsIoLib = commonsIoProject.createMainModule("commons-io") | ||
.addDependency(byteUtilsLib); | ||
|
||
var quarkusProject = TestProject.of("io.quarkus", "1.0") | ||
.setRepoUrl("https://quarkus.io/code") | ||
.setTag("1.0"); | ||
var quarkusParent = quarkusProject.createParentPom("quarkus-parent"); | ||
var quarkusBom = quarkusParent.addPomModule("quarkus-bom") | ||
.addVersionConstraint("quarkus-core"); | ||
var quarkusBuildParent = quarkusParent.addPomModule("quarkus-build-parent") | ||
.importBom(quarkusBom); | ||
var quarkusCore = quarkusBuildParent.addModule("quarkus-core") | ||
.addDependency(commonsIoLib); | ||
|
||
var filesLibProject = TestProject.of("org.files", "1.0") | ||
.setRepoUrl("https://files.org/code") | ||
.setTag("1.0"); | ||
var filesLib = filesLibProject.createMainModule("file-utils"); | ||
|
||
var xmlLibProject = TestProject.of("org.xml", "1.0") | ||
.setRepoUrl("https://xml.org/code") | ||
.setTag("1.0"); | ||
var xmlLib = xmlLibProject.createMainModule("xml-lib") | ||
.addDependency(filesLib); | ||
|
||
var camelProject = TestProject.of("org.camel", "1.0") | ||
.setRepoUrl("https://camel.org/code") | ||
.setTag("1.0"); | ||
var camelParent = camelProject.createParentPom("camel-parent"); | ||
var camelBom = camelParent.addPomModule("camel-bom") | ||
.addVersionConstraint("camel-core") | ||
.addVersionConstraint("camel-xml-lib") | ||
.addVersionConstraint(xmlLib) | ||
.addVersionConstraint(commonsIoLib); | ||
var camelBuildParent = camelParent.addPomModule("camel-build-parent") | ||
.importBom(camelBom); | ||
var camelCore = camelBuildParent.addModule("camel-core") | ||
.addDependency(quarkusCore); | ||
var camelXmlLib = camelBuildParent.addModule("camel-xml-lib") | ||
.addManagedDependency(camelCore) | ||
.addManagedDependency(xmlLib); | ||
|
||
testRepo.install(quarkusProject) | ||
.install(camelProject) | ||
.install(filesLibProject) | ||
.install(xmlLibProject) | ||
.install(commonsIoProject) | ||
.install(byteUtilsProject); | ||
|
||
releaseAssertions = Map.<ReleaseId, Consumer<ReleaseRepo>> of( | ||
ReleaseIdFactory.forScmAndTag("https://quarkus.io/code", "1.0"), | ||
release -> { | ||
assertThat(release.id()).isEqualTo(ReleaseIdFactory.forScmAndTag("https://quarkus.io/code", "1.0")); | ||
assertThat(release.getArtifacts()).hasSize(4); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.pom("io.quarkus", "quarkus-parent", "1.0")); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.pom("io.quarkus", "quarkus-bom", "1.0")); | ||
assertThat(release.getArtifacts()) | ||
.containsKey(ArtifactCoords.pom("io.quarkus", "quarkus-build-parent", "1.0")); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.jar("io.quarkus", "quarkus-core", "1.0")); | ||
assertThat(release.getDependencies()).hasSize(1); | ||
}, | ||
ReleaseIdFactory.forScmAndTag("https://camel.org/code", "1.0"), | ||
release -> { | ||
assertThat(release.id()).isEqualTo(ReleaseIdFactory.forScmAndTag("https://camel.org/code", "1.0")); | ||
assertThat(release.getArtifacts()).hasSize(5); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.pom("org.camel", "camel-parent", "1.0")); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.pom("org.camel", "camel-bom", "1.0")); | ||
assertThat(release.getArtifacts()) | ||
.containsKey(ArtifactCoords.pom("org.camel", "camel-build-parent", "1.0")); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.jar("org.camel", "camel-core", "1.0")); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.jar("org.camel", "camel-xml-lib", "1.0")); | ||
assertThat(release.getDependencies()).hasSize(2); | ||
}, | ||
ReleaseIdFactory.forScmAndTag("https://xml.org/code", "1.0"), | ||
release -> { | ||
assertThat(release.id()).isEqualTo(ReleaseIdFactory.forScmAndTag("https://xml.org/code", "1.0")); | ||
assertThat(release.getArtifacts()).hasSize(1); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.jar("org.xml", "xml-lib", "1.0")); | ||
}, | ||
ReleaseIdFactory.forScmAndTag("https://commons.org/code/io", "1.0"), | ||
release -> { | ||
assertThat(release.id()).isEqualTo(ReleaseIdFactory.forScmAndTag("https://commons.org/code/io", "1.0")); | ||
assertThat(release.getArtifacts()).hasSize(1); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.jar("org.commons.io", "commons-io", "1.0")); | ||
}, | ||
ReleaseIdFactory.forScmAndTag("https://bytes.org/code", "1.0"), | ||
release -> { | ||
assertThat(release.id()).isEqualTo(ReleaseIdFactory.forScmAndTag("https://bytes.org/code", "1.0")); | ||
assertThat(release.getArtifacts()).hasSize(1); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.jar("org.bytes", "byte-utils", "1.0")); | ||
assertThat(release.getDependencies()).isEmpty(); | ||
}, | ||
ReleaseIdFactory.forScmAndTag("https://files.org/code", "1.0"), | ||
release -> { | ||
assertThat(release.id()).isEqualTo(ReleaseIdFactory.forScmAndTag("https://files.org/code", "1.0")); | ||
assertThat(release.getArtifacts()).hasSize(1); | ||
assertThat(release.getArtifacts()).containsKey(ArtifactCoords.jar("org.files", "file-utils", "1.0")); | ||
assertThat(release.getDependencies()).isEmpty(); | ||
}); | ||
} | ||
|
||
private static ProjectDependencyConfig.Mutable newDependencyConfig() { | ||
return ProjectDependencyConfig.builder() | ||
.setWarnOnMissingScm(true) | ||
.setLegacyScmLocator(true) | ||
.setProjectBom(ArtifactCoords.pom("org.camel", "camel-bom", "1.0")) | ||
.setNonProjectBoms(List.of(ArtifactCoords.pom("io.quarkus", "quarkus-bom", "1.0"))); | ||
} | ||
|
||
@Test | ||
public void managedOnly() { | ||
|
||
var depConfig = newDependencyConfig() | ||
.setIncludeNonManaged(false) | ||
.setProjectArtifacts(List.of( | ||
ArtifactCoords.jar("org.camel", "camel-core", "1.0"), | ||
ArtifactCoords.jar("org.camel", "camel-xml-lib", "1.0"))); | ||
|
||
var rc = ProjectDependencyResolver.builder() | ||
.setArtifactResolver(artifactResolver) | ||
.setDependencyConfig(depConfig.build()) | ||
.build() | ||
.getReleaseCollection(); | ||
assertThat(rc).isNotNull(); | ||
|
||
var releaseAssertions = new HashMap<ReleaseId, Consumer<ReleaseRepo>>(); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://quarkus.io/code", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://camel.org/code", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://xml.org/code", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://commons.org/code/io", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
|
||
assertReleaseDependencies(rc, releaseAssertions); | ||
} | ||
|
||
@Test | ||
public void completeTree() { | ||
|
||
var depConfig = newDependencyConfig() | ||
.setProjectArtifacts(List.of( | ||
ArtifactCoords.jar("org.camel", "camel-core", "1.0"), | ||
ArtifactCoords.jar("org.camel", "camel-xml-lib", "1.0"))); | ||
|
||
var rc = ProjectDependencyResolver.builder() | ||
.setArtifactResolver(artifactResolver) | ||
.setDependencyConfig(depConfig.build()) | ||
.build() | ||
.getReleaseCollection(); | ||
assertThat(rc).isNotNull(); | ||
|
||
var releaseAssertions = new HashMap<ReleaseId, Consumer<ReleaseRepo>>(); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://quarkus.io/code", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://camel.org/code", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://xml.org/code", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://commons.org/code/io", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://bytes.org/code", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
releaseAssertions.computeIfAbsent(ReleaseIdFactory.forScmAndTag("https://files.org/code", "1.0"), | ||
k -> NonCorePlatformMemberDependenciesTest.releaseAssertions.get(k)); | ||
|
||
assertReleaseDependencies(rc, releaseAssertions); | ||
} | ||
|
||
private static void assertReleaseDependencies(ReleaseCollection rc, | ||
HashMap<ReleaseId, Consumer<ReleaseRepo>> releaseAssertions) { | ||
for (ReleaseRepo r : rc.getReleases()) { | ||
var assertions = releaseAssertions.remove(r.id()); | ||
if (assertions == null) { | ||
fail("Unexpected release " + r.id()); | ||
} else { | ||
assertions.accept(r); | ||
} | ||
} | ||
|
||
if (!releaseAssertions.isEmpty()) { | ||
var i = releaseAssertions.keySet().iterator(); | ||
var sb = new StringBuilder(); | ||
sb.append("Missing release(s): ").append(i.next()); | ||
while (i.hasNext()) { | ||
sb.append(", ").append(i.next()); | ||
} | ||
fail(sb.toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters