Search in sources :

Example 6 with TestDownload

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));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 7 with TestDownload

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"));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Document(org.w3c.dom.Document) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 8 with TestDownload

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"));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 9 with TestDownload

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);
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 10 with TestDownload

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);
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) OutputStream(java.io.OutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Aggregations

TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)16 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 Test (org.junit.Test)15 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)11 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)11 Transfer (org.commonjava.maven.galley.model.Transfer)11 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)8 Location (org.commonjava.maven.galley.model.Location)7 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)7 URI (java.net.URI)5 LinkedHashMap (java.util.LinkedHashMap)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)5 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)5 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)3 ProjectRelationship (org.commonjava.maven.atlas.graph.rel.ProjectRelationship)3 PluginView (org.commonjava.maven.galley.maven.model.view.PluginView)3 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)2 RepositoryLocation (org.commonjava.indy.model.galley.RepositoryLocation)2 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)2 Document (org.w3c.dom.Document)2