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