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