Search in sources :

Example 16 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class HttpProxyTransferTest method testGetOverHttpProxy.

@Test
public void testGetOverHttpProxy() throws Exception {
    assertTrue(StringUtils.isEmpty(System.getProperty("http.proxyHost", "")));
    assertTrue(StringUtils.isEmpty(System.getProperty("http.proxyPort", "")));
    String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
    // Configure Connector (usually done within archiva.xml configuration)
    addConnector();
    managedDefaultRepository = repositoryRegistry.getManagedRepository(MANAGED_ID).getContent();
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Path expectedFile = managedDefaultRepository.getRepository().getRoot().resolve(path).getFilePath();
    Files.deleteIfExists(expectedFile);
    Artifact artifact = layout.getArtifact(path);
    // Attempt the proxy fetch.
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path sourceFile = Paths.get(PROXIED_BASEDIR, path);
    assertNotNull("Expected File should not be null.", expectedFile);
    assertNotNull("Actual File should not be null.", downloadedFile);
    assertTrue("Check actual file exists.", Files.exists(downloadedFile.getFilePath()));
    assertTrue("Check filename path is appropriate.", Files.isSameFile(expectedFile, downloadedFile.getFilePath()));
    assertTrue("Check file path matches.", Files.isSameFile(expectedFile, downloadedFile.getFilePath()));
    String expectedContents = FileUtils.readFileToString(sourceFile.toFile(), Charset.defaultCharset());
    String actualContents = FileUtils.readFileToString(downloadedFile.getFilePath().toFile(), Charset.defaultCharset());
    assertEquals("Check file contents.", expectedContents, actualContents);
    assertTrue(StringUtils.isEmpty(System.getProperty("http.proxyHost", "")));
    assertTrue(StringUtils.isEmpty(System.getProperty("http.proxyPort", "")));
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 17 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class ManagedDefaultTransferTest method testGetDefaultLayoutNotPresent.

@Test
public void testGetDefaultLayoutNotPresent() throws Exception {
    String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    // Ensure file isn't present first.
    assertNotExistsInManagedDefaultRepo(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.
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path sourceFile = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), sourceFile);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 18 with Artifact

use of org.apache.archiva.repository.content.Artifact 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);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    assertNotExistsInManagedDefaultRepo(expectedFile);
    // Configure Repository (usually done within archiva.xml configuration)
    saveRemoteRepositoryConfig("badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default");
    saveRemoteRepositoryConfig("badproxied2", "Bad Proxied 2", "http://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");
    doThrow(new ResourceDoesNotExistException("Can't find resource.")).when(wagonMock).get(eq(path), any());
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    verify(wagonMock, atLeastOnce()).get(eq(path), any());
    assertNotDownloaded(downloadedFile);
    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) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) Test(org.junit.Test)

Example 19 with Artifact

use of org.apache.archiva.repository.content.Artifact in project archiva by apache.

the class ManagedDefaultTransferTest method testGetDefaultLayoutAlreadyPresentNewerThanRemotePolicyIgnored.

/**
 * <p>
 * Request a file, that exists locally, and remotely.
 * </p>
 * <p>
 * All policies are set to IGNORE.
 * </p>
 * <p>
 * Managed file is newer than remote file.
 * </p>
 * <p>
 * Transfer should not have occured, as managed file is newer.
 * </p>
 *
 * @throws Exception
 */
@Test
public void testGetDefaultLayoutAlreadyPresentNewerThanRemotePolicyIgnored() 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 local.
    setManagedNewerThanRemote(expectedFile, remoteFile);
    long originalModificationTime = Files.getLastModifiedTime(expectedFile).toMillis();
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(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.
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    assertNotDownloaded(downloadedFile);
    assertNotModified(expectedFile, originalModificationTime);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 20 with Artifact

use of org.apache.archiva.repository.content.Artifact 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);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(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.
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
    assertNoTempFiles(expectedFile);
    // TODO: is this check even needed if it passes above?
    String actualContents = FileUtils.readFileToString(downloadedFile.getFilePath().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) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Aggregations

Artifact (org.apache.archiva.repository.content.Artifact)78 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)63 Test (org.junit.Test)60 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)59 Path (java.nio.file.Path)54 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)26 ItemSelector (org.apache.archiva.repository.content.ItemSelector)21 LayoutException (org.apache.archiva.repository.content.LayoutException)21 ContentItem (org.apache.archiva.repository.content.ContentItem)19 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)15 IOException (java.io.IOException)13 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 Project (org.apache.archiva.repository.content.Project)13 MavenMetadataReader (org.apache.archiva.maven.metadata.MavenMetadataReader)12 Version (org.apache.archiva.repository.content.Version)12 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)12 Reader (java.io.Reader)11 List (java.util.List)11 Collectors (java.util.stream.Collectors)11 Inject (javax.inject.Inject)11