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