Skip to content

Commit

Permalink
Merge pull request #294 from jfdenise/issue_287
Browse files Browse the repository at this point in the history
Fix Issue #287, Ability to list the ChannelManifest and Streams present in a ChannelSession
  • Loading branch information
jmesnil authored Oct 22, 2024
2 parents 42ac81e + bbcbc34 commit bfa2963
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/org/wildfly/channel/ChannelSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ public MavenArtifact resolveMavenArtifact(String groupId, String artifactId, Str
return new MavenArtifact(groupId, artifactId, extension, classifier, latestVersion, artifact.file, artifact.channel.getResolvedChannelDefinition().getName());
}

/**
* Return the list of manifests configured in this channel session.
* @return The list of manifests.
*/
public List<ChannelManifest> getManifests() {
return channels.stream()
.map(p -> p.getManifest())
.collect(Collectors.toUnmodifiableList());
}

/**
* Resolve a list of Maven artifacts according to the session's channels.
* <p>
Expand Down
41 changes: 41 additions & 0 deletions core/src/test/java/org/wildfly/channel/ChannelSessionTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -571,6 +572,46 @@ public void testChannelWithStrictStrategy() throws Exception {
}
}

@Test
public void testGetManifests() throws Exception {
String name1 = "manifest1";
String name2 = "manifest2";
Stream[] streams1 = {new Stream("org.foo", "foo", "25.0.0.Final"), new Stream("org.foo", "bar", "23.0.0.Final")};
Stream[] streams2 = {new Stream("org.bar", "foo", "20.0.0.Final"), new Stream("org.bar", "bar", "21.0.0.Final")};
String manifest1 = buildManifest(name1, streams1);
String manifest2 = buildManifest(name2, streams2);

MavenVersionsResolver.Factory factory = mock(MavenVersionsResolver.Factory.class);
MavenVersionsResolver resolver = mock(MavenVersionsResolver.class);
when(factory.create(any())).thenReturn(resolver);

final List<Channel> channels = mockChannel(resolver, tempDir, manifest1, manifest2);

try (ChannelSession session = new ChannelSession(channels, factory)) {
assertEquals(2,session.getManifests().size());
checkManifest(session.getManifests().get(0), name1, streams1);
checkManifest(session.getManifests().get(1), name2, streams2);
}
}

private String buildManifest(String name, Stream... streams) {
StringBuilder manifest = new StringBuilder("schemaVersion: " + CURRENT_SCHEMA_VERSION + "\n" +
"name: " + name + "\n" +
"streams:\n");
for(Stream stream : streams) {
manifest.append(
" - groupId: "+ stream.getGroupId() + "\n"
+ " artifactId: "+ stream.getArtifactId() + "\n"
+ " version: \"" + stream.getVersion() + "\"\n");
}
return manifest.toString();
}

private void checkManifest(ChannelManifest manifest, String name, Stream... streams) {
assertEquals(name, manifest.getName());
assertTrue(Set.of(streams).containsAll(manifest.getStreams()));
}

@Test
public void testChannelWithDefaultStrategy() throws Exception {
String manifest = "schemaVersion: " + CURRENT_SCHEMA_VERSION + "\n" +
Expand Down

0 comments on commit bfa2963

Please sign in to comment.