Search in sources :

Example 11 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetArtifactsByChecksumDeepNamespace.

@Test
public void testGetArtifactsByChecksumDeepNamespace() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    String namespace = "multi.level.ns";
    artifact.setNamespace(namespace);
    repository.updateArtifact(TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    repository.save();
    tryAssert(() -> assertEquals(Collections.singletonList(artifact), new ArrayList<>(repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_SHA1))));
    tryAssert(() -> assertEquals(Collections.singletonList(artifact), new ArrayList<>(repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_MD5))));
}
Also used : ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 12 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method createArtifactWithFacet.

private void createArtifactWithFacet(int artifacts, MetadataFacet artifactFacet, MetadataFacet projectVersionMetadataFacet) throws MetadataRepositoryException, MetadataResolutionException {
    for (int i = 0; i < artifacts; i++) {
        ArtifactMetadata artifact = createArtifact();
        if (artifactFacet != null) {
            artifact.addFacet(artifactFacet);
        }
        repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    }
    if (projectVersionMetadataFacet != null) {
        ProjectVersionMetadata metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
        metadata.addFacet(projectVersionMetadataFacet);
        metadata.setOrganization(TEST_ORGANIZATION);
        metadata.setUrl(TEST_URL);
        repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
    }
    repository.save();
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 13 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetArtifacts.

@Test
public void testGetArtifacts() throws Exception {
    ArtifactMetadata artifact1 = createArtifact();
    ArtifactMetadata artifact2 = createArtifact("pom");
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1);
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2);
    Collection<ArtifactMetadata> artifacts = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    ArrayList<ArtifactMetadata> actual = new ArrayList<>(artifacts);
    Collections.sort(actual, (o1, o2) -> o1.getId().compareTo(o2.getId()));
    assertEquals(Arrays.asList(artifact1, artifact2), actual);
}
Also used : ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 14 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetArtifactsDoesntReturnProjectVersionMetadataFacets.

@Test
public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets() throws Exception {
    ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
    versionMetadata.setId(TEST_PROJECT_VERSION);
    MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz");
    versionMetadata.addFacet(facet);
    repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata);
    ArtifactMetadata artifactMetadata = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata);
    repository.save();
    Collection<ArtifactMetadata> artifacts = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
    artifacts = repository.getArtifacts(TEST_REPO_ID);
    assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
    artifacts = repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_SHA1);
    assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
    artifacts = repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_MD5);
    assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
    artifacts = repository.getArtifactsByDateRange(TEST_REPO_ID, null, null);
    assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 15 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class AbstractMetadataRepositoryTest method createArtifactWithData.

private void createArtifactWithData() throws MetadataRepositoryException, MetadataResolutionException {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    ProjectVersionMetadata metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    metadata.setOrganization(TEST_ORGANIZATION);
    metadata.setUrl(TEST_URL);
    repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
    repository.save();
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Aggregations

ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)96 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)23 Path (java.nio.file.Path)20 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)17 Date (java.util.Date)15 HashSet (java.util.HashSet)11 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)10 MavenArtifactFacet (org.apache.archiva.metadata.model.maven2.MavenArtifactFacet)9 HashMap (java.util.HashMap)8 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)8 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)7 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)7 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)7 Node (javax.jcr.Node)6 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)6 IOException (java.io.IOException)5 RepositoryException (javax.jcr.RepositoryException)5