Search in sources :

Example 31 with ItemSelector

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

the class ManagedDefaultRepositoryContentTest method testGetArtifactFromContentItem.

@Test
public void testGetArtifactFromContentItem() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").build();
    Namespace ns = repoContent.getNamespace(selector);
    List<? extends Artifact> artifacts = repoContent.getArtifacts(ns);
    assertNotNull(artifacts);
    assertEquals(39, artifacts.size());
    List<? extends Artifact> artifacts2 = repoContent.getArtifacts((ContentItem) ns);
    assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven.shared").withProjectId("maven-downloader").build();
    Project project = repoContent.getProject(selector);
    artifacts = repoContent.getArtifacts(project);
    assertNotNull(artifacts);
    assertEquals(27, artifacts.size());
    artifacts2 = repoContent.getArtifacts((ContentItem) project);
    assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven.shared").withProjectId("maven-downloader").withVersion("1.1").build();
    Version version = repoContent.getVersion(selector);
    artifacts = repoContent.getArtifacts(version);
    assertNotNull(artifacts);
    assertEquals(12, artifacts.size());
    artifacts2 = repoContent.getArtifacts((ContentItem) version);
    assertArrayEquals(artifacts.toArray(), artifacts2.toArray());
}
Also used : Project(org.apache.archiva.repository.content.Project) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Version(org.apache.archiva.repository.content.Version) Namespace(org.apache.archiva.repository.content.Namespace) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Test(org.junit.Test)

Example 32 with ItemSelector

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

the class ManagedDefaultRepositoryContentTest method assertArtifactVersions.

private void assertArtifactVersions(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.getArtifactVersions(selector).stream().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 33 with ItemSelector

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

the class ManagedDefaultRepositoryContentTest method testGetItemWithNamespaceSelector.

@Test
public void testGetItemWithNamespaceSelector() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").build();
    ContentItem item = repoContent.getItem(selector);
    assertNotNull(item);
    assertTrue(item instanceof Namespace);
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Namespace(org.apache.archiva.repository.content.Namespace) Test(org.junit.Test)

Example 34 with ItemSelector

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

the class ManagedDefaultRepositoryContentTest method testGetVersionsWithSelector.

@Test
public void testGetVersionsWithSelector() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("samplejar").build();
    List<? extends Version> versions = repoContent.getVersions(selector);
    assertNotNull(versions);
    assertEquals(2, versions.size());
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Test(org.junit.Test)

Example 35 with ItemSelector

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

the class ManagedDefaultRepositoryContentTest method testGetArtifactStreamWithVersionSelector.

@Test
public void testGetArtifactStreamWithVersionSelector() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("javax.sql").withProjectId("jdbc").withVersion("2.0").build();
    try (Stream<? extends Artifact> stream = repoContent.newArtifactStream(selector)) {
        assertNotNull(stream);
        List<? extends Artifact> results = stream.collect(Collectors.toList());
        checkArtifactListWithVersionSelector1(results);
    }
}
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