Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFARQ-195] Add a slot to the @RequiresModule annotation. This assist… #512

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@
* @return the module name
*/
String value();

/**
* The slot for the module. The default is {@code main}.
*
* @return the slot for the module
*/
String slot() default "main";
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ private ConditionEvaluationResult checkModule(final RequiresModule requiresModul

try {
// Get the module XML file.
final Optional<ModuleDefinition> moduleDefinition = findModuleXml(moduleDir, moduleToPath(requiresModule.value()));
final Optional<ModuleDefinition> moduleDefinition = findModuleXml(moduleDir,
moduleToPath(requiresModule.value(), requiresModule.slot()));
if (moduleDefinition.isPresent()) {
if (requiresModule.minVersion().isBlank()) {
final var def = moduleDefinition.get();
Expand Down Expand Up @@ -103,8 +104,8 @@ private ConditionEvaluationResult checkVersion(final RequiresModule requiresModu
requiresModule.minVersion()));
}

private static String moduleToPath(final String moduleName) {
return String.join(File.separator, moduleName.split("\\."));
private static String moduleToPath(final String moduleName, final String slot) {
return String.join(File.separator, moduleName.split("\\.")) + File.separator + slot;
}

private static ModuleDefinition parse(final Path moduleXmlFile) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.wildfly.arquillian.junit.requires.module;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.wildfly.arquillian.junit.annotations.RequiresModule;

Expand All @@ -28,4 +29,25 @@ public void skippedVersion() {
@RequiresModule(value = "org.wildfly.arquillian.junit.test.artifact.invalid")
public void skippedMissingModule() {
}

@Test
@RequiresModule(value = "org.wildfly.arquillian.junit.test.client", minVersion = "3.0.0.Final")
public void client() {
}

@Test
@RequiresModule(value = "org.wildfly.arquillian.junit.test.client-api", minVersion = "1.0.0.Final")
public void clientApi() {
}

@Test
@RequiresModule(value = "org.wildfly.arquillian.junit.test.client-api", slot = "test", minVersion = "1.1.0.Beta1")
public void clientApiTest() {
}

@Test
@RequiresModule(value = "org.wildfly.arquillian.junit.test.client-spi", minVersion = "1.0.0.Final")
public void clientSpi() {
Assertions.fail("Should have skipped");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,49 @@ public void snapshotSkippedVersion() {
"Found version 1.0.0.Beta2-SNAPSHOT and required a minimum of version 1.0.0.Beta3. Disabling test.")));
}

@Test
public void client() {
final var testEvents = EngineTestKit.engine("junit-jupiter")
.selectors(DiscoverySelectors.selectMethod(RequireArtifact.class, "client"))
.execute()
.testEvents();

testEvents.assertStatistics((stats) -> stats.succeeded(1L));
}

@Test
public void clientApi() {
final var testEvents = EngineTestKit.engine("junit-jupiter")
.selectors(DiscoverySelectors.selectMethod(RequireArtifact.class, "clientApi"))
.execute()
.testEvents();

testEvents.assertStatistics((stats) -> stats.succeeded(1L));
}

@Test
public void clientApiTest() {
final var testEvents = EngineTestKit.engine("junit-jupiter")
.selectors(DiscoverySelectors.selectMethod(RequireArtifact.class, "clientApiTest"))
.execute()
.testEvents();

testEvents.assertStatistics((stats) -> stats.succeeded(1L));
}

@Test
public void clientSpi() {
final var testEvents = EngineTestKit.engine("junit-jupiter")
.selectors(DiscoverySelectors.selectMethod(RequireArtifact.class, "clientSpi"))
.execute()
.testEvents();

testEvents.assertStatistics((stats) -> stats.skipped(1L));
testEvents.assertThatEvents().haveExactly(1, EventConditions.event(
EventConditions.skippedWithReason(
"Found version 1.0.0.Beta1 and required a minimum of version 1.0.0.Final. Disabling test.")));
}

private static void createJar(final String moduleName, final Path jbossHome, final String version) throws IOException {
// Create the JAR with a manifest only
final Path jarPath = jbossHome.resolve(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<module name="org.wildfly.arquillian.junit.test.client-api" xmlns="urn:jboss:module:1.9">

<resources>
<artifact name="org.wildfly.arquillian.test:client-api:1.0.0.Final" />
</resources>

<dependencies>
<module name="java.logging" />
</dependencies>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<module name="org.wildfly.arquillian.junit.test.client-api" xmlns="urn:jboss:module:1.9">

<resources>
<artifact name="org.wildfly.arquillian.test:client-api:1.1.0.Beta1" />
</resources>

<dependencies>
<module name="java.logging" />
</dependencies>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<module name="org.wildfly.arquillian.junit.test.client-spi" xmlns="urn:jboss:module:1.9">

<resources>
<artifact name="org.wildfly.arquillian.test:client-spi:1.0.0.Beta1" />
</resources>

<dependencies>
<module name="java.logging" />
</dependencies>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<module name="org.wildfly.arquillian.junit.test.client" xmlns="urn:jboss:module:1.9">

<resources>
<artifact name="org.wildfly.arquillian.test:client:3.0.0.Final" />
</resources>

<dependencies>
<module name="java.logging" />
</dependencies>
</module>