Skip to content

Commit

Permalink
Merge pull request wildfly-extras#669 from spyrkob/downstream_testsuite
Browse files Browse the repository at this point in the history
Make integration tests customizable
  • Loading branch information
spyrkob authored May 14, 2024
2 parents 2952150 + df0af0d commit fe8d15a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jboss.galleon.config.ProvisioningConfig;
import org.jboss.galleon.universe.FeaturePackLocation;
import org.jboss.galleon.xml.ProvisioningXmlParser;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -41,37 +42,45 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

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

public class FeaturesAddTest {

protected static final String DATASOURCE_GALLEON_FPL = "org.wildfly:wildfly-datasources-galleon-pack";
protected static final String DATASOURCES_FP_VERSION = "4.0.0.Final";
protected static final String MYSQL_CONNECTOR_VERSION = "8.0.32";
protected static final Path MODULE_PATH = Path.of("modules", "com", "mysql", "jdbc");
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

private File targetDir;
private String profileName;
private String datasourceGalleonFp;
private static final String DS_GROUP_ID = "org.postgresql";
private static final String DS_ARTIFACT_ID = "postgresql";
protected static final String DS_VERSION = "42.7.3";
protected static final Path MODULE_PATH = Path.of("modules", DS_GROUP_ID.replace('.', '/'), "jdbc");


@Before
public void setUp() throws IOException {
targetDir = tempDir.newFolder("wildfly");

final Properties properties = new Properties();
properties.load(this.getClass().getClassLoader().getResourceAsStream("properties-from-pom.properties"));
datasourceGalleonFp = String.format("%s:%s",
properties.getProperty("prospero.test.datasources-feature-pack.groupId"),
properties.getProperty("prospero.test.datasources-feature-pack.artifactId"));

profileName = properties.getProperty("prospero.test.server.profile");
}

@Test
public void addFeaturePack() throws Exception {
installWildfly();

final ChannelManifest manifest = new ChannelManifest(null, null, null, List.of(
new Stream("org.wildfly", "wildfly-datasources-galleon-pack", DATASOURCES_FP_VERSION),
new Stream("com.mysql", "mysql-connector-j", MYSQL_CONNECTOR_VERSION))
);
final Path manifestPath = tempDir.newFile("datasources-manifest.yaml").toPath();
Files.writeString(manifestPath, ChannelManifestMapper.toYaml(manifest));
final Path manifestPath = generateDatasourcesManifest();

System.out.println("Adding datasources channel");
ExecutionUtils.prosperoExecution(CliConstants.Commands.CHANNEL, CliConstants.Commands.ADD,
Expand All @@ -86,8 +95,9 @@ public void addFeaturePack() throws Exception {
// install the datasource FP
System.out.println("Installing datasources feature pack");
ExecutionUtils.prosperoExecution(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD,
CliConstants.FPL, DATASOURCE_GALLEON_FPL,
CliConstants.LAYERS, "datasources-web-server,mysql-datasource",
CliConstants.FPL, datasourceGalleonFp,
CliConstants.LAYERS, "datasources-web-server,postgresql-datasource",
CliConstants.ACCEPT_AGREEMENTS,
CliConstants.YES,
CliConstants.DIR, targetDir.getAbsolutePath())
.withTimeLimit(10, TimeUnit.MINUTES)
Expand All @@ -99,7 +109,7 @@ public void addFeaturePack() throws Exception {
.exists()
.isDirectory();

assertThat(targetDir.toPath().resolve(MODULE_PATH).resolve("main").resolve("mysql-connector-j-8.0.32.jar"))
assertThat(targetDir.toPath().resolve(MODULE_PATH).resolve("main").resolve(String.format("%s-%s.jar", DS_ARTIFACT_ID, DS_VERSION)))
.exists()
.isNotEmptyFile();

Expand Down Expand Up @@ -140,17 +150,19 @@ public void datasourcesFeaturePackRequiresLayers() throws Exception {
// install the datasource FP
System.out.println("Installing datasources feature pack");
ExecutionUtils.prosperoExecution(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD,
CliConstants.FPL, DATASOURCE_GALLEON_FPL,
CliConstants.FPL, datasourceGalleonFp,
CliConstants.YES,
CliConstants.ACCEPT_AGREEMENTS,
CliConstants.DIR, targetDir.getAbsolutePath())
.withTimeLimit(10, TimeUnit.MINUTES)
.execute()
.assertReturnCode(ReturnCodes.INVALID_ARGUMENTS)
.assertErrorContains(CliMessages.MESSAGES.featurePackRequiresLayers(DATASOURCE_GALLEON_FPL));
.assertErrorContains(CliMessages.MESSAGES.featurePackRequiresLayers(datasourceGalleonFp));
}

@Test
public void installWildflyGalleonPackOverWildflyEEGalleonPack_ReplacesWildflyGalleonPack() throws Exception {
Assume.assumeTrue(profileName.equals("wildfly"));
System.out.println("Installing wildfly EE");
final Path channelsFile = MetadataTestUtils.prepareChannel("manifests/wildfly-30.0.0.Final-manifest.yaml");
ExecutionUtils.prosperoExecution(CliConstants.Commands.INSTALL,
Expand Down Expand Up @@ -199,10 +211,16 @@ public void installWildflyGalleonPackOverWildflyEEGalleonPack_ReplacesWildflyGal
private void installWildfly() throws Exception {
System.out.println("Installing wildfly");
final Path channelsFile = MetadataTestUtils.prepareChannel("manifests/wildfly-30.0.0.Final-manifest.yaml");
ExecutionUtils.prosperoExecution(CliConstants.Commands.INSTALL,
CliConstants.CHANNELS, channelsFile.toString(),
CliConstants.PROFILE, "wildfly",
CliConstants.DIR, targetDir.getAbsolutePath())
final List<String> args = new ArrayList<>(List.of(
CliConstants.Commands.INSTALL,
CliConstants.PROFILE, profileName,
CliConstants.DIR, targetDir.getAbsolutePath()));

if (profileName.equals("wildfly")) {
args.add(CliConstants.CHANNELS);
args.add(channelsFile.toString());
}
ExecutionUtils.prosperoExecution(args.toArray(new String[]{}))
.withTimeLimit(10, TimeUnit.MINUTES)
.execute()
.assertReturnCode(ReturnCodes.SUCCESS);
Expand All @@ -214,7 +232,7 @@ private void installWildfly() throws Exception {
private Path generateDatasourcesManifest() throws IOException {
final ChannelManifest manifest = new ChannelManifest(null, null, null, List.of(
new Stream("org.wildfly", "wildfly-datasources-galleon-pack", DATASOURCES_FP_VERSION),
new Stream("com.mysql", "mysql-connector-j", MYSQL_CONNECTOR_VERSION))
new Stream(DS_GROUP_ID, DS_ARTIFACT_ID, DS_VERSION))
);
final Path manifestPath = tempDir.newFile("datasources-manifest.yaml").toPath();
Files.writeString(manifestPath, ChannelManifestMapper.toYaml(manifest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public void testInstallProsperoWithWildfly() throws Exception {
.execute()
.assertReturnCode(ReturnCodes.SUCCESS);

final Path installedProspero = targetDir.resolve("bin").resolve(ExecutionUtils.isWindows()?"prospero.bat":"prospero.sh");
final Path installedProspero = targetDir.resolve("bin")
.resolve(ExecutionUtils.isWindows()?DistributionInfo.DIST_NAME + ".bat":DistributionInfo.DIST_NAME + ".sh");
assertTrue(Files.exists(installedProspero));

ExecutionUtils.prosperoExecution(CliConstants.Commands.UPDATE, CliConstants.Commands.LIST,
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<prospero.test.base.channel.groupId>org.wildfly.channels</prospero.test.base.channel.groupId>
<prospero.test.base.channel.artifactId>wildfly-30-test</prospero.test.base.channel.artifactId>
<prospero.test.base.repositories>https://repo1.maven.org/maven2/,https://repository.jboss.org/nexus/content/groups/public/</prospero.test.base.repositories>
<prospero.test.datasources-feature-pack.groupId>org.wildfly</prospero.test.datasources-feature-pack.groupId>
<prospero.test.datasources-feature-pack.artifactId>wildfly-datasources-galleon-pack</prospero.test.datasources-feature-pack.artifactId>
<prospero.test.server.profile>wildfly</prospero.test.server.profile>
<prospero.repo.id>central</prospero.repo.id>
<prospero.repo.url>https://repo1.maven.org/maven2/</prospero.repo.url>
<prospero.channel.resolution.mode>NOT_REQUIRED</prospero.channel.resolution.mode>
Expand Down

0 comments on commit fe8d15a

Please sign in to comment.