Search in sources :

Example 11 with BaseRepositoryContentLayout

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

the class ChecksumTransferTest method testGetChecksumNotFoundOnRemote.

@Test
public void testGetChecksumNotFoundOnRemote() throws Exception {
    String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    FileUtils.deleteDirectory(expectedFile.getParent());
    assertFalse(Files.exists(expectedFile.getParent()));
    assertFalse(Files.exists(expectedFile));
    saveRemoteRepositoryConfig("badproxied", "Bad Proxied", "http://bad.machine.com/repo/", "default");
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    doThrow(new ResourceDoesNotExistException("Resource does not exist.")).when(wagonMock).get(eq(path + ".md5"), any());
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    verify(wagonMock, times(1)).get(eq(path), any());
    verify(wagonMock, times(1)).get(eq(path + ".sha1"), any());
    verify(wagonMock, times(1)).get(eq(path + ".md5"), any());
    // Do what the mock doesn't do.
    Path proxyPath = Paths.get(REPOPATH_PROXIED1, path).toAbsolutePath();
    Path localPath = managedDefaultDir.resolve(path).toAbsolutePath();
    Files.copy(proxyPath, localPath, StandardCopyOption.REPLACE_EXISTING);
    Files.copy(proxyPath.resolveSibling(proxyPath.getFileName() + ".sha1"), localPath.resolveSibling(localPath.getFileName() + ".sha1"), StandardCopyOption.REPLACE_EXISTING);
    // Test results.
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
    assertNoTempFiles(expectedFile);
    assertChecksums(expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", null);
}
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 12 with BaseRepositoryContentLayout

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

the class ChecksumTransferTest method testGetChecksumCorrectSha1BadMd5UsingIgnoredSetting.

@Test
public void testGetChecksumCorrectSha1BadMd5UsingIgnoredSetting() throws Exception {
    String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    FileUtils.deleteDirectory(expectedFile.getParent());
    assertFalse(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
    assertNoTempFiles(expectedFile);
    assertChecksums(expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar", "invalid checksum file");
}
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 13 with BaseRepositoryContentLayout

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

the class ChecksumTransferTest method testGetChecksumCorrectSha1NoMd5.

@Test
public void testGetChecksumCorrectSha1NoMd5() throws Exception {
    String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    FileUtils.deleteDirectory(expectedFile.getParent());
    assertFalse(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
    assertNoTempFiles(expectedFile);
    assertChecksums(expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", null);
}
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 14 with BaseRepositoryContentLayout

use of org.apache.archiva.repository.content.BaseRepositoryContentLayout 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 15 with BaseRepositoryContentLayout

use of org.apache.archiva.repository.content.BaseRepositoryContentLayout 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)

Aggregations

BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)62 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)55 Artifact (org.apache.archiva.repository.content.Artifact)50 Path (java.nio.file.Path)49 Test (org.junit.Test)45 LayoutException (org.apache.archiva.repository.content.LayoutException)10 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)9 ContentItem (org.apache.archiva.repository.content.ContentItem)7 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 Project (org.apache.archiva.repository.content.Project)5 Version (org.apache.archiva.repository.content.Version)5 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)4 ContentAccessException (org.apache.archiva.repository.content.ContentAccessException)4 ItemSelector (org.apache.archiva.repository.content.ItemSelector)4 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)4 IOException (java.io.IOException)3 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)3 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 RepositoryException (org.apache.archiva.repository.RepositoryException)3