1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.legacy.resolver.conflict;
20
21 import javax.inject.Inject;
22
23 import java.util.Collections;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.factory.ArtifactFactory;
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.artifact.resolver.ResolutionNode;
29 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
30 import org.apache.maven.artifact.versioning.VersionRange;
31 import org.codehaus.plexus.PlexusContainer;
32 import org.junit.jupiter.api.BeforeEach;
33
34 import static org.junit.jupiter.api.Assertions.assertEquals;
35 import static org.junit.jupiter.api.Assertions.assertNotNull;
36
37
38
39
40
41
42 public abstract class AbstractConflictResolverTest {
43
44
45 private static final String GROUP_ID = "test";
46
47
48
49 protected Artifact a1;
50
51 protected Artifact a2;
52
53 protected Artifact b1;
54
55 private final String roleHint;
56
57 @Inject
58 private ArtifactFactory artifactFactory;
59
60 @Inject
61 private PlexusContainer container;
62
63 private ConflictResolver conflictResolver;
64
65
66
67 public AbstractConflictResolverTest(String roleHint) throws Exception {
68 this.roleHint = roleHint;
69 }
70
71
72
73
74
75
76 @BeforeEach
77 protected void setUp() throws Exception {
78
79 conflictResolver = (ConflictResolver) container.lookup(ConflictResolver.ROLE, roleHint);
80
81 a1 = createArtifact("a", "1.0");
82 a2 = createArtifact("a", "2.0");
83 b1 = createArtifact("b", "1.0");
84 }
85
86
87
88 protected ConflictResolver getConflictResolver() {
89 return conflictResolver;
90 }
91
92 protected void assertResolveConflict(
93 ResolutionNode expectedNode, ResolutionNode actualNode1, ResolutionNode actualNode2) {
94 ResolutionNode resolvedNode = getConflictResolver().resolveConflict(actualNode1, actualNode2);
95
96 assertNotNull(resolvedNode, "Expected resolvable");
97 assertEquals(expectedNode, resolvedNode, "Resolution node");
98 }
99
100 protected Artifact createArtifact(String id, String version) throws InvalidVersionSpecificationException {
101 return createArtifact(id, version, Artifact.SCOPE_COMPILE);
102 }
103
104 protected Artifact createArtifact(String id, String version, String scope)
105 throws InvalidVersionSpecificationException {
106 return createArtifact(id, version, scope, null, false);
107 }
108
109 protected Artifact createArtifact(String id, String version, String scope, String inheritedScope, boolean optional)
110 throws InvalidVersionSpecificationException {
111 VersionRange versionRange = VersionRange.createFromVersionSpec(version);
112
113 return artifactFactory.createDependencyArtifact(
114 GROUP_ID, id, versionRange, "jar", null, scope, inheritedScope, optional);
115 }
116
117 protected ResolutionNode createResolutionNode(Artifact artifact) {
118 return new ResolutionNode(artifact, Collections.<ArtifactRepository>emptyList());
119 }
120
121 protected ResolutionNode createResolutionNode(Artifact artifact, ResolutionNode parent) {
122 return new ResolutionNode(artifact, Collections.<ArtifactRepository>emptyList(), parent);
123 }
124 }