21
21
import java .io .File ;
22
22
import java .net .URI ;
23
23
import java .net .URL ;
24
+ import java .util .ArrayList ;
24
25
import java .util .Arrays ;
25
26
import java .util .Collections ;
26
27
import java .util .HashMap ;
@@ -46,22 +47,24 @@ public class AetherGrapeEngineTests {
46
47
47
48
private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader ();
48
49
49
- private final AetherGrapeEngine grapeEngine = createGrapeEngine ();
50
-
51
- private AetherGrapeEngine createGrapeEngine () {
52
- return AetherGrapeEngineFactory .create (this .groovyClassLoader , Arrays
53
- .asList (new RepositoryConfiguration ("central" , URI
54
- .create ("http://repo1.maven.org/maven2" ), false ),
55
- new RepositoryConfiguration ("spring-milestone" , URI
56
- .create ("http://repo.spring.io/milestone" ), false )),
57
- new DependencyResolutionContext ());
50
+ private final RepositoryConfiguration springMilestones = new RepositoryConfiguration (
51
+ "spring-milestones" , URI .create ("https://repo.spring.io/milestone" ), false );
52
+
53
+ private AetherGrapeEngine createGrapeEngine (
54
+ RepositoryConfiguration ... additionalRepositories ) {
55
+ List <RepositoryConfiguration > repositoryConfigurations = new ArrayList <RepositoryConfiguration >();
56
+ repositoryConfigurations .add (new RepositoryConfiguration ("central" , URI
57
+ .create ("http://repo1.maven.org/maven2" ), false ));
58
+ repositoryConfigurations .addAll (Arrays .asList (additionalRepositories ));
59
+ return AetherGrapeEngineFactory .create (this .groovyClassLoader ,
60
+ repositoryConfigurations , new DependencyResolutionContext ());
58
61
}
59
62
60
63
@ Test
61
64
public void dependencyResolution () {
62
65
Map <String , Object > args = new HashMap <String , Object >();
63
66
64
- this .grapeEngine .grab (args ,
67
+ createGrapeEngine ( this .springMilestones ) .grab (args ,
65
68
createDependency ("org.springframework" , "spring-jdbc" , "3.2.4.RELEASE" ));
66
69
67
70
assertEquals (5 , this .groovyClassLoader .getURLs ().length );
@@ -94,7 +97,7 @@ public void run() {
94
97
95
98
List <RemoteRepository > repositories = (List <RemoteRepository >) ReflectionTestUtils
96
99
.getField (grapeEngine , "repositories" );
97
- assertEquals (2 , repositories .size ());
100
+ assertEquals (1 , repositories .size ());
98
101
assertEquals ("central-mirror" , repositories .get (0 ).getId ());
99
102
}
100
103
});
@@ -111,7 +114,7 @@ public void run() {
111
114
112
115
List <RemoteRepository > repositories = (List <RemoteRepository >) ReflectionTestUtils
113
116
.getField (grapeEngine , "repositories" );
114
- assertEquals (2 , repositories .size ());
117
+ assertEquals (1 , repositories .size ());
115
118
Authentication authentication = repositories .get (0 ).getAuthentication ();
116
119
assertNotNull (authentication );
117
120
}
@@ -125,7 +128,7 @@ public void dependencyResolutionWithExclusions() {
125
128
args .put ("excludes" ,
126
129
Arrays .asList (createExclusion ("org.springframework" , "spring-core" )));
127
130
128
- this .grapeEngine .grab (args ,
131
+ createGrapeEngine ( this .springMilestones ) .grab (args ,
129
132
createDependency ("org.springframework" , "spring-jdbc" , "3.2.4.RELEASE" ),
130
133
createDependency ("org.springframework" , "spring-beans" , "3.2.4.RELEASE" ));
131
134
@@ -136,7 +139,7 @@ public void dependencyResolutionWithExclusions() {
136
139
public void nonTransitiveDependencyResolution () {
137
140
Map <String , Object > args = new HashMap <String , Object >();
138
141
139
- this . grapeEngine .grab (
142
+ createGrapeEngine () .grab (
140
143
args ,
141
144
createDependency ("org.springframework" , "spring-jdbc" , "3.2.4.RELEASE" ,
142
145
false ));
@@ -150,7 +153,7 @@ public void dependencyResolutionWithCustomClassLoader() {
150
153
GroovyClassLoader customClassLoader = new GroovyClassLoader ();
151
154
args .put ("classLoader" , customClassLoader );
152
155
153
- this .grapeEngine .grab (args ,
156
+ createGrapeEngine ( this .springMilestones ) .grab (args ,
154
157
createDependency ("org.springframework" , "spring-jdbc" , "3.2.4.RELEASE" ));
155
158
156
159
assertEquals (0 , this .groovyClassLoader .getURLs ().length );
@@ -160,10 +163,10 @@ public void dependencyResolutionWithCustomClassLoader() {
160
163
@ Test
161
164
public void resolutionWithCustomResolver () {
162
165
Map <String , Object > args = new HashMap <String , Object >();
163
- this .grapeEngine . addResolver ( createResolver ( "restlet.org" ,
164
- "http://maven.restlet.org" ));
165
- this . grapeEngine . grab ( args ,
166
- createDependency ("org.restlet" , "org.restlet" , "1.1.6" ));
166
+ AetherGrapeEngine grapeEngine = this .createGrapeEngine ();
167
+ grapeEngine
168
+ . addResolver ( createResolver ( "restlet.org" , "http://maven.restlet.org" ));
169
+ grapeEngine . grab ( args , createDependency ("org.restlet" , "org.restlet" , "1.1.6" ));
167
170
assertEquals (1 , this .groovyClassLoader .getURLs ().length );
168
171
}
169
172
@@ -173,7 +176,7 @@ public void differingTypeAndExt() {
173
176
"grails-dependencies" , "2.4.0" );
174
177
dependency .put ("type" , "foo" );
175
178
dependency .put ("ext" , "bar" );
176
- this . grapeEngine .grab (Collections .emptyMap (), dependency );
179
+ createGrapeEngine () .grab (Collections .emptyMap (), dependency );
177
180
}
178
181
179
182
@ Test
@@ -182,7 +185,7 @@ public void pomDependencyResolutionViaType() {
182
185
Map <String , Object > dependency = createDependency ("org.springframework" ,
183
186
"spring-framework-bom" , "4.0.5.RELEASE" );
184
187
dependency .put ("type" , "pom" );
185
- this . grapeEngine .grab (args , dependency );
188
+ createGrapeEngine () .grab (args , dependency );
186
189
URL [] urls = this .groovyClassLoader .getURLs ();
187
190
assertEquals (1 , urls .length );
188
191
assertTrue (urls [0 ].toExternalForm ().endsWith (".pom" ));
@@ -194,7 +197,7 @@ public void pomDependencyResolutionViaExt() {
194
197
Map <String , Object > dependency = createDependency ("org.springframework" ,
195
198
"spring-framework-bom" , "4.0.5.RELEASE" );
196
199
dependency .put ("ext" , "pom" );
197
- this . grapeEngine .grab (args , dependency );
200
+ createGrapeEngine () .grab (args , dependency );
198
201
URL [] urls = this .groovyClassLoader .getURLs ();
199
202
assertEquals (1 , urls .length );
200
203
assertTrue (urls [0 ].toExternalForm ().endsWith (".pom" ));
@@ -207,7 +210,7 @@ public void resolutionWithClassifier() {
207
210
Map <String , Object > dependency = createDependency ("org.springframework" ,
208
211
"spring-jdbc" , "3.2.4.RELEASE" , false );
209
212
dependency .put ("classifier" , "sources" );
210
- this . grapeEngine .grab (args , dependency );
213
+ createGrapeEngine () .grab (args , dependency );
211
214
212
215
URL [] urls = this .groovyClassLoader .getURLs ();
213
216
assertEquals (1 , urls .length );
0 commit comments