Search in sources :

Example 56 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class ManagedDefaultTransferTest method testGetWhenInBothProxiedRepos.

@Test
public void testGetWhenInBothProxiedRepos() throws Exception {
    String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
    assertNotExistsInManagedDefaultRepo(expectedFile);
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, false);
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED2, false);
    // Attempt the proxy fetch.
    Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
    assertFileEquals(expectedFile, downloadedFile, proxied1File);
    assertNoTempFiles(expectedFile);
    // TODO: is this check even needed if it passes above?
    String actualContents = FileUtils.readFileToString(downloadedFile.toFile(), Charset.defaultCharset());
    String badContents = FileUtils.readFileToString(proxied2File.toFile(), Charset.defaultCharset());
    assertFalse("Downloaded file contents should not be that of proxy 2", StringUtils.equals(actualContents, badContents));
}
Also used : Path(java.nio.file.Path) ArtifactReference(org.apache.archiva.model.ArtifactReference) Test(org.junit.Test)

Example 57 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class ManagedDefaultTransferTest method testGetDefaultLayoutAlreadyPresentPolicyOnce.

/**
 * The attempt here should result in no file being transferred.
 * <p/>
 * The file exists locally, and the policy is ONCE.
 *
 * @throws Exception
 */
@Test
public void testGetDefaultLayoutAlreadyPresentPolicyOnce() throws Exception {
    String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
    assertTrue(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE, CachedFailuresPolicy.NO, false);
    // Attempt the proxy fetch.
    Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
    assertFileEquals(expectedFile, downloadedFile, expectedFile);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) ArtifactReference(org.apache.archiva.model.ArtifactReference) Test(org.junit.Test)

Example 58 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class ManagedDefaultTransferTest method testGetAllRepositoriesFail.

@Test
public void testGetAllRepositoriesFail() throws Exception {
    String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
    assertNotExistsInManagedDefaultRepo(expectedFile);
    // Configure Repository (usually done within archiva.xml configuration)
    saveRemoteRepositoryConfig("badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default");
    saveRemoteRepositoryConfig("badproxied2", "Bad Proxied 2", "test://dead.machine.com/repo/", "default");
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "badproxied1", false);
    saveConnector(ID_DEFAULT_MANAGED, "badproxied2", false);
    Path tmpFile = expectedFile.getParent().resolve(expectedFile.getFileName() + ".tmp");
    wagonMock.get(EasyMock.eq(path), EasyMock.anyObject(File.class));
    EasyMock.expectLastCall().andThrow(new ResourceDoesNotExistException("Can't find resource."));
    wagonMock.get(EasyMock.eq(path), EasyMock.anyObject(File.class));
    EasyMock.expectLastCall().andThrow(new ResourceDoesNotExistException("Can't find resource."));
    wagonMockControl.replay();
    Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
    assertNotDownloaded(downloadedFile);
    wagonMockControl.verify();
    assertNoTempFiles(expectedFile);
// TODO: do not want failures to present as a not found [MRM-492]
// TODO: How much information on each failure should we pass back to the user vs. logging in the proxy?
}
Also used : Path(java.nio.file.Path) ArtifactReference(org.apache.archiva.model.ArtifactReference) File(java.io.File) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) Test(org.junit.Test)

Example 59 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class ManagedDefaultTransferTest method testGetDefaultLayoutAlreadyPresentOlderThanRemotePolicyIgnored.

/**
 * <p>
 * Request a file, that exists locally, and remotely.
 * </p>
 * <p>
 * All policies are set to IGNORE.
 * </p>
 * <p>
 * Managed file is older than Remote file.
 * </p>
 * <p>
 * Transfer should have occured, as managed file is older than remote.
 * </p>
 *
 * @throws Exception
 */
@Test
public void testGetDefaultLayoutAlreadyPresentOlderThanRemotePolicyIgnored() throws Exception {
    String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
    // Set the managed file to be newer than remote file.
    setManagedOlderThanRemote(expectedFile, remoteFile);
    ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
    assertTrue(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    // Attempt the proxy fetch.
    Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
    Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile, proxiedFile);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) ArtifactReference(org.apache.archiva.model.ArtifactReference) Test(org.junit.Test)

Example 60 with ArtifactReference

use of org.apache.archiva.model.ArtifactReference in project archiva by apache.

the class ManagedDefaultTransferTest method testNotFoundInAnyProxies.

@Test
public void testNotFoundInAnyProxies() throws Exception {
    String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
    assertNotExistsInManagedDefaultRepo(expectedFile);
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, false);
    saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED2, false);
    // Attempt the proxy fetch.
    Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
    assertNull("File returned was: " + downloadedFile + "; should have got a not found exception", downloadedFile);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) ArtifactReference(org.apache.archiva.model.ArtifactReference) Test(org.junit.Test)

Aggregations

ArtifactReference (org.apache.archiva.model.ArtifactReference)77 Path (java.nio.file.Path)62 Test (org.junit.Test)50 LayoutException (org.apache.archiva.repository.LayoutException)13 IOException (java.io.IOException)10 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)9 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)8 RepositoryException (org.apache.archiva.repository.RepositoryException)8 VersionedReference (org.apache.archiva.model.VersionedReference)7 File (java.io.File)5 Date (java.util.Date)5 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)5 RepositoryTask (org.apache.archiva.scheduler.repository.model.RepositoryTask)5 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)4 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)4 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)4 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)4