use of org.apache.ivy.plugins.repository.AbstractRepository in project ant-ivy by apache.
the class ResolveTest method testUseCacheOnly.
@Test
public void testUseCacheOnly() throws Exception {
ResolveOptions option = getResolveOptions(new String[] { "*" }).setValidate(false);
URL url = new File("test/repositories/1/usecacheonly/mod1/ivys/ivy-1.0.xml").toURI().toURL();
// normal resolve, the file goes in the cache
ResolveReport report = ivy.resolve(url, option);
assertFalse(report.hasError());
option.setUseCacheOnly(true);
// use cache only, hit the cache
report = ivy.resolve(url, option);
assertFalse(report.hasError());
CacheCleaner.deleteDir(cache);
createCache();
// no more in the cache, missed
report = ivy.resolve(url, option);
assertTrue(report.hasError());
option.setUseCacheOnly(false);
// try with use origin: should fail as the cache is empty
ivy.getSettings().setDefaultUseOrigin(true);
option.setUseCacheOnly(true);
report = ivy.resolve(url, option);
assertTrue(report.hasError());
// populate the cache
option.setUseCacheOnly(false);
report = ivy.resolve(url, option);
assertFalse(report.hasError());
// use origin should now work
option.setUseCacheOnly(true);
report = ivy.resolve(url, option);
assertFalse(report.hasError());
// ensure that we hit only the cache and never try to hit in the repository
FileSystemResolver resolver = (FileSystemResolver) ivy.getSettings().getResolver("1");
resolver.setRepository(new AbstractRepository() {
public List<String> list(String parent) {
throw new UnsupportedOperationException();
}
public Resource getResource(String source) {
throw new UnsupportedOperationException();
}
public void get(String source, File destination) {
throw new UnsupportedOperationException();
}
});
report = ivy.resolve(url, option);
assertFalse(report.hasError());
}
Aggregations