-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from TomasHofman/multiple-channels-in-file
Allow multiple channels to be loaded from a single file
- Loading branch information
Showing
6 changed files
with
123 additions
and
4 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
76 changes: 76 additions & 0 deletions
76
plugin/src/test/java/org/wildfly/channelplugin/AbstractChannelMojoTestCase.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,76 @@ | ||
package org.wildfly.channelplugin; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.assertj.core.api.Assertions; | ||
import org.eclipse.aether.RepositorySystem; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.eclipse.aether.resolution.ArtifactRequest; | ||
import org.eclipse.aether.resolution.ArtifactResult; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class AbstractChannelMojoTestCase { | ||
|
||
@TempDir | ||
File tempDir; | ||
|
||
private final RepositorySystem repositorySystem = Mockito.mock(RepositorySystem.class); | ||
|
||
private AbstractChannelMojo mojo; | ||
|
||
@BeforeEach | ||
public void before() throws Exception { | ||
// Prepare test resources as local files | ||
Path channelFile = prepareResource("multiple-channels.yaml"); | ||
Path manifestFile = prepareResource("manifest.yaml"); | ||
|
||
// Mock RepositorySystem, the resolveArtifact() method must return a valid manifest file because this is needed | ||
// for ChannelSession init. | ||
ArtifactResult artifactResult = new ArtifactResult(new ArtifactRequest()); | ||
artifactResult.setArtifact(new DefaultArtifact(null, null, null, null, null, Collections.emptyMap(), | ||
manifestFile.toFile())); | ||
Mockito.when(repositorySystem.resolveArtifact(Mockito.any(), Mockito.any())) | ||
.thenReturn(artifactResult); | ||
|
||
// Initialize a concrete instance of the AbstractChannelMojo class | ||
mojo = new AbstractChannelMojo() { | ||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
|
||
} | ||
}; | ||
mojo.channelFile = channelFile.toString(); | ||
mojo.remoteRepositories = Collections.emptyList(); | ||
mojo.repositorySystem = repositorySystem; | ||
} | ||
|
||
@Test | ||
public void testMultipleChannelsInFile() throws Exception { | ||
mojo.initChannelSession(); | ||
|
||
Assertions.assertThat(mojo.channels.size()).isEqualTo(2); | ||
Assertions.assertThat(mojo.channels).extracting("manifestCoordinate.artifactId").containsAll( | ||
List.of("eap-8.0", "eap-xp-5.0")); | ||
} | ||
|
||
@SuppressWarnings("ResultOfMethodCallIgnored") | ||
private Path prepareResource(String resourceName) throws IOException { | ||
tempDir.mkdir(); | ||
Path targetFile = tempDir.toPath().resolve(resourceName); | ||
InputStream resource = getClass().getResourceAsStream(resourceName); | ||
Assertions.assertThat(resource).isNotNull().withFailMessage("Resource not found: " + resourceName); | ||
Files.copy(resource, targetFile); | ||
return targetFile; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
plugin/src/test/resources/org/wildfly/channelplugin/manifest.yaml
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,2 @@ | ||
--- | ||
schemaVersion: 1.0.0 |
24 changes: 24 additions & 0 deletions
24
plugin/src/test/resources/org/wildfly/channelplugin/multiple-channels.yaml
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,24 @@ | ||
--- | ||
schemaVersion: "2.0.0" | ||
name: "eap-xp-5.0-channel" | ||
repositories: | ||
- id: "Brew" | ||
url: "https://download.eng.bos.redhat.com/brewroot/repos/jb-eap-8.0-maven-build/latest/maven/" | ||
manifest: | ||
maven: | ||
groupId: "org.jboss.eap.channels" | ||
artifactId: "eap-xp-5.0" | ||
version: "1.0.0" | ||
noStreamStrategy: "none" | ||
--- | ||
schemaVersion: "2.0.0" | ||
name: "eap-8.0-channel" | ||
repositories: | ||
- id: "Brew" | ||
url: "https://download.eng.bos.redhat.com/brewroot/repos/jb-eap-8.0-maven-build/latest/maven/" | ||
manifest: | ||
maven: | ||
groupId: "org.jboss.eap.channels" | ||
artifactId: "eap-8.0" | ||
version: "1.0.0" | ||
noStreamStrategy: "none" |
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