Search in sources :

Example 16 with Metadata

use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository.

@Test
public void testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository() throws ArtifactResolutionException {
    session.setLocalRepositoryManager(new LocalRepositoryManager() {

        public LocalRepository getRepository() {
            return null;
        }

        public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
            return null;
        }

        public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
            return null;
        }

        public String getPathForLocalMetadata(Metadata metadata) {
            return null;
        }

        public String getPathForLocalArtifact(Artifact artifact) {
            return null;
        }

        public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
            LocalArtifactResult result = new LocalArtifactResult(request);
            result.setAvailable(false);
            try {
                result.setFile(TestFileUtils.createTempFile(""));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }

        public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
        }

        public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
            LocalMetadataResult result = new LocalMetadataResult(request);
            return result;
        }

        public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    resolver.setVersionResolver(new VersionResolver() {

        public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
            return new VersionResult(request).setRepository(new LocalRepository("id")).setVersion(request.getArtifact().getVersion());
        }
    });
    ArtifactResult result = resolver.resolveArtifact(session, request);
    assertTrue(result.getExceptions().isEmpty());
    Artifact resolved = result.getArtifact();
    assertNotNull(resolved.getFile());
    resolved = resolved.setFile(null);
    assertEquals(artifact, resolved);
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) LocalArtifactRegistration(org.sonatype.aether.repository.LocalArtifactRegistration) LocalMetadataRequest(org.sonatype.aether.repository.LocalMetadataRequest) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) LocalMetadataRegistration(org.sonatype.aether.repository.LocalMetadataRegistration) LocalRepository(org.sonatype.aether.repository.LocalRepository) Metadata(org.sonatype.aether.metadata.Metadata) VersionRequest(org.sonatype.aether.resolution.VersionRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) IOException(java.io.IOException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) VersionResolver(org.sonatype.aether.impl.VersionResolver) VersionResult(org.sonatype.aether.resolution.VersionResult) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) TestLocalRepositoryManager(org.sonatype.aether.test.impl.TestLocalRepositoryManager) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) VersionResolutionException(org.sonatype.aether.resolution.VersionResolutionException) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Example 17 with Metadata

use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.

the class ConnectorTestSuite method testProgressEventsDataBuffer.

@Test
public void testProgressEventsDataBuffer() throws UnsupportedEncodingException, IOException, NoSuchAlgorithmException, NoRepositoryConnectorException {
    byte[] bytes = "These are the test contents.\n".getBytes("UTF-8");
    int count = 120000;
    MessageDigest digest = MessageDigest.getInstance("SHA-1");
    for (int i = 0; i < count; i++) {
        digest.update(bytes);
    }
    byte[] hash = digest.digest();
    File file = TestFileUtils.createTempFile(bytes, count);
    Artifact artifact = new StubArtifact("gid:aid:ext:ver");
    ArtifactUpload upA = new ArtifactUpload(artifact, file);
    File dir = TestFileUtils.createTempDir("con-test");
    File downAFile = new File(dir, "downA.file");
    downAFile.deleteOnExit();
    ArtifactDownload downA = new ArtifactDownload(artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    Metadata metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
    MetadataUpload upM = new MetadataUpload(metadata, file);
    File downMFile = new File(dir, "downM.file");
    downMFile.deleteOnExit();
    MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    DigestingTransferListener listener = new DigestingTransferListener();
    session.setTransferListener(listener);
    RepositoryConnector connector = factory().newInstance(session, repository);
    connector.put(Arrays.asList(upA), null);
    assertArrayEquals(hash, listener.getHash());
    listener.rewind();
    connector.put(null, Arrays.asList(upM));
    assertArrayEquals(hash, listener.getHash());
    listener.rewind();
    connector.get(Arrays.asList(downA), null);
    assertArrayEquals(hash, listener.getHash());
    listener.rewind();
    connector.get(null, Arrays.asList(downM));
    assertArrayEquals(hash, listener.getHash());
    listener.rewind();
    connector.close();
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) MessageDigest(java.security.MessageDigest) File(java.io.File) Test(org.junit.Test)

Example 18 with Metadata

use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckMetadataErrorFromRepo.

@Test
public void testCheckMetadataErrorFromRepo() throws Exception {
    metadata.getFile().delete();
    UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    check.setException(new MetadataTransferException(metadata, repository, "some error"));
    manager.touchMetadata(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired && previousError -> depends on transfer error caching
    check = newMetadataCheck();
    session.setTransferErrorCachingEnabled(true);
    manager.checkMetadata(session, check);
    assertEquals(false, check.isRequired());
    assertTrue(check.getException() instanceof MetadataTransferException);
    assertTrue(String.valueOf(check.getException()), check.getException().getMessage().contains("some error"));
}
Also used : StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException) Test(org.junit.Test)

Example 19 with Metadata

use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckMetadataErrorFromRepoNoCaching.

@Test
public void testCheckMetadataErrorFromRepoNoCaching() throws Exception {
    metadata.getFile().delete();
    UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    check.setException(new MetadataTransferException(metadata, repository, "some error"));
    manager.touchMetadata(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired && previousError -> depends on transfer error caching
    check = newMetadataCheck();
    session.setTransferErrorCachingEnabled(false);
    manager.checkMetadata(session, check);
    assertEquals(true, check.isRequired());
    assertNull(check.getException());
}
Also used : StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException) Test(org.junit.Test)

Example 20 with Metadata

use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.

the class PutTest method testClosedPut.

@Test(expected = Exception.class)
public void testClosedPut() throws Exception {
    connector().close();
    Metadata metadata = metadata("metadata");
    List<MetadataUpload> uploads = Arrays.asList(new MetadataUpload(metadata, metadata.getFile()));
    connector().put(null, uploads);
}
Also used : Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) Test(org.junit.Test)

Aggregations

Metadata (org.sonatype.aether.metadata.Metadata)27 Test (org.junit.Test)15 Artifact (org.sonatype.aether.artifact.Artifact)10 File (java.io.File)9 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)9 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)8 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)7 MetadataTransferException (org.sonatype.aether.transfer.MetadataTransferException)7 IOException (java.io.IOException)6 LocalMetadataResult (org.sonatype.aether.repository.LocalMetadataResult)6 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)6 ArrayList (java.util.ArrayList)5 LocalMetadataRequest (org.sonatype.aether.repository.LocalMetadataRequest)5 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)5 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)5 LocalRepository (org.sonatype.aether.repository.LocalRepository)4 MetadataNotFoundException (org.sonatype.aether.transfer.MetadataNotFoundException)4 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)3 RequestTrace (org.sonatype.aether.RequestTrace)3 LocalArtifactRegistration (org.sonatype.aether.repository.LocalArtifactRegistration)3