Search in sources :

Example 71 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactVersionsMultipleArtifactsSingleVersion.

@Test
public void testGetArtifactVersionsMultipleArtifactsSingleVersion() throws Exception {
    ArtifactMetadata artifact1 = createArtifact();
    artifact1.setId(TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar");
    ArtifactMetadata artifact2 = createArtifact();
    artifact2.setId(TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar");
    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<String> versions = repository.getArtifactVersions(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertThat(versions).isNotNull().isNotEmpty().hasSize(1).containsExactly(TEST_PROJECT_VERSION);
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 72 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByDateRangeUpperBound.

@Test
public void testGetArtifactsByDateRangeUpperBound() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    repository.save();
    Date upper = new Date(artifact.getWhenGathered().getTime() + 10000);
    List<ArtifactMetadata> artifacts = repository.getArtifactsByDateRange(TEST_REPO_ID, null, upper);
    assertEquals(Collections.singletonList(artifact), artifacts);
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Date(java.util.Date) Test(org.junit.Test)

Example 73 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByMetadataAllRepositories.

@Test
public void testGetArtifactsByMetadataAllRepositories() throws Exception {
    createArtifactWithMavenArtifactFacet();
    tryAssert(() -> {
        Collection<ArtifactMetadata> artifactsByMetadata = repository.getArtifactsByMetadata("foo", TEST_METADATA_VALUE, null);
        assertThat(artifactsByMetadata).hasSize(1);
        ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next();
        assertThat(artifactMetadata.getId()).isEqualTo("projectId-1.0.jar");
        assertThat(artifactMetadata.getSha1()).isEqualTo(TEST_SHA1);
        assertThat(artifactMetadata.getRepositoryId()).isEqualTo(TEST_REPO_ID);
        MetadataFacet facet = artifactMetadata.getFacet(TEST_FACET_ID);
        assertThat(facet).isNotNull();
        assertThat(facet.toProperties()).isEqualTo(Collections.singletonMap("foo", TEST_METADATA_VALUE));
    });
}
Also used : 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 74 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactOnly.

@Test
public void testGetArtifactOnly() throws Exception {
    assertThat(new ArrayList<>(repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION))).isNotNull().isEmpty();
    assertThat(repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION)).isNull();
    assertThat(repository.getProject(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT)).isNull();
    assertThat(repository.getRootNamespaces(TEST_REPO_ID)).isNotNull().isEmpty();
    ArtifactMetadata metadata = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
    Collection<ArtifactMetadata> artifacts = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    // assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
    assertThat(artifacts).containsExactly(metadata);
    // test that namespace, project and project version is also constructed
    assertThat(repository.getRootNamespaces(TEST_REPO_ID)).isNotNull().isNotEmpty().contains(TEST_NAMESPACE).hasSize(1);
    ProjectMetadata projectMetadata = repository.getProject(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT);
    assertEquals(TEST_PROJECT, projectMetadata.getId());
    assertEquals(TEST_NAMESPACE, projectMetadata.getNamespace());
    ProjectVersionMetadata projectVersionMetadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertEquals(TEST_PROJECT_VERSION, projectVersionMetadata.getId());
}
Also used : ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 75 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByRepoId.

@Test
public void testGetArtifactsByRepoId() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    repository.save();
    tryAssert(() -> {
        List<ArtifactMetadata> artifacts = repository.getArtifacts(TEST_REPO_ID);
        assertEquals(Collections.singletonList(artifact), artifacts);
    });
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

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