Search in sources :

Example 51 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method assertVersions.

private void assertVersions(String artifactId, String version, String[] expectedVersions) throws Exception {
    // Use the test metadata-repository, which is already setup for
    // These kind of version tests.
    Path repoDir = getRepositoryPath("metadata-repository");
    ((EditableManagedRepository) repoContent.getRepository()).setLocation(repoDir.toAbsolutePath().toUri());
    // Request the versions.
    // Sort the list (for asserts later)
    final VersionComparator comparator = new VersionComparator();
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.archiva.metadata.tests").withProjectId(artifactId).withVersion(version).build();
    List<String> versions = repoContent.getVersions(selector).stream().map(v -> v.getId()).sorted(comparator).collect(Collectors.toList());
    assertArrayEquals(expectedVersions, versions.toArray());
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) VersionComparator(org.apache.archiva.common.utils.VersionComparator)

Example 52 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method getTestGetVersionWithIllegalArgs.

@Test
public void getTestGetVersionWithIllegalArgs() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withVersion("1.0").build();
    try {
        repoContent.getVersion(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").build();
    try {
        repoContent.getVersion(selector);
        assertFalse("Should throw IllegalArgumentException if no version is given", true);
    } catch (IllegalArgumentException e) {
        // Everything fine
        assertTrue(e.getMessage().contains("Version 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 53 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method testArtifactListWithArtifactSelector1.

@Test
public void testArtifactListWithArtifactSelector1() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("test").withVersion("1.0-SNAPSHOT").withArtifactId("test").withArtifactVersion("1.0-20050611.112233-1").build();
    List<? extends Artifact> results = repoContent.getArtifacts(selector);
    assertNotNull(results);
    assertEquals(1, results.size());
    Artifact artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("test-1.0-20050611.112233-1.jar")).findFirst().get();
    assertNotNull(artifact);
    assertEquals("", artifact.getClassifier());
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 54 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method testArtifactListWithArtifactSelector2.

@Test
public void testArtifactListWithArtifactSelector2() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("test").withVersion("1.0-SNAPSHOT").withClassifier("*").withArtifactId("test").withArtifactVersion("1.0-20050611.112233-1").build();
    List<? extends Artifact> results = repoContent.getArtifacts(selector);
    assertNotNull(results);
    assertEquals(2, results.size());
    Artifact artifact = results.stream().filter(a -> a.getFileName().equalsIgnoreCase("test-1.0-20050611.112233-1-javadoc.jar")).findFirst().get();
    assertNotNull(artifact);
    assertEquals("javadoc", artifact.getClassifier());
    assertEquals("javadoc", artifact.getType());
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 55 with ItemSelector

use of org.apache.archiva.repository.content.ItemSelector in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method testArtifactListWithNamespaceSelector.

@Test
public void testArtifactListWithNamespaceSelector() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.multilevel").build();
    List<? extends Artifact> results = repoContent.getArtifacts(selector);
    assertNotNull(results);
    assertEquals(3, results.size());
    assertTrue(results.get(0).getFileName().startsWith("testproj1"));
}
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