From 5defa42436f8b88345ffc54a9c54eb195034ed54 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 10 Jun 2015 16:16:23 +0100 Subject: [PATCH] Update AetherGrapeEngineTests to only use milestone repo when needed Closes gh-3051 --- .../grape/AetherGrapeEngineTests.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java index d00a4f04f0..a1c63a5b4b 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java @@ -21,6 +21,7 @@ import groovy.lang.GroovyClassLoader; import java.io.File; import java.net.URI; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -46,22 +47,24 @@ public class AetherGrapeEngineTests { private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(); - private final AetherGrapeEngine grapeEngine = createGrapeEngine(); - - private AetherGrapeEngine createGrapeEngine() { - return AetherGrapeEngineFactory.create(this.groovyClassLoader, Arrays - .asList(new RepositoryConfiguration("central", URI - .create("http://repo1.maven.org/maven2"), false), - new RepositoryConfiguration("spring-milestone", URI - .create("http://repo.spring.io/milestone"), false)), - new DependencyResolutionContext()); + private final RepositoryConfiguration springMilestones = new RepositoryConfiguration( + "spring-milestones", URI.create("https://repo.spring.io/milestone"), false); + + private AetherGrapeEngine createGrapeEngine( + RepositoryConfiguration... additionalRepositories) { + List repositoryConfigurations = new ArrayList(); + repositoryConfigurations.add(new RepositoryConfiguration("central", URI + .create("http://repo1.maven.org/maven2"), false)); + repositoryConfigurations.addAll(Arrays.asList(additionalRepositories)); + return AetherGrapeEngineFactory.create(this.groovyClassLoader, + repositoryConfigurations, new DependencyResolutionContext()); } @Test public void dependencyResolution() { Map args = new HashMap(); - this.grapeEngine.grab(args, + createGrapeEngine(this.springMilestones).grab(args, createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE")); assertEquals(5, this.groovyClassLoader.getURLs().length); @@ -94,7 +97,7 @@ public class AetherGrapeEngineTests { List repositories = (List) ReflectionTestUtils .getField(grapeEngine, "repositories"); - assertEquals(2, repositories.size()); + assertEquals(1, repositories.size()); assertEquals("central-mirror", repositories.get(0).getId()); } }); @@ -111,7 +114,7 @@ public class AetherGrapeEngineTests { List repositories = (List) ReflectionTestUtils .getField(grapeEngine, "repositories"); - assertEquals(2, repositories.size()); + assertEquals(1, repositories.size()); Authentication authentication = repositories.get(0).getAuthentication(); assertNotNull(authentication); } @@ -125,7 +128,7 @@ public class AetherGrapeEngineTests { args.put("excludes", Arrays.asList(createExclusion("org.springframework", "spring-core"))); - this.grapeEngine.grab(args, + createGrapeEngine(this.springMilestones).grab(args, createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"), createDependency("org.springframework", "spring-beans", "3.2.4.RELEASE")); @@ -136,7 +139,7 @@ public class AetherGrapeEngineTests { public void nonTransitiveDependencyResolution() { Map args = new HashMap(); - this.grapeEngine.grab( + createGrapeEngine().grab( args, createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE", false)); @@ -150,7 +153,7 @@ public class AetherGrapeEngineTests { GroovyClassLoader customClassLoader = new GroovyClassLoader(); args.put("classLoader", customClassLoader); - this.grapeEngine.grab(args, + createGrapeEngine(this.springMilestones).grab(args, createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE")); assertEquals(0, this.groovyClassLoader.getURLs().length); @@ -160,10 +163,10 @@ public class AetherGrapeEngineTests { @Test public void resolutionWithCustomResolver() { Map args = new HashMap(); - this.grapeEngine.addResolver(createResolver("restlet.org", - "http://maven.restlet.org")); - this.grapeEngine.grab(args, - createDependency("org.restlet", "org.restlet", "1.1.6")); + AetherGrapeEngine grapeEngine = this.createGrapeEngine(); + grapeEngine + .addResolver(createResolver("restlet.org", "http://maven.restlet.org")); + grapeEngine.grab(args, createDependency("org.restlet", "org.restlet", "1.1.6")); assertEquals(1, this.groovyClassLoader.getURLs().length); } @@ -173,7 +176,7 @@ public class AetherGrapeEngineTests { "grails-dependencies", "2.4.0"); dependency.put("type", "foo"); dependency.put("ext", "bar"); - this.grapeEngine.grab(Collections.emptyMap(), dependency); + createGrapeEngine().grab(Collections.emptyMap(), dependency); } @Test @@ -182,7 +185,7 @@ public class AetherGrapeEngineTests { Map dependency = createDependency("org.springframework", "spring-framework-bom", "4.0.5.RELEASE"); dependency.put("type", "pom"); - this.grapeEngine.grab(args, dependency); + createGrapeEngine().grab(args, dependency); URL[] urls = this.groovyClassLoader.getURLs(); assertEquals(1, urls.length); assertTrue(urls[0].toExternalForm().endsWith(".pom")); @@ -194,7 +197,7 @@ public class AetherGrapeEngineTests { Map dependency = createDependency("org.springframework", "spring-framework-bom", "4.0.5.RELEASE"); dependency.put("ext", "pom"); - this.grapeEngine.grab(args, dependency); + createGrapeEngine().grab(args, dependency); URL[] urls = this.groovyClassLoader.getURLs(); assertEquals(1, urls.length); assertTrue(urls[0].toExternalForm().endsWith(".pom")); @@ -207,7 +210,7 @@ public class AetherGrapeEngineTests { Map dependency = createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE", false); dependency.put("classifier", "sources"); - this.grapeEngine.grab(args, dependency); + createGrapeEngine().grab(args, dependency); URL[] urls = this.groovyClassLoader.getURLs(); assertEquals(1, urls.length);