Search in sources :

Example 6 with Namespace

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

the class AbstractRepositoryContentTest method assertLayoutCi.

private void assertLayoutCi(String path, String groupId, String artifactId, String version, String artifactVersion, String classifier, String type) throws LayoutException {
    ItemSelector expectedArtifact = createItemSelector(groupId, artifactId, version, artifactVersion, classifier, type);
    // --- Artifact Tests.
    // Artifact to Path
    assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(expectedArtifact));
    // --- Artifact Reference Tests
    // Path to Artifact Reference.
    ItemSelector testReference = toItemSelector(path);
    assertItemSelector(testReference, groupId, artifactId, version, artifactVersion, classifier, type);
    // And back again, using test Reference from previous step.
    assertEquals("Artifact <" + expectedArtifact + "> to path:", path, toPath(testReference));
    if (getManaged() != null) {
        Namespace ns = null;
        Project pr = null;
        Version ver = null;
        if (StringUtils.isNotEmpty(groupId)) {
            ns = getManaged().getLayout(BaseRepositoryContentLayout.class).getNamespace(expectedArtifact);
            assertNotNull(ns);
            assertEquals(groupId, ns.getId());
        }
        if (StringUtils.isNotEmpty(artifactId)) {
            pr = getManaged().getLayout(BaseRepositoryContentLayout.class).getProject(expectedArtifact);
            assertNotNull(pr);
            assertEquals(artifactId, pr.getId());
            assertEquals(ns, pr.getNamespace());
        }
        if (StringUtils.isNotEmpty(version)) {
            ver = getManaged().getLayout(BaseRepositoryContentLayout.class).getVersion(expectedArtifact);
            assertNotNull(ver);
            assertEquals(version, ver.getId());
            assertEquals(pr, ver.getProject());
        }
        Artifact artifact = getManaged().getLayout(BaseRepositoryContentLayout.class).getArtifact(expectedArtifact);
        assertNotNull(artifact);
        assertEquals(artifactId, artifact.getId());
        assertEquals(ver, artifact.getVersion());
    }
}
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) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) Namespace(org.apache.archiva.repository.content.Namespace) Artifact(org.apache.archiva.repository.content.Artifact)

Example 7 with Namespace

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

the class ManagedDefaultRepositoryContentTest method deleteItemNotFound.

@Test
public void deleteItemNotFound() throws IOException, URISyntaxException, ItemNotFoundException {
    ManagedRepository repo = createManagedRepoWithContent("delete-repository");
    ManagedRepositoryContent myRepoContent = repo.getContent();
    Path repoRoot = repo.getRoot().getFilePath();
    ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.test2").build();
    ContentItem item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Namespace);
    try {
        myRepoContent.deleteItem(item);
        assertTrue("ItemNotFoundException expected for non existing namespace", false);
    } catch (ItemNotFoundException e) {
    }
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar2").build();
    item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Project);
    try {
        myRepoContent.deleteItem(item);
        assertTrue("ItemNotFoundException expected for non existing project", false);
    } catch (ItemNotFoundException e) {
    }
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar").withVersion("1.1").build();
    item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Version);
    try {
        myRepoContent.deleteItem(item);
        assertTrue("ItemNotFoundException expected for non existing version", false);
    } catch (ItemNotFoundException e) {
    }
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar").withVersion("1.0").withArtifactId("samplejar").withArtifactVersion("1.0").withExtension("jax").build();
    item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Artifact);
    try {
        myRepoContent.deleteItem(item);
        assertTrue("ItemNotFoundException expected for non existing artifact", false);
    } catch (ItemNotFoundException e) {
    }
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) Project(org.apache.archiva.repository.content.Project) MavenManagedRepository(org.apache.archiva.maven.repository.MavenManagedRepository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) Version(org.apache.archiva.repository.content.Version) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Namespace(org.apache.archiva.repository.content.Namespace) Artifact(org.apache.archiva.repository.content.Artifact) ItemNotFoundException(org.apache.archiva.repository.content.ItemNotFoundException) Test(org.junit.Test)

Example 8 with Namespace

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

the class ManagedDefaultRepositoryContentTest method testGetProjects.

@Test
public void testGetProjects() {
    ItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").build();
    Namespace ns = repoContent.getNamespace(selector);
    assertNotNull(ns);
    List<? extends Project> projects = repoContent.getProjects(ns);
    assertEquals(12, projects.size());
    String[] expected = new String[] { "A", "B", "C", "archiva", "discovery", "maven-parent", "samplejar", "shared", "some-ejb", "test", "testing", "update" };
    Object[] actual = projects.stream().map(p -> p.getId()).sorted().toArray();
    assertArrayEquals(expected, actual);
}
Also used : ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) ItemSelector(org.apache.archiva.repository.content.ItemSelector) Namespace(org.apache.archiva.repository.content.Namespace) Test(org.junit.Test)

Aggregations

Namespace (org.apache.archiva.repository.content.Namespace)8 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)6 Test (org.junit.Test)6 ContentItem (org.apache.archiva.repository.content.ContentItem)4 ItemSelector (org.apache.archiva.repository.content.ItemSelector)4 Project (org.apache.archiva.repository.content.Project)4 Version (org.apache.archiva.repository.content.Version)4 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)4 Artifact (org.apache.archiva.repository.content.Artifact)3 Path (java.nio.file.Path)2 MavenManagedRepository (org.apache.archiva.maven.repository.MavenManagedRepository)2 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)2 ManagedRepository (org.apache.archiva.repository.ManagedRepository)2 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)2 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)1 ItemNotFoundException (org.apache.archiva.repository.content.ItemNotFoundException)1 LayoutException (org.apache.archiva.repository.content.LayoutException)1 ArchivaNamespace (org.apache.archiva.repository.content.base.ArchivaNamespace)1 ArchivaProject (org.apache.archiva.repository.content.base.ArchivaProject)1 ArchivaVersion (org.apache.archiva.repository.content.base.ArchivaVersion)1