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);
}
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());
}
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));
}
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;
}
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");
}
Aggregations