Search in sources :

Example 66 with ItemSelector

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"));
    }
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Test(org.junit.Test)

Example 67 with ItemSelector

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);
    }
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) MavenManagedRepository(org.apache.archiva.maven.repository.MavenManagedRepository) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ArrayList(java.util.ArrayList) VersionComparator(org.apache.archiva.common.utils.VersionComparator)

Example 68 with ItemSelector

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);
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent)

Example 69 with ItemSelector

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());
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector)

Example 70 with ItemSelector

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));
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Test(org.junit.Test)

Aggregations

ItemSelector (org.apache.archiva.repository.content.ItemSelector)76 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)74 Test (org.junit.Test)41 Path (java.nio.file.Path)16 Artifact (org.apache.archiva.repository.content.Artifact)16 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)13 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)12 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)12 LayoutException (org.apache.archiva.repository.content.LayoutException)12 IOException (java.io.IOException)11 ContentItem (org.apache.archiva.repository.content.ContentItem)11 Project (org.apache.archiva.repository.content.Project)11 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)10 Namespace (org.apache.archiva.repository.content.Namespace)9 Version (org.apache.archiva.repository.content.Version)9 VersionComparator (org.apache.archiva.common.utils.VersionComparator)8 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6