mirror of https://github.com/apache/ant-ivy
Merge 373dca7da6 into 8f2556cb9f
This commit is contained in:
commit
0b72e6f4db
|
|
@ -17,6 +17,19 @@
|
|||
*/
|
||||
package org.apache.ivy.core.retrieve;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.ivy.Ivy;
|
||||
import org.apache.ivy.TestHelper;
|
||||
import org.apache.ivy.core.IvyPatternHelper;
|
||||
|
|
@ -38,35 +51,24 @@ import org.apache.ivy.core.resolve.ResolveOptions;
|
|||
import org.apache.ivy.util.DefaultMessageLogger;
|
||||
import org.apache.ivy.util.Message;
|
||||
import org.apache.ivy.util.MockMessageLogger;
|
||||
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.filters.TokenFilter.ReplaceString;
|
||||
import org.apache.tools.ant.taskdefs.Copy;
|
||||
import org.apache.tools.ant.taskdefs.Delete;
|
||||
import org.apache.tools.ant.types.FilterChain;
|
||||
import org.apache.tools.ant.filters.TokenFilter.ReplaceString;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
|
||||
public class RetrieveTest {
|
||||
|
||||
|
|
@ -505,7 +507,7 @@ public class RetrieveTest {
|
|||
|
||||
// normal resolve, the file goes in the cache
|
||||
final ResolveReport report = ivy.resolve(url, roptions);
|
||||
assertFalse("Resolution report has errors", report.hasError());
|
||||
assumeFalse(report.hasError());
|
||||
final ModuleDescriptor md = report.getModuleDescriptor();
|
||||
assertNotNull("Module descriptor from report was null", md);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,20 +26,31 @@ import org.apache.ivy.util.url.TimeoutConstrainedURLHandler;
|
|||
import org.apache.ivy.util.url.URLHandlerDispatcher;
|
||||
import org.apache.ivy.util.url.URLHandlerRegistry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
/**
|
||||
* split from XmlIvyConfigurationParserTest due to dependency on network resource
|
||||
* Split from XmlIvyConfigurationParserTest due to dependency on network resource.
|
||||
*/
|
||||
public class OnlineXmlSettingsParserTest {
|
||||
// remote.test
|
||||
public class OnlineXmlSettingsParserTest { // remote.test
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
URLHandlerDispatcher dispatcher = new URLHandlerDispatcher();
|
||||
TimeoutConstrainedURLHandler httpHandler = URLHandlerRegistry.getHttp();
|
||||
dispatcher.setDownloader("http", httpHandler);
|
||||
dispatcher.setDownloader("https", httpHandler);
|
||||
URLHandlerRegistry.setDefault(dispatcher);
|
||||
|
||||
assumeTrue(httpHandler.isReachable(new URL("https://ant.apache.org/")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludeHttpUrl() throws Exception {
|
||||
configureURLHandler();
|
||||
IvySettings settings = new IvySettings();
|
||||
XmlSettingsParser parser = new XmlSettingsParser(settings);
|
||||
parser.parse(new URL("https://ant.apache.org/ivy/test/ivysettings-include-http-url.xml"));
|
||||
|
|
@ -52,11 +63,9 @@ public class OnlineXmlSettingsParserTest {
|
|||
@Test
|
||||
public void testIncludeHttpRelativeUrl() throws Exception {
|
||||
// Use a settings file via http that use an include with relative url
|
||||
configureURLHandler();
|
||||
IvySettings settings = new IvySettings();
|
||||
XmlSettingsParser parser = new XmlSettingsParser(settings);
|
||||
parser.parse(new URL(
|
||||
"https://ant.apache.org/ivy/test/ivysettings-include-http-relative-url.xml"));
|
||||
parser.parse(new URL("https://ant.apache.org/ivy/test/ivysettings-include-http-relative-url.xml"));
|
||||
|
||||
DependencyResolver resolver = settings.getResolver("ivyrep");
|
||||
assertNotNull(resolver);
|
||||
|
|
@ -66,11 +75,9 @@ public class OnlineXmlSettingsParserTest {
|
|||
@Test
|
||||
public void testIncludeHttpRelativeFile() throws Exception {
|
||||
// Use a settings file via http that use an include with relative file
|
||||
configureURLHandler();
|
||||
IvySettings settings = new IvySettings();
|
||||
XmlSettingsParser parser = new XmlSettingsParser(settings);
|
||||
parser.parse(new URL(
|
||||
"https://ant.apache.org/ivy/test/ivysettings-include-http-relative-file.xml"));
|
||||
parser.parse(new URL("https://ant.apache.org/ivy/test/ivysettings-include-http-relative-file.xml"));
|
||||
|
||||
DependencyResolver resolver = settings.getResolver("ivyrep");
|
||||
assertNotNull(resolver);
|
||||
|
|
@ -82,23 +89,12 @@ public class OnlineXmlSettingsParserTest {
|
|||
// Use a settings file via http that use an include with absolute file
|
||||
// WARNING : this test will only work if the test are launched from the project root
|
||||
// directory
|
||||
configureURLHandler();
|
||||
IvySettings settings = new IvySettings();
|
||||
XmlSettingsParser parser = new XmlSettingsParser(settings);
|
||||
parser.parse(new URL(
|
||||
"https://ant.apache.org/ivy/test/ivysettings-include-http-absolute-file.xml"));
|
||||
parser.parse(new URL("https://ant.apache.org/ivy/test/ivysettings-include-http-absolute-file.xml"));
|
||||
|
||||
DependencyResolver inc = settings.getResolver("includeworks");
|
||||
assertNotNull(inc);
|
||||
assertTrue(inc instanceof ChainResolver);
|
||||
}
|
||||
|
||||
private void configureURLHandler() {
|
||||
URLHandlerDispatcher dispatcher = new URLHandlerDispatcher();
|
||||
TimeoutConstrainedURLHandler httpHandler = URLHandlerRegistry.getHttp();
|
||||
dispatcher.setDownloader("http", httpHandler);
|
||||
dispatcher.setDownloader("https", httpHandler);
|
||||
URLHandlerRegistry.setDefault(dispatcher);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
package org.apache.ivy.osgi.updatesite;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.ParseException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.ivy.Ivy;
|
||||
import org.apache.ivy.core.cache.RepositoryCacheManager;
|
||||
|
|
@ -32,11 +32,12 @@ import org.apache.ivy.core.settings.IvySettings;
|
|||
import org.apache.ivy.osgi.core.BundleInfo;
|
||||
import org.apache.ivy.plugins.resolver.ChainResolver;
|
||||
import org.apache.ivy.plugins.resolver.IBiblioResolver;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.apache.ivy.plugins.resolver.IBiblioResolver.DEFAULT_M2_ROOT;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
|
||||
public class UpdateSiteAndIbiblioResolverTest {
|
||||
|
||||
|
|
@ -56,7 +57,15 @@ public class UpdateSiteAndIbiblioResolverTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
try {
|
||||
new URL(IBiblioResolver.DEFAULT_M2_ROOT).getContent();
|
||||
} catch (Exception e) {
|
||||
assumeNoException(e);
|
||||
}
|
||||
|
||||
settings = new IvySettings();
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.root", IBiblioResolver.DEFAULT_M2_ROOT);
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.pattern", "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
|
||||
|
||||
chain = new ChainResolver();
|
||||
chain.setName("chain");
|
||||
|
|
@ -69,9 +78,6 @@ public class UpdateSiteAndIbiblioResolverTest {
|
|||
|
||||
resolver2 = new IBiblioResolver();
|
||||
resolver2.setName("maven2");
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.root", DEFAULT_M2_ROOT);
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.pattern",
|
||||
"[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
|
||||
resolver2.setSettings(settings);
|
||||
|
||||
chain.add(resolver);
|
||||
|
|
@ -98,19 +104,15 @@ public class UpdateSiteAndIbiblioResolverTest {
|
|||
data = new ResolveData(ivy.getResolveEngine(), new ResolveOptions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArtifactRef() throws ParseException {
|
||||
|
||||
@Test
|
||||
public void testArtifactRef() throws Exception {
|
||||
// Simple Dependency for ibiblio
|
||||
ModuleRevisionId mrid1 = ModuleRevisionId.newInstance("log4j", "log4j", "1.2.16");
|
||||
ResolvedModuleRevision rmr1 = chain.getDependency(new DefaultDependencyDescriptor(mrid1,
|
||||
false), data);
|
||||
ResolvedModuleRevision rmr1 = chain.getDependency(new DefaultDependencyDescriptor(mrid1, false), data);
|
||||
|
||||
// Simple Dependency for updatesite
|
||||
ModuleRevisionId mrid2 = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE,
|
||||
"org.apache.ivy", "2.0.0.final_20090108225011");
|
||||
ResolvedModuleRevision rmr2 = chain.getDependency(new DefaultDependencyDescriptor(mrid2,
|
||||
false), data);
|
||||
ModuleRevisionId mrid2 = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.apache.ivy", "2.0.0.final_20090108225011");
|
||||
ResolvedModuleRevision rmr2 = chain.getDependency(new DefaultDependencyDescriptor(mrid2, false), data);
|
||||
|
||||
assertNotNull(rmr1);
|
||||
assertNotNull(rmr2);
|
||||
|
|
@ -121,5 +123,4 @@ public class UpdateSiteAndIbiblioResolverTest {
|
|||
chain.exists(artifacts2[0]);
|
||||
chain.exists(artifacts1[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,8 @@
|
|||
*/
|
||||
package org.apache.ivy.osgi.updatesite;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.ivy.core.cache.CacheResourceOptions;
|
||||
|
|
@ -34,11 +28,15 @@ import org.apache.ivy.osgi.repo.ModuleDescriptorWrapper;
|
|||
import org.apache.ivy.osgi.repo.RepoDescriptor;
|
||||
import org.apache.ivy.util.CacheCleaner;
|
||||
import org.apache.ivy.util.CollectionUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
|
||||
public class UpdateSiteLoaderTest {
|
||||
|
||||
|
|
@ -48,10 +46,12 @@ public class UpdateSiteLoaderTest {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
IvySettings ivySettings = new IvySettings();
|
||||
cache = new File("build/cache");
|
||||
cache.mkdirs();
|
||||
|
||||
IvySettings ivySettings = new IvySettings();
|
||||
ivySettings.setDefaultCache(cache);
|
||||
|
||||
CacheResourceOptions options = new CacheResourceOptions();
|
||||
loader = new UpdateSiteLoader(ivySettings.getDefaultRepositoryCacheManager(), null, options, null);
|
||||
}
|
||||
|
|
@ -62,9 +62,14 @@ public class UpdateSiteLoaderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIvyDE() throws IOException, ParseException, SAXException, URISyntaxException {
|
||||
RepoDescriptor site = loader.load(new URI(
|
||||
"https://archive.apache.org/dist/ant/ivyde/updatesite/"));
|
||||
public void testIvyDE() throws Exception {
|
||||
URI uri = new URI("https://archive.apache.org/dist/ant/ivyde/updatesite/");
|
||||
try {
|
||||
uri.toURL().getContent();
|
||||
} catch (Exception e) {
|
||||
assumeNoException(e);
|
||||
}
|
||||
RepoDescriptor site = loader.load(uri);
|
||||
assertTrue(site.getModules().hasNext());
|
||||
Iterator<ModuleDescriptorWrapper> it = site.getModules();
|
||||
while (it.hasNext()) {
|
||||
|
|
@ -73,19 +78,16 @@ public class UpdateSiteLoaderTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Ignore // download site seems to have changed
|
||||
@Ignore("download site seems to have changed")
|
||||
@Test
|
||||
public void testM2Eclipse() throws IOException, ParseException, SAXException,
|
||||
URISyntaxException {
|
||||
RepoDescriptor site = loader.load(new URI(
|
||||
"https://download.eclipse.org/technology/m2e/releases/"));
|
||||
public void testM2Eclipse() throws Exception {
|
||||
RepoDescriptor site = loader.load(new URI("https://download.eclipse.org/technology/m2e/releases/"));
|
||||
assertTrue(CollectionUtils.toList(site.getModules()).size() > 20);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testHeliosEclipse() throws IOException, ParseException, SAXException,
|
||||
URISyntaxException {
|
||||
public void testHeliosEclipse() throws Exception {
|
||||
RepoDescriptor site = loader.load(new URI("https://download.eclipse.org/releases/helios/"));
|
||||
assertTrue(CollectionUtils.toList(site.getModules()).size() > 900);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
package org.apache.ivy.plugins.resolver;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.ivy.TestHelper;
|
||||
import org.apache.ivy.core.IvyContext;
|
||||
import org.apache.ivy.core.event.EventManager;
|
||||
|
|
@ -37,6 +39,7 @@ import org.apache.ivy.core.settings.IvySettings;
|
|||
import org.apache.ivy.core.sort.SortEngine;
|
||||
import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
|
||||
import org.apache.ivy.util.MockMessageLogger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -44,6 +47,7 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
|
||||
public class BintrayResolverTest extends AbstractDependencyResolverTest {
|
||||
|
||||
|
|
@ -136,17 +140,20 @@ public class BintrayResolverTest extends AbstractDependencyResolverTest {
|
|||
|
||||
@Test
|
||||
public void testBintray() throws Exception {
|
||||
try {
|
||||
new URL("https://jcenter.bintray.com/").getContent();
|
||||
} catch (Exception e) {
|
||||
assumeNoException(e);
|
||||
}
|
||||
|
||||
BintrayResolver resolver = new BintrayResolver();
|
||||
resolver.setSettings(settings);
|
||||
ModuleRevisionId mrid = ModuleRevisionId
|
||||
.newInstance("org.apache.ant", "ant-antunit", "1.2");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
|
||||
false), data);
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ant", "ant-antunit", "1.2");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
|
||||
assertNotNull(rmr);
|
||||
assertEquals(mrid, rmr.getId());
|
||||
|
||||
DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(),
|
||||
"ant-antunit", "jar", "jar");
|
||||
DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "jar", "jar");
|
||||
DownloadReport report = resolver.download(new Artifact[] {artifact}, downloadOptions());
|
||||
assertNotNull(report);
|
||||
|
||||
|
|
@ -184,42 +191,38 @@ public class BintrayResolverTest extends AbstractDependencyResolverTest {
|
|||
MockMessageLogger mockMessageImpl = new MockMessageLogger();
|
||||
IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockMessageImpl);
|
||||
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "commons-fileupload",
|
||||
"1.0");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
|
||||
false), data);
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "commons-fileupload", "1.0");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
|
||||
assertNull(rmr);
|
||||
|
||||
mockMessageImpl
|
||||
.assertLogContains("trying https://dl.bintray.com/unknown/unknown/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
|
||||
mockMessageImpl
|
||||
.assertLogContains("tried https://dl.bintray.com/unknown/unknown/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
|
||||
mockMessageImpl.assertLogContains("trying https://dl.bintray.com/unknown/unknown/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
|
||||
mockMessageImpl.assertLogContains("tried https://dl.bintray.com/unknown/unknown/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBintrayArtifacts() throws Exception {
|
||||
try {
|
||||
new URL("https://jcenter.bintray.com/").getContent();
|
||||
} catch (Exception e) {
|
||||
assumeNoException(e);
|
||||
}
|
||||
|
||||
BintrayResolver resolver = new BintrayResolver();
|
||||
resolver.setName("test");
|
||||
resolver.setSettings(settings);
|
||||
assertEquals("test", resolver.getName());
|
||||
|
||||
ModuleRevisionId mrid = ModuleRevisionId
|
||||
.newInstance("org.apache.ant", "ant-antunit", "1.2");
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ant", "ant-antunit", "1.2");
|
||||
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false);
|
||||
dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(),
|
||||
"ant-antunit", "javadoc", "jar"), ExactPatternMatcher.INSTANCE, null));
|
||||
dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(),
|
||||
"ant-antunit", "sources", "jar"), ExactPatternMatcher.INSTANCE, null));
|
||||
dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "javadoc", "jar"), ExactPatternMatcher.INSTANCE, null));
|
||||
dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "sources", "jar"), ExactPatternMatcher.INSTANCE, null));
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(dd, data);
|
||||
assertNotNull(rmr);
|
||||
assertEquals(mrid, rmr.getId());
|
||||
|
||||
DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(),
|
||||
"ant-antunit", "javadoc", "jar");
|
||||
DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit",
|
||||
"sources", "jar");
|
||||
DownloadReport report = resolver.download(new Artifact[] {profiler, trace},
|
||||
downloadOptions());
|
||||
DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "javadoc", "jar");
|
||||
DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "sources", "jar");
|
||||
DownloadReport report = resolver.download(new Artifact[] {profiler, trace}, downloadOptions());
|
||||
assertNotNull(report);
|
||||
|
||||
assertEquals(2, report.getArtifactsReports().length);
|
||||
|
|
@ -261,9 +264,7 @@ public class BintrayResolverTest extends AbstractDependencyResolverTest {
|
|||
resolver.setName("test");
|
||||
resolver.setSettings(settings);
|
||||
|
||||
assertNull(resolver.getDependency(
|
||||
new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("unknown", "unknown",
|
||||
"1.0"), false), data));
|
||||
assertNull(resolver.getDependency(new DefaultDependencyDescriptor(
|
||||
ModuleRevisionId.newInstance("unknown", "unknown", "1.0"), false), data));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,7 @@
|
|||
*/
|
||||
package org.apache.ivy.plugins.resolver;
|
||||
|
||||
import static org.apache.ivy.plugins.resolver.IBiblioResolver.DEFAULT_M2_ROOT;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -46,15 +40,19 @@ import org.apache.ivy.core.search.RevisionEntry;
|
|||
import org.apache.ivy.core.settings.IvySettings;
|
||||
import org.apache.ivy.core.sort.SortEngine;
|
||||
import org.apache.ivy.util.MockMessageLogger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
|
||||
public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
||||
// remote.test
|
||||
|
||||
private IvySettings settings;
|
||||
|
||||
|
|
@ -79,23 +77,19 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
@Test
|
||||
public void testDefaults() {
|
||||
IBiblioResolver resolver = new IBiblioResolver();
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.root",
|
||||
"http://www.ibiblio.org/mymaven/");
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.pattern",
|
||||
"[module]/jars/[artifact]-[revision].jar");
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.root", "http://www.ibiblio.org/mymaven/");
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.pattern", "[module]/jars/[artifact]-[revision].jar");
|
||||
resolver.setSettings(settings);
|
||||
List<String> l = resolver.getArtifactPatterns();
|
||||
assertNotNull(l);
|
||||
assertEquals(1, l.size());
|
||||
assertEquals("http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar",
|
||||
l.get(0));
|
||||
assertEquals("http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar", l.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitFromConf() throws Exception {
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.root", "http://www.ibiblio.org/maven/");
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.pattern",
|
||||
"[module]/jars/[artifact]-[revision].jar");
|
||||
settings.setVariable("ivy.ibiblio.default.artifact.pattern", "[module]/jars/[artifact]-[revision].jar");
|
||||
settings.setVariable("my.ibiblio.root", "http://www.ibiblio.org/mymaven/");
|
||||
settings.setVariable("my.ibiblio.pattern", "[module]/[artifact]-[revision].jar");
|
||||
settings.load(IBiblioResolverTest.class.getResource("ibiblioresolverconf.xml"));
|
||||
|
|
@ -111,8 +105,7 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
l = resolver.getArtifactPatterns();
|
||||
assertNotNull(l);
|
||||
assertEquals(1, l.size());
|
||||
assertEquals("http://www.ibiblio.org/mymaven/[organisation]/jars/[artifact]-[revision].jar",
|
||||
l.get(0));
|
||||
assertEquals("http://www.ibiblio.org/mymaven/[organisation]/jars/[artifact]-[revision].jar", l.get(0));
|
||||
|
||||
resolver = (IBiblioResolver) settings.getResolver("ibiblioC");
|
||||
assertTrue(resolver.isM2compatible());
|
||||
|
|
@ -120,10 +113,8 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
l = resolver.getArtifactPatterns();
|
||||
assertNotNull(l);
|
||||
assertEquals(1, l.size());
|
||||
assertTrue("Default Maven URL must end with '/'", DEFAULT_M2_ROOT.endsWith("/"));
|
||||
assertEquals(DEFAULT_M2_ROOT
|
||||
+ "[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]",
|
||||
l.get(0));
|
||||
assertTrue("Default Maven URL must end with '/'", IBiblioResolver.DEFAULT_M2_ROOT.endsWith("/"));
|
||||
assertEquals(IBiblioResolver.DEFAULT_M2_ROOT + "[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", l.get(0));
|
||||
|
||||
resolver = (IBiblioResolver) settings.getResolver("ibiblioD");
|
||||
assertFalse(resolver.isM2compatible());
|
||||
|
|
@ -131,8 +122,7 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
l = resolver.getArtifactPatterns();
|
||||
assertNotNull(l);
|
||||
assertEquals(1, l.size());
|
||||
assertEquals("http://www.ibiblio.org/maven/[module]/jars/[artifact]-[revision].jar",
|
||||
l.get(0));
|
||||
assertEquals("http://www.ibiblio.org/maven/[module]/jars/[artifact]-[revision].jar", l.get(0));
|
||||
|
||||
resolver = (IBiblioResolver) settings.getResolver("ibiblioE");
|
||||
assertTrue(resolver.isM2compatible());
|
||||
|
|
@ -140,9 +130,7 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
l = resolver.getArtifactPatterns();
|
||||
assertNotNull(l);
|
||||
assertEquals(1, l.size());
|
||||
assertEquals(
|
||||
"http://www.ibiblio.org/mymaven/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]",
|
||||
l.get(0));
|
||||
assertEquals("http://www.ibiblio.org/mymaven/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", l.get(0));
|
||||
|
||||
resolver = (IBiblioResolver) settings.getResolver("ibiblioF");
|
||||
assertTrue(resolver.isM2compatible());
|
||||
|
|
@ -150,12 +138,9 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
l = resolver.getArtifactPatterns();
|
||||
assertNotNull(l);
|
||||
assertEquals(1, l.size());
|
||||
assertEquals(
|
||||
"http://www.ibiblio.org/mymaven/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]",
|
||||
l.get(0));
|
||||
assertEquals("http://www.ibiblio.org/mymaven/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", l.get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Test
|
||||
public void testMaven2Listing() {
|
||||
IBiblioResolver resolver = new IBiblioResolver();
|
||||
|
|
@ -164,8 +149,13 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
resolver.setM2compatible(true);
|
||||
assertEquals("test", resolver.getName());
|
||||
|
||||
ModuleEntry[] modules = resolver
|
||||
.listModules(new OrganisationEntry(resolver, "commons-lang"));
|
||||
try {
|
||||
new URL(IBiblioResolver.DEFAULT_M2_ROOT).getContent();
|
||||
} catch (Exception e) {
|
||||
assumeNoException(e);
|
||||
}
|
||||
|
||||
ModuleEntry[] modules = resolver.listModules(new OrganisationEntry(resolver, "commons-lang"));
|
||||
assertNotNull(modules);
|
||||
assertEquals(1, modules.length);
|
||||
assertEquals("commons-lang", modules[0].getModule());
|
||||
|
|
@ -173,17 +163,16 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
RevisionEntry[] revisions = resolver.listRevisions(modules[0]);
|
||||
assertTrue(revisions.length > 0);
|
||||
|
||||
Map otherTokenValues = new HashMap();
|
||||
Map<String, String> otherTokenValues = new HashMap<>();
|
||||
otherTokenValues.put(IvyPatternHelper.ORGANISATION_KEY, "commons-lang");
|
||||
String[] values = resolver.listTokenValues(IvyPatternHelper.MODULE_KEY, otherTokenValues);
|
||||
assertNotNull(values);
|
||||
assertEquals(1, values.length);
|
||||
assertEquals("commons-lang", values[0]);
|
||||
|
||||
Map[] valuesMaps = resolver.listTokenValues(new String[] {IvyPatternHelper.MODULE_KEY},
|
||||
otherTokenValues);
|
||||
Set vals = new HashSet();
|
||||
for (Map valuesMap : valuesMaps) {
|
||||
Map<String, String>[] valuesMaps = resolver.listTokenValues(new String[] {IvyPatternHelper.MODULE_KEY}, Map.class.cast(otherTokenValues));
|
||||
Set<String> vals = new HashSet<>();
|
||||
for (Map<String, String> valuesMap : valuesMaps) {
|
||||
vals.add(valuesMap.get(IvyPatternHelper.MODULE_KEY));
|
||||
}
|
||||
values = (String[]) vals.toArray(new String[vals.size()]);
|
||||
|
|
@ -203,16 +192,11 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
MockMessageLogger mockMessageImpl = new MockMessageLogger();
|
||||
IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockMessageImpl);
|
||||
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "commons-fileupload",
|
||||
"1.0");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
|
||||
false), data);
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "commons-fileupload", "1.0");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
|
||||
assertNull(rmr);
|
||||
|
||||
mockMessageImpl
|
||||
.assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.pom");
|
||||
mockMessageImpl
|
||||
.assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
|
||||
mockMessageImpl.assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.pom");
|
||||
mockMessageImpl.assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
package org.apache.ivy.plugins.resolver;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.ivy.TestHelper;
|
||||
import org.apache.ivy.core.event.EventManager;
|
||||
import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
|
||||
|
|
@ -28,6 +30,7 @@ import org.apache.ivy.core.resolve.ResolvedModuleRevision;
|
|||
import org.apache.ivy.core.settings.IvySettings;
|
||||
import org.apache.ivy.core.settings.XmlSettingsParser;
|
||||
import org.apache.ivy.core.sort.SortEngine;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -35,6 +38,7 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
|
||||
public class MirroredURLResolverTest {
|
||||
|
||||
|
|
@ -49,16 +53,14 @@ public class MirroredURLResolverTest {
|
|||
settings = new IvySettings();
|
||||
engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
|
||||
data = new ResolveData(engine, new ResolveOptions());
|
||||
|
||||
TestHelper.createCache();
|
||||
settings.setDefaultCache(TestHelper.cache);
|
||||
settings.setVariable("test.mirroredurl.mirrorlist-solo.url",
|
||||
this.getClass().getResource("mirrorlist-solo.txt").toExternalForm());
|
||||
settings.setVariable("test.mirroredurl.mirrorlist-failover.url", this.getClass()
|
||||
.getResource("mirrorlist-failover.txt").toExternalForm());
|
||||
settings.setVariable("test.mirroredurl.mirrorlist-fail.url",
|
||||
this.getClass().getResource("mirrorlist-fail.txt").toExternalForm());
|
||||
new XmlSettingsParser(settings).parse(MirroredURLResolverTest.class
|
||||
.getResource("mirror-resolver-settings.xml"));
|
||||
settings.setVariable("test.mirroredurl.mirrorlist-solo.url", getClass().getResource("mirrorlist-solo.txt").toExternalForm());
|
||||
settings.setVariable("test.mirroredurl.mirrorlist-failover.url", getClass().getResource("mirrorlist-failover.txt").toExternalForm());
|
||||
settings.setVariable("test.mirroredurl.mirrorlist-fail.url", getClass().getResource("mirrorlist-fail.txt").toExternalForm());
|
||||
|
||||
new XmlSettingsParser(settings).parse(getClass().getResource("mirror-resolver-settings.xml"));
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
@ -69,40 +71,42 @@ public class MirroredURLResolverTest {
|
|||
@Test
|
||||
public void testSolo() throws Exception {
|
||||
DependencyResolver resolver = settings.getResolver("solo");
|
||||
assertNotNull(resolver);
|
||||
assertTrue(resolver instanceof MirroredURLResolver);
|
||||
MirroredURLResolver mirrored = (MirroredURLResolver) resolver;
|
||||
|
||||
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
|
||||
ModuleRevisionId.newInstance("commons-lang", "commons-lang", "2.4"), false);
|
||||
ResolvedModuleRevision rmr = mirrored.getDependency(dd, data);
|
||||
try {
|
||||
new URL("https://repo1.maven.org/maven2/").getContent();
|
||||
} catch (Exception e) {
|
||||
assumeNoException(e);
|
||||
}
|
||||
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("commons-lang", "commons-lang", "2.4");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
|
||||
assertNotNull(rmr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailover() throws Exception {
|
||||
DependencyResolver resolver = settings.getResolver("failover");
|
||||
assertNotNull(resolver);
|
||||
assertTrue(resolver instanceof MirroredURLResolver);
|
||||
MirroredURLResolver mirrored = (MirroredURLResolver) resolver;
|
||||
|
||||
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
|
||||
ModuleRevisionId.newInstance("commons-lang", "commons-lang", "2.4"), false);
|
||||
ResolvedModuleRevision rmr = mirrored.getDependency(dd, data);
|
||||
try {
|
||||
new URL("https://repo1.maven.org/maven2/").getContent();
|
||||
} catch (Exception e) {
|
||||
assumeNoException(e);
|
||||
}
|
||||
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("commons-lang", "commons-lang", "2.4");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
|
||||
assertNotNull(rmr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFail() throws Exception {
|
||||
DependencyResolver resolver = settings.getResolver("fail");
|
||||
assertNotNull(resolver);
|
||||
assertTrue(resolver instanceof MirroredURLResolver);
|
||||
MirroredURLResolver mirrored = (MirroredURLResolver) resolver;
|
||||
|
||||
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
|
||||
ModuleRevisionId.newInstance("commons-lang", "commons-lang", "2.4"), false);
|
||||
ResolvedModuleRevision rmr = mirrored.getDependency(dd, data);
|
||||
ModuleRevisionId mrid = ModuleRevisionId.newInstance("commons-lang", "commons-lang", "2.4");
|
||||
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
|
||||
assertNull(rmr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,11 +30,8 @@ import static org.junit.Assert.assertFalse;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
/**
|
||||
* Test BasicURLHandler
|
||||
*/
|
||||
public class BasicURLHandlerTest {
|
||||
// remote.test
|
||||
public class BasicURLHandlerTest { // remote.test
|
||||
|
||||
private File testDir;
|
||||
|
||||
private BasicURLHandler handler;
|
||||
|
|
@ -55,35 +52,28 @@ public class BasicURLHandlerTest {
|
|||
@Test
|
||||
public void testIsReachable() throws Exception {
|
||||
final int connectionTimeoutInMillis = 15000; // 15 seconds
|
||||
assertTrue(handler.isReachable(new URL("http://www.google.fr/"), connectionTimeoutInMillis));
|
||||
assumeTrue(handler.isReachable(new URL("http://www.google.fr/"), connectionTimeoutInMillis));
|
||||
assertFalse(handler.isReachable(new URL("http://www.google.fr/unknownpage.html"), connectionTimeoutInMillis));
|
||||
|
||||
assertTrue(handler.isReachable(new File("build.xml").toURI().toURL(), connectionTimeoutInMillis));
|
||||
assertFalse(handler.isReachable(new File("unknownfile.xml").toURI().toURL(), connectionTimeoutInMillis));
|
||||
|
||||
// to test ftp we should know of an anonymous ftp site... !
|
||||
// assertTrue(handler.isReachable(new URL("ftp://ftp.mozilla.org/pub/dir.sizes")));
|
||||
// to test FTP we should know of an anonymous FTP site
|
||||
//assertTrue(handler.isReachable(new URL("ftp://ftp.mozilla.org/pub/dir.sizes")));
|
||||
assertFalse(handler.isReachable(new URL("ftp://ftp.mozilla.org/unknown.file"), 5000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentEncoding() throws Exception {
|
||||
assumeTrue(handler.isReachable(new URL("http://carsten.codimi.de/"), 5000));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html"), new File(
|
||||
testDir, "gzip.txt"));
|
||||
assertDownloadOK(new URL(
|
||||
"http://carsten.codimi.de/gzip.yaws/daniels.html?deflate=on&zlib=on"), new File(
|
||||
testDir, "deflate-zlib.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html?deflate=on"),
|
||||
new File(testDir, "deflate.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/a5.ps"), new File(testDir,
|
||||
"a5-gzip.ps"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/a5.ps?deflate=on"), new File(
|
||||
testDir, "a5-deflate.ps"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/nh80.pdf"), new File(testDir,
|
||||
"nh80-gzip.pdf"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/nh80.pdf?deflate=on"),
|
||||
new File(testDir, "nh80-deflate.pdf"));
|
||||
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html"), new File(testDir, "gzip.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html?deflate=on&zlib=on"), new File(testDir, "deflate-zlib.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html?deflate=on"), new File(testDir, "deflate.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/a5.ps"), new File(testDir, "a5-gzip.ps"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/a5.ps?deflate=on"), new File(testDir, "a5-deflate.ps"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/nh80.pdf"), new File(testDir, "nh80-gzip.pdf"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/nh80.pdf?deflate=on"), new File(testDir, "nh80-deflate.pdf"));
|
||||
}
|
||||
|
||||
private void assertDownloadOK(URL url, File file) throws Exception {
|
||||
|
|
|
|||
|
|
@ -44,9 +44,8 @@ import static org.junit.Assert.assertThrows;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
public class HttpClientHandlerTest {
|
||||
public class HttpClientHandlerTest { // remote.test
|
||||
|
||||
// remote.test
|
||||
private File testDir;
|
||||
|
||||
private HttpClientHandler handler;
|
||||
|
|
@ -60,8 +59,9 @@ public class HttpClientHandlerTest {
|
|||
|
||||
handler = new HttpClientHandler();
|
||||
|
||||
defaultTimeoutConstraint = new NamedTimeoutConstraint("default-http-client-handler-timeout");
|
||||
((NamedTimeoutConstraint) defaultTimeoutConstraint).setConnectionTimeout(5000);
|
||||
NamedTimeoutConstraint constraint = new NamedTimeoutConstraint("default-http-client-handler-timeout");
|
||||
constraint.setConnectionTimeout(5000);
|
||||
defaultTimeoutConstraint = constraint;
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
@ -75,10 +75,8 @@ public class HttpClientHandlerTest {
|
|||
|
||||
@Test
|
||||
public void testIsReachable() throws Exception {
|
||||
assertTrue("URL resource was expected to be reachable",
|
||||
handler.isReachable(new URL("http://www.google.fr/"), defaultTimeoutConstraint));
|
||||
assertFalse("URL resource was expected to be unreachable",
|
||||
handler.isReachable(new URL("http://www.google.fr/unknownpage.html"), defaultTimeoutConstraint));
|
||||
assumeTrue("URL resource was expected to be reachable", handler.isReachable(new URL("http://www.google.fr/"), defaultTimeoutConstraint));
|
||||
assertFalse("URL resource was expected to be unreachable", handler.isReachable(new URL("http://www.google.fr/unknownpage.html"), defaultTimeoutConstraint));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,35 +84,26 @@ public class HttpClientHandlerTest {
|
|||
*
|
||||
* @see <a href="https://issues.apache.org/jira/browse/IVY-390">IVY-390</a>
|
||||
*/
|
||||
@SuppressWarnings({"resource", "deprecation"})
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testGetURLInfo() throws Exception {
|
||||
final TimeoutConstrainedURLHandler handler = new HttpClientHandler();
|
||||
assertTrue("Default Maven URL must end with '/'", DEFAULT_M2_ROOT.endsWith("/"));
|
||||
URLInfo info = handler.getURLInfo(new URL(DEFAULT_M2_ROOT
|
||||
+ "commons-lang/commons-lang/[1.0,3.0[/commons-lang-[1.0,3.0[.pom"), defaultTimeoutConstraint);
|
||||
|
||||
assertEquals(TimeoutConstrainedURLHandler.UNAVAILABLE, info);
|
||||
try (HttpClientHandler handler = new HttpClientHandler()) {
|
||||
assertTrue("Default Maven URL must end with '/'", DEFAULT_M2_ROOT.endsWith("/"));
|
||||
URLInfo info = handler.getURLInfo(new URL(DEFAULT_M2_ROOT + "commons-lang/commons-lang/[1.0,3.0[/commons-lang-[1.0,3.0[.pom"), defaultTimeoutConstraint);
|
||||
assertEquals(URLHandler.UNAVAILABLE, info);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentEncoding() throws Exception {
|
||||
assumeTrue(handler.isReachable(new URL("http://carsten.codimi.de/"), 5000));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html"), new File(
|
||||
testDir, "gzip.txt"));
|
||||
assertDownloadOK(new URL(
|
||||
"http://carsten.codimi.de/gzip.yaws/daniels.html?deflate=on&zlib=on"), new File(
|
||||
testDir, "deflate-zlib.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html?deflate=on"),
|
||||
new File(testDir, "deflate.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/a5.ps"), new File(testDir,
|
||||
"a5-gzip.ps"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/a5.ps?deflate=on"), new File(
|
||||
testDir, "a5-deflate.ps"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/nh80.pdf"), new File(testDir,
|
||||
"nh80-gzip.pdf"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/nh80.pdf?deflate=on"),
|
||||
new File(testDir, "nh80-deflate.pdf"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html"), new File(testDir, "gzip.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html?deflate=on&zlib=on"), new File(testDir, "deflate-zlib.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/daniels.html?deflate=on"), new File(testDir, "deflate.txt"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/a5.ps"), new File(testDir, "a5-gzip.ps"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/a5.ps?deflate=on"), new File(testDir, "a5-deflate.ps"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/nh80.pdf"), new File(testDir, "nh80-gzip.pdf"));
|
||||
assertDownloadOK(new URL("http://carsten.codimi.de/gzip.yaws/nh80.pdf?deflate=on"), new File(testDir, "nh80-deflate.pdf"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,8 +132,7 @@ public class HttpClientHandlerTest {
|
|||
|
||||
final File target = new File(testDir, "downloaded.xml");
|
||||
assertFalse("File " + target + " already exists", target.exists());
|
||||
final URL src = new URL("http://localhost:" + serverBindAddr.getPort() + "/"
|
||||
+ contextRoot + "/ivysettings.xml");
|
||||
final URL src = new URL("http://localhost:" + serverBindAddr.getPort() + "/" + contextRoot + "/ivysettings.xml");
|
||||
// download it
|
||||
handler.download(src, target, null, defaultTimeoutConstraint);
|
||||
assertTrue("File " + target + " was not downloaded from " + src, target.isFile());
|
||||
|
|
@ -157,8 +145,7 @@ public class HttpClientHandlerTest {
|
|||
|
||||
final File target = new File(testDir, "should-not-have-been-downloaded.xml");
|
||||
assertFalse("File " + target + " already exists", target.exists());
|
||||
final URL src = new URL("http://localhost:" + serverBindAddr.getPort() + "/"
|
||||
+ contextRoot + "/ivysettings.xml");
|
||||
final URL src = new URL("http://localhost:" + serverBindAddr.getPort() + "/" + contextRoot + "/ivysettings.xml");
|
||||
// download it (expected to fail)
|
||||
Exception exception = assertThrows(IOException.class, () -> handler.download(src, target, null, defaultTimeoutConstraint));
|
||||
// we catch it and check for presence of 401 in the exception message.
|
||||
|
|
@ -172,7 +159,6 @@ public class HttpClientHandlerTest {
|
|||
private void assertDownloadOK(final URL url, final File file) throws Exception {
|
||||
handler.download(url, file, null, defaultTimeoutConstraint);
|
||||
assertTrue("Content from " + url + " wasn't downloaded to " + file, file.exists());
|
||||
assertTrue("Unexpected content at " + file + " for resource that was downloaded from "
|
||||
+ url, file.isFile() && file.length() > 0);
|
||||
assertTrue("Unexpected content at " + file + " for resource that was downloaded from " + url, file.isFile() && file.length() > 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue