Search in sources :

Example 66 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByDateRangeOpen.

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

Example 67 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testDeleteRepository.

@Test
public void testDeleteRepository() throws Exception {
    repository.updateNamespace(TEST_REPO_ID, TEST_NAMESPACE);
    ProjectMetadata project1 = new ProjectMetadata();
    project1.setNamespace(TEST_NAMESPACE);
    project1.setId("project1");
    repository.updateProject(TEST_REPO_ID, project1);
    ProjectMetadata project2 = new ProjectMetadata();
    project2.setNamespace(TEST_NAMESPACE);
    project2.setId("project2");
    repository.updateProject(TEST_REPO_ID, project2);
    ArtifactMetadata artifact1 = createArtifact();
    artifact1.setProject("project1");
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, "project1", TEST_PROJECT_VERSION, artifact1);
    ArtifactMetadata artifact2 = createArtifact();
    artifact2.setProject("project2");
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, "project2", TEST_PROJECT_VERSION, artifact2);
    repository.save();
    List<ArtifactMetadata> expected = Arrays.asList(artifact1, artifact2);
    Collections.sort(expected, new ArtifactMetadataComparator());
    tryAssert(() -> {
        List<ArtifactMetadata> actual = new ArrayList<>(repository.getArtifactsByDateRange(TEST_REPO_ID, null, null));
        Collections.sort(actual, new ArtifactMetadataComparator());
        assertEquals(expected, actual);
    });
    repository.removeRepository(TEST_REPO_ID);
    assertTrue(repository.getArtifacts(TEST_REPO_ID).isEmpty());
    assertTrue(repository.getRootNamespaces(TEST_REPO_ID).isEmpty());
}
Also used : ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 68 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testGetArtifactsByDateRangeSparseNamespace.

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

Example 69 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method createArtifact.

private static ArtifactMetadata createArtifact(String type) {
    ArtifactMetadata artifact = new ArtifactMetadata();
    artifact.setId(TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type);
    artifact.setWhenGathered(new Date());
    artifact.setNamespace(TEST_NAMESPACE);
    artifact.setProject(TEST_PROJECT);
    artifact.setRepositoryId(TEST_REPO_ID);
    artifact.setFileLastModified(System.currentTimeMillis());
    artifact.setVersion(TEST_PROJECT_VERSION);
    artifact.setProjectVersion(TEST_PROJECT_VERSION);
    artifact.setMd5(TEST_MD5);
    artifact.setSha1(TEST_SHA1);
    return artifact;
}
Also used : ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Date(java.util.Date)

Example 70 with ArtifactMetadata

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

the class AbstractMetadataRepositoryTest method testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved.

@Test
public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved() throws Exception {
    ArtifactMetadata metadata = createArtifact();
    Map<String, String> additionalProps = new HashMap<>();
    additionalProps.put("deleteKey", "deleteValue");
    MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz", additionalProps);
    metadata.addFacet(facet);
    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);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
    metadata = artifacts.iterator().next();
    Collection<String> ids = metadata.getFacetIds();
    assertThat(ids).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
    TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
    Map<String, String> facetProperties = testFacet.toProperties();
    assertEquals("deleteValue", facetProperties.get("deleteKey"));
    facetProperties.remove("deleteKey");
    TestMetadataFacet newTestFacet = new TestMetadataFacet(TEST_FACET_ID, testFacet.getValue(), facetProperties);
    metadata.addFacet(newTestFacet);
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
    artifacts = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
    metadata = artifacts.iterator().next();
    ids = metadata.getFacetIds();
    assertThat(ids).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
    testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
    Map<String, String> props = testFacet.toProperties();
    assertThat(props).isNotNull().doesNotContainKey("deleteKey");
}
Also used : HashMap(java.util.HashMap) 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)

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