Search in sources :

Example 21 with ContentItem

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

the class ManagedDefaultRepositoryContentTest method testToItemFromPath.

@Test
public void testToItemFromPath() throws LayoutException {
    String path = "/org/apache/maven/shared";
    ContentItem item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = "/org/apache/maven/shared/maven-downloader";
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = "/org/apache/maven/shared/maven-downloader/1.1";
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = "/org/apache/maven/shared/maven-downloader/1.1/maven-downloader-1.1.jar";
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof DataItem);
}
Also used : ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) DataItem(org.apache.archiva.repository.content.DataItem) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Test(org.junit.Test)

Example 22 with ContentItem

use of org.apache.archiva.repository.content.ContentItem 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 23 with ContentItem

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

the class ManagedDefaultRepositoryContentTest method deleteVersionItem.

@Test
public void deleteVersionItem() throws IOException, URISyntaxException, ItemNotFoundException {
    ManagedRepository repo = createManagedRepoWithContent("delete-repository");
    ManagedRepositoryContent myRepoContent = repo.getContent();
    Path repoRoot = repo.getRoot().getFilePath();
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/A/1.0")));
    ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("A").withVersion("1.0").build();
    ContentItem item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Version);
    myRepoContent.deleteItem(item);
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/A")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/samplejar/1.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/samplejar/2.0")));
    assertFalse(Files.exists(repoRoot.resolve("org/apache/maven/A/1.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar")));
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar").withVersion("2.0").build();
    item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Version);
    myRepoContent.deleteItem(item);
    assertFalse(Files.exists(repoRoot.resolve("org/apache/test/samplejar/2.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar/1.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar/2.0")));
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) 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) Test(org.junit.Test)

Example 24 with ContentItem

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

the class ManagedDefaultRepositoryContentTest method testToItemFromAssetPath.

@Test
public void testToItemFromAssetPath() throws LayoutException {
    StorageAsset path = repoContent.getRepository().getAsset("/org/apache/maven/shared");
    ContentItem item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = repoContent.getRepository().getAsset("/org/apache/maven/shared/maven-downloader");
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = repoContent.getRepository().getAsset("/org/apache/maven/shared/maven-downloader/1.1");
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof ArchivaContentItem);
    path = repoContent.getRepository().getAsset("/org/apache/maven/shared/maven-downloader/1.1/maven-downloader-1.1.jar");
    item = repoContent.toItem(path);
    assertNotNull(item);
    assertTrue(item instanceof DataItem);
}
Also used : ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) DataItem(org.apache.archiva.repository.content.DataItem) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Test(org.junit.Test)

Example 25 with ContentItem

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

the class ManagedDefaultRepositoryContentTest method deleteArtifactItem.

@Test
public void deleteArtifactItem() throws IOException, URISyntaxException, ItemNotFoundException {
    ManagedRepository repo = createManagedRepoWithContent("delete-repository");
    ManagedRepositoryContent myRepoContent = repo.getContent();
    Path repoRoot = repo.getRoot().getFilePath();
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/A/1.0/A-1.0.pom")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/A/1.0/A-1.0.war")));
    ArchivaItemSelector selector = ArchivaItemSelector.builder().withNamespace("org.apache.maven").withProjectId("A").withVersion("1.0").withArtifactId("A").withArtifactVersion("1.0").withExtension("pom").build();
    ContentItem item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Artifact);
    myRepoContent.deleteItem(item);
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/samplejar/1.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/samplejar/2.0")));
    assertFalse(Files.exists(repoRoot.resolve("org/apache/maven/A/1.0/A-1.0.pom")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/maven/A/1.0/A-1.0.war")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar.md5")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar.sha1")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.pom")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0-source.jar")));
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar").withVersion("1.0").withArtifactId("samplejar").withArtifactVersion("1.0").withExtension("jar").build();
    item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Artifact);
    myRepoContent.deleteItem(item);
    assertFalse(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar.md5")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar.sha1")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.pom")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0-source.jar")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/2.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar/1.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar/2.0")));
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar").withVersion("1.0").withArtifactId("samplejar").withArtifactVersion("1.0").withClassifier("source").withExtension("jar").build();
    item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Artifact);
    myRepoContent.deleteItem(item);
    assertFalse(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar.md5")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar.sha1")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.pom")));
    assertFalse(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0-source.jar")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0-source.jar.sha1")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/2.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar/1.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar/2.0")));
    selector = ArchivaItemSelector.builder().withNamespace("org.apache.test").withProjectId("samplejar").withVersion("1.0").withArtifactId("samplejar").withArtifactVersion("1.0").withExtension("jar.md5").build();
    item = myRepoContent.getItem(selector);
    assertTrue(item instanceof Artifact);
    myRepoContent.deleteItem(item);
    assertFalse(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar")));
    assertFalse(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar.md5")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.jar.sha1")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0.pom")));
    assertFalse(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0-source.jar")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/1.0/samplejar-1.0-source.jar.sha1")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/samplejar/2.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar/1.0")));
    assertTrue(Files.exists(repoRoot.resolve("org/apache/test/sub/samplejar/2.0")));
}
Also used : Path(java.nio.file.Path) ArchivaItemSelector(org.apache.archiva.repository.content.base.ArchivaItemSelector) MavenManagedRepository(org.apache.archiva.maven.repository.MavenManagedRepository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ContentItem(org.apache.archiva.repository.content.ContentItem) ArchivaContentItem(org.apache.archiva.repository.content.base.ArchivaContentItem) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Aggregations

ContentItem (org.apache.archiva.repository.content.ContentItem)29 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)16 ArchivaContentItem (org.apache.archiva.repository.content.base.ArchivaContentItem)15 Test (org.junit.Test)14 Path (java.nio.file.Path)12 StorageAsset (org.apache.archiva.repository.storage.StorageAsset)12 Artifact (org.apache.archiva.repository.content.Artifact)10 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)10 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)9 Project (org.apache.archiva.repository.content.Project)9 ManagedRepository (org.apache.archiva.repository.ManagedRepository)8 LayoutException (org.apache.archiva.repository.content.LayoutException)8 Version (org.apache.archiva.repository.content.Version)8 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)7 ItemSelector (org.apache.archiva.repository.content.ItemSelector)7 MavenManagedRepository (org.apache.archiva.maven.repository.MavenManagedRepository)6 DataItem (org.apache.archiva.repository.content.DataItem)6 Namespace (org.apache.archiva.repository.content.Namespace)6 IOException (java.io.IOException)5 ItemNotFoundException (org.apache.archiva.repository.content.ItemNotFoundException)5