use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class ManagedDefaultRepositoryContentTest method getTestGetArtifactWithIllegalArgs.
@Test
public void getTestGetArtifactWithIllegalArgs() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withVersion("1.0").withArtifactId("shared").withArtifactVersion("1.0").build();
try {
repoContent.getArtifact(selector);
assertFalse("Should throw IllegalArgumentException if no project id is given", true);
} catch (IllegalArgumentException e) {
// Everything fine
assertTrue(e.getMessage().contains("Project id must be set"));
}
selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("shared").withArtifactId("shared").build();
try {
repoContent.getArtifact(selector);
assertFalse("Should throw IllegalArgumentException if no version is given", true);
} catch (IllegalArgumentException e) {
// Everything fine
assertTrue(e.getMessage().contains("Version must be set"));
}
selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("shared").withVersion("1.0").withArtifactVersion("1.0").build();
try {
repoContent.getArtifact(selector);
assertFalse("Should throw IllegalArgumentException if no artifact id is given", true);
} catch (IllegalArgumentException e) {
// Everything fine
assertTrue(e.getMessage().contains("Artifact id must be set"));
}
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class MetadataToolsTest method assertSnapshotVersions.
private void assertSnapshotVersions(String artifactId, String version, String[] expectedVersions) throws Exception {
Path repoRootDir = getRepositoryPath("metadata-repository");
ItemSelector reference = ArchivaItemSelector.builder().withNamespace("org.apache.archiva.metadata.tests").withArtifactId(artifactId).withProjectId(artifactId).withVersion(version).build();
MavenManagedRepository repo = createRepository("test-repo", "Test Repository: " + name.getMethodName(), repoRootDir);
RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
Set<String> testedVersionSet = tools.gatherSnapshotVersions(repoContent, reference);
// Sort the list (for asserts)
List<String> testedVersions = new ArrayList<>();
testedVersions.addAll(testedVersionSet);
Collections.sort(testedVersions, new VersionComparator());
// Test the expected array of versions, to the actual tested versions
assertEquals("Assert Snapshot Versions: length/size", expectedVersions.length, testedVersions.size());
for (int i = 0; i < expectedVersions.length; i++) {
String actualVersion = testedVersions.get(i);
assertEquals("Snapshot Versions[" + i + "]", expectedVersions[i], actualVersion);
}
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class MetadataToolsTest method assertUpdatedProjectMetadata.
private void assertUpdatedProjectMetadata(String artifactId, String[] expectedVersions, String latestVersion, String releaseVersion) throws Exception {
ManagedRepositoryContent testRepo = createTestRepoContent();
ItemSelector reference = ArchivaItemSelector.builder().withNamespace("org.apache.archiva.metadata.tests").withProjectId(artifactId).build();
prepProjectTestRepo(testRepo, reference);
tools.updateProjectMetadata(testRepo, reference);
StringBuilder buf = new StringBuilder();
buf.append("<metadata>\n");
buf.append(" <groupId>").append(reference.getNamespace()).append("</groupId>\n");
buf.append(" <artifactId>").append(reference.getProjectId()).append("</artifactId>\n");
if (expectedVersions != null) {
buf.append(" <versioning>\n");
if (latestVersion != null) {
buf.append(" <latest>").append(latestVersion).append("</latest>\n");
}
if (releaseVersion != null) {
buf.append(" <release>").append(releaseVersion).append("</release>\n");
}
buf.append(" <versions>\n");
for (int i = 0; i < expectedVersions.length; i++) {
buf.append(" <version>").append(expectedVersions[i]).append("</version>\n");
}
buf.append(" </versions>\n");
buf.append(" </versioning>\n");
}
buf.append("</metadata>");
assertProjectMetadata(buf.toString(), testRepo, reference);
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class MetadataToolsTest method assertVersionedReference.
private void assertVersionedReference(String groupId, String artifactId, String version, String path) throws RepositoryMetadataException {
ItemSelector reference = tools.toVersionedSelector(path);
assertNotNull("Reference should not be null.", reference);
assertEquals("VersionedReference.groupId", groupId, reference.getNamespace());
assertEquals("VersionedReference.artifactId", artifactId, reference.getArtifactId());
assertEquals("VersionedReference.version", version, reference.getVersion());
}
use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.
the class MetadataToolsTest method testToPathFromVersionReference.
@Test
public void testToPathFromVersionReference() {
ItemSelector selector = ArchivaItemSelector.builder().withNamespace("com.foo").withArtifactId("foo-tool").withProjectId("foo-tool").withVersion("1.0").build();
assertEquals("com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath(selector));
}
Aggregations