Search in sources :

Example 16 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataToolsTest method assertUpdatedProjectMetadata.

private void assertUpdatedProjectMetadata(String artifactId, String[] expectedVersions, String latestVersion, String releaseVersion) throws Exception {
    ManagedRepositoryContent testRepo = createTestRepoContent();
    ProjectReference reference = new ProjectReference();
    reference.setGroupId("org.apache.archiva.metadata.tests");
    reference.setArtifactId(artifactId);
    prepTestRepo(testRepo, reference);
    tools.updateMetadata(testRepo, reference);
    StringBuilder buf = new StringBuilder();
    buf.append("<metadata>\n");
    buf.append("  <groupId>").append(reference.getGroupId()).append("</groupId>\n");
    buf.append("  <artifactId>").append(reference.getArtifactId()).append("</artifactId>\n");
    if (expectedVersions != null) {
        buf.append("  <versioning>\n");
        if (latestVersion != null) {
            buf.append("    <latest>").append(latestVersion).append("</latest>\n");
        }
        if (releaseVersion != null) {
            buf.append("    <release>").append(releaseVersion).append("</release>\n");
        }
        buf.append("    <versions>\n");
        for (int i = 0; i < expectedVersions.length; i++) {
            buf.append("      <version>").append(expectedVersions[i]).append("</version>\n");
        }
        buf.append("    </versions>\n");
        buf.append("  </versioning>\n");
    }
    buf.append("</metadata>");
    assertMetadata(buf.toString(), testRepo, reference);
}
Also used : ProjectReference(org.apache.archiva.model.ProjectReference) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent)

Example 17 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataToolsTest method prepTestRepo.

private void prepTestRepo(ManagedRepositoryContent repo, VersionedReference reference) throws IOException {
    ProjectReference projectRef = new ProjectReference();
    projectRef.setGroupId(reference.getGroupId());
    projectRef.setArtifactId(reference.getArtifactId());
    prepTestRepo(repo, projectRef);
}
Also used : ProjectReference(org.apache.archiva.model.ProjectReference)

Example 18 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataToolsTest method testUpdateProjectNonExistingVersion.

// TODO: replace with group tests
// public void testUpdateProjectBadArtifact()
// throws Exception
// {
// try
// {
// assertUpdatedProjectMetadata( "bad_artifact", null );
// fail( "Should have thrown an IOException on a bad artifact." );
// }
// catch ( IOException e )
// {
// // Expected path
// }
// }
@Test
public void testUpdateProjectNonExistingVersion() throws Exception {
    ManagedRepositoryContent testRepo = createTestRepoContent();
    ProjectReference reference = new ProjectReference();
    reference.setGroupId("org.apache.archiva.metadata.tests");
    reference.setArtifactId("missing_artifact");
    prepTestRepo(testRepo, reference);
    // check metadata prior to update -- should contain the non-existing artifact version
    assertProjectMetadata(testRepo, reference, "missing_artifact", new String[] { "1.0-SNAPSHOT", "1.1-SNAPSHOT", "1.2-SNAPSHOT" }, "1.2-SNAPSHOT", null);
    tools.updateMetadata(testRepo, reference);
    // metadata should not contain the non-existing artifact version -- 1.1-SNAPSHOT
    assertProjectMetadata(testRepo, reference, "missing_artifact", new String[] { "1.0-SNAPSHOT", "1.2-SNAPSHOT" }, "1.2-SNAPSHOT", null);
}
Also used : ProjectReference(org.apache.archiva.model.ProjectReference) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) Test(org.junit.Test)

Example 19 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class MetadataToolsTest method assertProjectReference.

private void assertProjectReference(String groupId, String artifactId, String path) throws RepositoryMetadataException {
    ProjectReference reference = tools.toProjectReference(path);
    assertNotNull("Reference should not be null.", reference);
    assertEquals("ProjectReference.groupId", groupId, reference.getGroupId());
    assertEquals("ProjectReference.artifactId", artifactId, reference.getArtifactId());
}
Also used : ProjectReference(org.apache.archiva.model.ProjectReference)

Example 20 with ProjectReference

use of org.apache.archiva.model.ProjectReference in project archiva by apache.

the class ManagedDefaultRepositoryContentTest method assertGetVersions.

private void assertGetVersions(String artifactId, List<String> expectedVersions) throws Exception {
    ProjectReference reference = new ProjectReference();
    reference.setGroupId("org.apache.archiva.metadata.tests");
    reference.setArtifactId(artifactId);
    // Use the test metadata-repository, which is already setup for
    // These kind of version tests.
    Path repoDir = Paths.get("src/test/repositories/metadata-repository");
    ((EditableManagedRepository) repoContent.getRepository()).setLocation(repoDir.toAbsolutePath().toUri());
    // Request the versions.
    Set<String> testedVersionSet = repoContent.getVersions(reference);
    // Sort the list (for asserts)
    List<String> testedVersions = new ArrayList<>();
    testedVersions.addAll(testedVersionSet);
    Collections.sort(testedVersions, new VersionComparator());
    // Test the expected array of versions, to the actual tested versions
    assertEquals("available versions", expectedVersions, testedVersions);
}
Also used : Path(java.nio.file.Path) ProjectReference(org.apache.archiva.model.ProjectReference) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ArrayList(java.util.ArrayList) VersionComparator(org.apache.archiva.common.utils.VersionComparator)

Aggregations

ProjectReference (org.apache.archiva.model.ProjectReference)20 Path (java.nio.file.Path)11 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 VersionedReference (org.apache.archiva.model.VersionedReference)3 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)3 LayoutException (org.apache.archiva.repository.LayoutException)3 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)2 ArtifactReference (org.apache.archiva.model.ArtifactReference)2 RepositoryException (org.apache.archiva.repository.RepositoryException)2 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)2 URI (java.net.URI)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1