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.codehaus.plexus.testing.PlexusTest;
33 import org.junit.jupiter.api.BeforeEach;
34
35 import static org.junit.jupiter.api.Assertions.assertEquals;
36 import static org.junit.jupiter.api.Assertions.assertNotNull;
37
38
39
40
41
42 @PlexusTest
43 @Deprecated
44 public abstract class AbstractConflictResolverTest {
45
46
47 private static final String GROUP_ID = "test";
48
49
50
51 protected Artifact a1;
52
53 protected Artifact a2;
54
55 protected Artifact b1;
56
57 private final String roleHint;
58
59 @Inject
60 private ArtifactFactory artifactFactory;
61
62 private ConflictResolver conflictResolver;
63
64 @Inject
65 protected PlexusContainer container;
66
67
68
69 public AbstractConflictResolverTest(String roleHint) throws Exception {
70 this.roleHint = roleHint;
71 }
72
73
74
75
76
77
78 @BeforeEach
79 public void setUp() throws Exception {
80 conflictResolver = (ConflictResolver) container.lookup(ConflictResolver.ROLE, roleHint);
81
82 a1 = createArtifact("a", "1.0");
83 a2 = createArtifact("a", "2.0");
84 b1 = createArtifact("b", "1.0");
85 }
86
87
88
89 protected ConflictResolver getConflictResolver() {
90 return conflictResolver;
91 }
92
93 protected void assertResolveConflict(
94 ResolutionNode expectedNode, ResolutionNode actualNode1, ResolutionNode actualNode2) {
95 ResolutionNode resolvedNode = getConflictResolver().resolveConflict(actualNode1, actualNode2);
96
97 assertNotNull(resolvedNode, "Expected resolvable");
98 assertEquals(expectedNode, resolvedNode, "Resolution node");
99 }
100
101 protected Artifact createArtifact(String id, String version) throws InvalidVersionSpecificationException {
102 return createArtifact(id, version, Artifact.SCOPE_COMPILE);
103 }
104
105 protected Artifact createArtifact(String id, String version, String scope)
106 throws InvalidVersionSpecificationException {
107 return createArtifact(id, version, scope, null, false);
108 }
109
110 protected Artifact createArtifact(String id, String version, String scope, String inheritedScope, boolean optional)
111 throws InvalidVersionSpecificationException {
112 VersionRange versionRange = VersionRange.createFromVersionSpec(version);
113
114 return artifactFactory.createDependencyArtifact(
115 GROUP_ID, id, versionRange, "jar", null, scope, inheritedScope, optional);
116 }
117
118 protected ResolutionNode createResolutionNode(Artifact Artifact) {
119 return new ResolutionNode(Artifact, Collections.<ArtifactRepository>emptyList());
120 }
121
122 protected ResolutionNode createResolutionNode(Artifact Artifact, ResolutionNode parent) {
123 return new ResolutionNode(Artifact, Collections.<ArtifactRepository>emptyList(), parent);
124 }
125 }