Search in sources :

Example 6 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByChecksumMultipleResult.

@Test
public void testGetArtifactsByChecksumMultipleResult() throws Exception {
    ArtifactMetadata artifact1 = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1);
    String newProjectId = "another-project";
    ArtifactMetadata artifact2 = createArtifact();
    artifact2.setProject(newProjectId);
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, newProjectId, TEST_PROJECT_VERSION, artifact2);
    repository.save();
    tryAssert(() -> {
        List<ArtifactMetadata> artifacts = new ArrayList<>(repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_SHA1));
        Collections.sort(artifacts, new ArtifactMetadataComparator());
        assertEquals(Arrays.asList(artifact2, artifact1), artifacts);
    });
    tryAssert(() -> {
        ArrayList<ArtifactMetadata> artifacts = new ArrayList<>(repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_MD5));
        Collections.sort(artifacts, new ArtifactMetadataComparator());
        assertEquals(Arrays.asList(artifact2, artifact1), artifacts);
    });
}
Also used : ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 7 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByChecksumSingleResultSha1.

@Test
public void testGetArtifactsByChecksumSingleResultSha1() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    repository.save();
    assertEquals(Collections.singletonList(artifact), new ArrayList<>(repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_SHA1)));
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 8 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByPropertySingleResult.

@Test
public void testGetArtifactsByPropertySingleResult() throws Exception {
    createArtifactWithData();
    // only works on JCR implementation
    // Collection<ArtifactMetadata> artifactsByProperty = repository.getArtifactsByProperty( "org.name", TEST_ORGANIZATION.getName(), TEST_REPO_ID );
    Collection<ArtifactMetadata> artifactsByProperty = repository.getArtifactsByProperty("url", TEST_URL, TEST_REPO_ID);
    assertThat(artifactsByProperty).hasSize(1);
    ArtifactMetadata artifactMetadata = artifactsByProperty.iterator().next();
    assertThat(artifactMetadata.getId()).isEqualTo("projectId-1.0.jar");
    assertThat(artifactMetadata.getSha1()).isEqualTo(TEST_SHA1);
    assertThat(artifactMetadata.getRepositoryId()).isEqualTo(TEST_REPO_ID);
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 9 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByChecksumMultipleCopies.

@Test
public void testGetArtifactsByChecksumMultipleCopies() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    ArtifactMetadata secondArtifact = createArtifact();
    secondArtifact.setRepositoryId(OTHER_REPO_ID);
    repository.updateArtifact(OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact);
    repository.save();
    // test it restricts to the appropriate repository
    assertEquals(Collections.singletonList(artifact), new ArrayList<>(repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_SHA1)));
    assertEquals(Collections.singletonList(secondArtifact), new ArrayList<>(repository.getArtifactsByChecksum(OTHER_REPO_ID, TEST_SHA1)));
    assertEquals(Collections.singletonList(artifact), new ArrayList<>(repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_MD5)));
    assertEquals(Collections.singletonList(secondArtifact), new ArrayList<>(repository.getArtifactsByChecksum(OTHER_REPO_ID, TEST_MD5)));
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 10 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByDateRangeMultipleCopies.

@Test
public void testGetArtifactsByDateRangeMultipleCopies() throws Exception {
    ArtifactMetadata artifact = createArtifact();
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact);
    ArtifactMetadata secondArtifact = createArtifact();
    secondArtifact.setRepositoryId(OTHER_REPO_ID);
    repository.updateArtifact(OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact);
    repository.save();
    // test it restricts to the appropriate repository
    assertEquals(Collections.singletonList(artifact), repository.getArtifactsByDateRange(TEST_REPO_ID, null, null));
    assertEquals(Collections.singletonList(secondArtifact), repository.getArtifactsByDateRange(OTHER_REPO_ID, null, null));
}
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