use of org.commonjava.maven.galley.testing.core.transport.job.TestDownload in project indy by Commonjava.
the class DownloadManagerTest method downloadOnePOMFromSecondRepositoryAfterDummyRepoFails.
@Test
public void downloadOnePOMFromSecondRepositoryAfterDummyRepoFails() throws Exception {
final RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "dummy", "http://www.nowhere.com/");
final String content = "This is a test";
final String path = "/org/apache/maven/maven-model/3.0.3/maven-model-3.0.3.pom";
final RemoteRepository repo2 = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
fixture.getTransport().registerDownload(new ConcreteResource(new RepositoryLocation(repo2), path), new TestDownload(content.getBytes()));
data.storeArtifactStore(repo, summary, false, true, new EventMetadata());
data.storeArtifactStore(repo2, summary, false, true, new EventMetadata());
final List<ArtifactStore> repos = new ArrayList<ArtifactStore>();
repos.add(repo);
repos.add(repo2);
final Transfer stream = downloader.retrieveFirst(repos, path, new EventMetadata());
final String downloaded = IOUtils.toString(stream.openInputStream());
assertThat(downloaded, equalTo(content));
}
use of org.commonjava.maven.galley.testing.core.transport.job.TestDownload in project galley by Commonjava.
the class ArtifactManagerImplTest method resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy.
@Test
public void resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy() throws Exception {
final String base = "2-snapshots-1-location/";
final String testResource = base + "two-snapshots.xml";
final String testPomResource = base + "two-snapshots-pom.xml";
final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group2", "artifact", "1.0-SNAPSHOT");
final ConcreteResource metadataResource = new ConcreteResource(LOCATION, fixture.snapshotMetadataPath(ref));
final ConcreteResource pomResource = new ConcreteResource(LOCATION, fixture.pomPath(ref.selectVersion("1.0-20140604.102909-1").asPomArtifact()));
fixture.getTransport().registerDownload(metadataResource, new TestDownload(ROOT + testResource));
fixture.getTransport().registerDownload(pomResource, new TestDownload(ROOT + testPomResource));
final Transfer retrieved = fixture.getArtifactManager().retrieve(LOCATION, ref.asPomArtifact(), new EventMetadata());
final Document document = fixture.getXml().parse(retrieved, new EventMetadata());
final ProjectVersionRef result = fixture.getXml().getProjectVersionRef(document);
System.out.println(result);
assertThat(result, notNullValue());
assertThat(result.getVersionString(), equalTo("1.0-20140604.102909-1"));
}
use of org.commonjava.maven.galley.testing.core.transport.job.TestDownload in project galley by Commonjava.
the class VersionResolverImplTest method resolveSnapshot_FirstMatch_SingletonLocationList_SingletonSnapshotList_LatestVersionStrategy.
@Test
public void resolveSnapshot_FirstMatch_SingletonLocationList_SingletonSnapshotList_LatestVersionStrategy() throws Exception {
final String testResource = "single-snapshot/single-snapshot.xml";
final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group", "artifact", "1.0-SNAPSHOT");
final ConcreteResource cr = new ConcreteResource(LOCATION, fixture.snapshotMetadataPath(ref));
final TestDownload download = new TestDownload(ROOT + testResource);
fixture.getTransport().registerDownload(cr, download);
final ProjectVersionRef result = fixture.getVersionResolver().resolveFirstMatchVariableVersion(ONE_LOCATION, ref, LatestVersionSelectionStrategy.INSTANCE, new EventMetadata());
assertThat(result, notNullValue());
assertThat(result.getVersionString(), equalTo("1.0-20140604.101244-1"));
}
use of org.commonjava.maven.galley.testing.core.transport.job.TestDownload in project galley by Commonjava.
the class AbstractTransferManagerTest method retrieve_cacheIfMissing.
/**
* Test that remote content will be downloaded then cached.
*/
@Test
public void retrieve_cacheIfMissing() throws Exception {
final String testContent = "This is a test " + System.currentTimeMillis();
final Location loc = new SimpleLocation("file:///test-repo");
final String path = "/path/to/test.txt";
final ConcreteResource resource = new ConcreteResource(loc, path);
// put in the content that we want to "download"
getTransport().registerDownload(resource, new TestDownload(testContent.getBytes()));
// now, use the manager to retrieve() the path...the remote content should come through here.
Transfer transfer = getTransferManagerImpl().retrieve(resource);
assertTransferContent(transfer, testContent);
// now, the right content should be cached.
// So, we'll put in some wrong content that will cause problems if the cache isn't used.
getTransport().registerDownload(resource, new TestDownload("This is WRONG".getBytes()));
// now, use the manager to retrieve() the path again...the cached content should come through here.
transfer = getTransferManagerImpl().retrieve(resource);
assertTransferContent(transfer, testContent);
}
use of org.commonjava.maven.galley.testing.core.transport.job.TestDownload in project galley by Commonjava.
the class AbstractTransferManagerTest method retrieve_preferCachedCopy.
/**
* Test that cached content will be used...if not, this test will fail, as
* the wrong content is registered with the test transport.
*/
@Test
public void retrieve_preferCachedCopy() throws Exception {
final String testContent = "This is a test " + System.currentTimeMillis();
final Location loc = new SimpleLocation("file:///test-repo");
final String path = "/path/to/test.txt";
final ConcreteResource resource = new ConcreteResource(loc, path);
// put in some wrong content that will cause problems if the cache isn't used.
getTransport().registerDownload(resource, new TestDownload("This is WRONG".getBytes()));
// seed the cache with the file we're trying to retrieve.
OutputStream os = null;
try {
os = getCacheProvider().openOutputStream(resource);
os.write(testContent.getBytes());
} finally {
closeQuietly(os);
}
// now, use the manager to retrieve() the path...the cached content should come through here.
final Transfer transfer = getTransferManagerImpl().retrieve(resource);
assertTransferContent(transfer, testContent);
}
Aggregations