Search in sources :

Example 16 with ReadMetadataRequest

use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.

the class Maven2RepositoryMetadataResolverTest method testGetArtifactsTimestampedSnapshots.

@Test
public void testGetArtifactsTimestampedSnapshots() throws Exception {
    List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(storage.readArtifactsMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL)));
    assertEquals(1, artifacts.size());
    ArtifactMetadata artifact = artifacts.get(0);
    assertEquals("missing-metadata-1.0-20091101.112233-1.pom", artifact.getId());
    assertEquals("com.example.test", artifact.getNamespace());
    assertEquals("missing-metadata", artifact.getProject());
    assertEquals("1.0-20091101.112233-1", artifact.getVersion());
    assertEquals(TEST_REPO_ID, artifact.getRepositoryId());
}
Also used : ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 17 with ReadMetadataRequest

use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.

the class Maven2RepositoryMetadataResolverTest method testModelWithJdkProfileActivation.

@Test
public void testModelWithJdkProfileActivation() throws Exception {
    ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(TEST_REPO_ID).namespace("org.apache.maven").projectId("maven-archiver").projectVersion("2.4.1");
    ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
    MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
}
Also used : ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) Test(org.junit.Test)

Example 18 with ReadMetadataRequest

use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.

the class Maven2RepositoryMetadataResolverTest method testGetArtifactMetadata.

@Test
public void testGetArtifactMetadata() throws Exception {
    Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata(new ReadMetadataRequest(TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL));
    List<ArtifactMetadata> artifacts = new ArrayList<>(springArtifacts);
    Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {

        @Override
        public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
            return o1.getId().compareTo(o2.getId());
        }
    });
    assertEquals(3, artifacts.size());
    ArtifactMetadata artifactMetadata = artifacts.get(0);
    assertEquals("plexus-spring-1.2-sources.jar", artifactMetadata.getId());
    MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(0, facet.getBuildNumber());
    assertNull(facet.getTimestamp());
    assertEquals("sources", facet.getClassifier());
    assertEquals("java-source", facet.getType());
    artifactMetadata = artifacts.get(1);
    assertEquals("plexus-spring-1.2.jar", artifactMetadata.getId());
    facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(0, facet.getBuildNumber());
    assertNull(facet.getTimestamp());
    assertNull(facet.getClassifier());
    assertEquals("jar", facet.getType());
    artifactMetadata = artifacts.get(2);
    assertEquals("plexus-spring-1.2.pom", artifactMetadata.getId());
    facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    assertEquals(0, facet.getBuildNumber());
    assertNull(facet.getTimestamp());
    assertNull(facet.getClassifier());
    assertEquals("pom", facet.getType());
}
Also used : ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ArrayList(java.util.ArrayList) MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 19 with ReadMetadataRequest

use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.

the class Maven2RepositoryMetadataResolverTest method testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata.

@Test
public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata() throws Exception {
    try {
        storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT"));
        fail("Should not be found");
    } catch (RepositoryStorageMetadataNotFoundException e) {
        assertEquals("missing-pom", e.getId());
    }
}
Also used : RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) Test(org.junit.Test)

Example 20 with ReadMetadataRequest

use of org.apache.archiva.metadata.repository.storage.ReadMetadataRequest in project archiva by apache.

the class Maven2RepositoryMetadataResolverTest method testGetArtifactMetadataSnapshotsMRM1859.

@Test
public void testGetArtifactMetadataSnapshotsMRM1859() throws Exception {
    Path repoDir = Paths.get("target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT");
    URL url = Thread.currentThread().getContextClassLoader().getResource("resolver-status.properties");
    Path resFile = Paths.get(url.toURI());
    Path destFile = repoDir.resolve(resFile.getFileName());
    Files.copy(resFile, destFile, StandardCopyOption.REPLACE_EXISTING);
    URL url2 = Thread.currentThread().getContextClassLoader().getResource("test01.properties");
    Path resFile2 = Paths.get(url2.toURI());
    Path destFile2 = repoDir.resolve(resFile2.getFileName());
    Files.copy(resFile2, destFile2, StandardCopyOption.REPLACE_EXISTING);
    try {
        Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL));
        List<ArtifactMetadata> artifacts = new ArrayList<>(testArtifacts);
        Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {

            @Override
            public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
                return o1.getId().compareTo(o2.getId());
            }
        });
        assertEquals(6, artifacts.size());
        ArtifactMetadata artifactMetadata = artifacts.get(0);
        assertEquals("test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId());
        MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
        assertEquals(1, facet.getBuildNumber());
        assertEquals("20100308.230825", facet.getTimestamp());
        assertNull(facet.getClassifier());
        assertEquals("jar", facet.getType());
        artifactMetadata = artifacts.get(1);
        assertEquals("test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId());
        facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
        assertEquals(1, facet.getBuildNumber());
        assertEquals("20100308.230825", facet.getTimestamp());
        assertNull(facet.getClassifier());
        assertEquals("pom", facet.getType());
        artifactMetadata = artifacts.get(2);
        assertEquals("test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId());
        facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
        assertEquals(2, facet.getBuildNumber());
        assertEquals("20100310.014828", facet.getTimestamp());
        assertEquals("javadoc", facet.getClassifier());
        assertEquals("javadoc", facet.getType());
        artifactMetadata = artifacts.get(3);
        assertEquals("test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId());
        facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
        assertEquals(2, facet.getBuildNumber());
        assertEquals("20100310.014828", facet.getTimestamp());
        assertEquals("sources", facet.getClassifier());
        assertEquals("java-source", facet.getType());
        artifactMetadata = artifacts.get(4);
        assertEquals("test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId());
        facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
        assertEquals(2, facet.getBuildNumber());
        assertEquals("20100310.014828", facet.getTimestamp());
        assertNull(facet.getClassifier());
        assertEquals("jar", facet.getType());
        artifactMetadata = artifacts.get(5);
        assertEquals("test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId());
        facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
        assertEquals(2, facet.getBuildNumber());
        assertEquals("20100310.014828", facet.getTimestamp());
        assertNull(facet.getClassifier());
        assertEquals("pom", facet.getType());
    } finally {
        Files.delete(destFile);
        Files.delete(destFile2);
    }
}
Also used : Path(java.nio.file.Path) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ArrayList(java.util.ArrayList) MavenArtifactFacet(org.apache.archiva.metadata.model.maven2.MavenArtifactFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)36 Test (org.junit.Test)31 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)20 ArrayList (java.util.ArrayList)16 RepositoryStorageMetadataNotFoundException (org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException)8 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)7 Dependency (org.apache.archiva.metadata.model.Dependency)7 RepositoryStorageMetadataInvalidException (org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException)6 RepositoryStorageRuntimeException (org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException)6 MavenArtifactFacet (org.apache.archiva.metadata.model.maven2.MavenArtifactFacet)3 Path (java.nio.file.Path)2 ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)2 RepositoryListener (org.apache.archiva.repository.events.RepositoryListener)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 URL (java.net.URL)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 NoSuchFileException (java.nio.file.NoSuchFileException)1