Search in sources :

Example 56 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset 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 57 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset 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 58 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset 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 59 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MetadataTransferTest method assertMetadataEquals.

private void assertMetadataEquals(String expectedMetadataXml, Path actualFile) throws Exception {
    assertNotNull("Actual File should not be null.", actualFile);
    assertTrue("Actual file exists.", Files.exists(actualFile));
    StringWriter actualContents = new StringWriter();
    FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager());
    StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString());
    ArchivaRepositoryMetadata metadata = metadataTools.getMetadataReader(null).read(actualFileAsset);
    RepositoryMetadataWriter.write(metadata, actualContents);
    Diff detailedDiff = DiffBuilder.compare(expectedMetadataXml).withTest(actualContents.toString()).checkForSimilar().build();
    if (detailedDiff.hasDifferences()) {
        for (Difference diff : detailedDiff.getDifferences()) {
            System.out.println(diff);
        }
        assertEquals(expectedMetadataXml, actualContents);
    }
// assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
}
Also used : StringWriter(java.io.StringWriter) Diff(org.xmlunit.diff.Diff) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Difference(org.xmlunit.diff.Difference) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 60 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class ManagedRepositoryContentMock method getArtifact.

@Override
public Artifact getArtifact(ItemSelector selector) throws ContentAccessException {
    StringBuilder path = new StringBuilder(selector.getNamespace().replace(".", "/"));
    path.append("/").append(selector.getProjectId()).append("/").append(selector.getVersion());
    path.append("/").append(selector.getArtifactId()).append("-").append(selector.getArtifactVersion()).append(".").append(selector.getType());
    StorageAsset asset = fsStorage.getAsset(path.toString());
    ArchivaNamespace ns = ArchivaNamespace.withRepository(repository.getContent()).withAsset(asset.getParent().getParent().getParent()).withNamespace(selector.getNamespace()).build();
    ArchivaProject project = ArchivaProject.withRepository(repository.getContent()).withAsset(asset.getParent().getParent()).withNamespace(ns).withId(selector.getProjectId()).build();
    ArchivaVersion version = ArchivaVersion.withRepository(repository.getContent()).withAsset(asset.getParent()).withProject(project).withVersion(selector.getVersion()).build();
    ArchivaArtifact artifact = ArchivaArtifact.withAsset(asset).withVersion(version).withId(selector.getArtifactId()).withArtifactVersion(selector.getArtifactVersion()).withType(selector.getType()).build();
    return artifact;
}
Also used : ArchivaProject(org.apache.archiva.repository.content.base.ArchivaProject) ArchivaArtifact(org.apache.archiva.repository.content.base.ArchivaArtifact) ArchivaNamespace(org.apache.archiva.repository.content.base.ArchivaNamespace) ArchivaVersion(org.apache.archiva.repository.content.base.ArchivaVersion) StorageAsset(org.apache.archiva.repository.storage.StorageAsset)

Aggregations

StorageAsset (org.apache.archiva.repository.storage.StorageAsset)191 Path (java.nio.file.Path)91 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)61 IOException (java.io.IOException)59 Test (org.junit.Test)59 Artifact (org.apache.archiva.repository.content.Artifact)54 ManagedRepository (org.apache.archiva.repository.ManagedRepository)27 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)22 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)22 List (java.util.List)20 Inject (javax.inject.Inject)20 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)20 Collectors (java.util.stream.Collectors)19 RemoteRepository (org.apache.archiva.repository.RemoteRepository)19 IndexingContext (org.apache.maven.index.context.IndexingContext)19 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)18 StringUtils (org.apache.commons.lang3.StringUtils)18 Logger (org.slf4j.Logger)18 LoggerFactory (org.slf4j.LoggerFactory)18 Map (java.util.Map)17