Search in sources :

Example 1 with ArtifactTransferException

use of org.sonatype.aether.transfer.ArtifactTransferException in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckArtifactUpdatePolicyRequired.

@Test
public void testCheckArtifactUpdatePolicyRequired() throws Exception {
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    check.setItem(artifact);
    check.setFile(artifact.getFile());
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.add(Calendar.DATE, -1);
    long lastUpdate = cal.getTimeInMillis();
    artifact.getFile().setLastModified(lastUpdate);
    check.setLocalLastUpdated(lastUpdate);
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
    manager.checkArtifact(session, check);
    assertNull(check.getException());
    assertTrue(check.isRequired());
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    manager.checkArtifact(session, check);
    assertNull(check.getException());
    assertTrue(check.isRequired());
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":60");
    manager.checkArtifact(session, check);
    assertNull(check.getException());
    assertTrue(check.isRequired());
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) Calendar(java.util.Calendar) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 2 with ArtifactTransferException

use of org.sonatype.aether.transfer.ArtifactTransferException in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckArtifactUpdatePolicyNotRequired.

@Test
public void testCheckArtifactUpdatePolicyNotRequired() throws Exception {
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    check.setItem(artifact);
    check.setFile(artifact.getFile());
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.add(Calendar.HOUR_OF_DAY, -1);
    check.setLocalLastUpdated(cal.getTimeInMillis());
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_NEVER);
    manager.checkArtifact(session, check);
    assertFalse(check.isRequired());
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    manager.checkArtifact(session, check);
    assertFalse(check.isRequired());
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":61");
    manager.checkArtifact(session, check);
    assertFalse(check.isRequired());
    check.setPolicy("no particular policy");
    manager.checkArtifact(session, check);
    assertFalse(check.isRequired());
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) Calendar(java.util.Calendar) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 3 with ArtifactTransferException

use of org.sonatype.aether.transfer.ArtifactTransferException in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckArtifact.

@Test
public void testCheckArtifact() throws Exception {
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    long fifteenMinutes = new Date().getTime() - (15 * 60 * 1000);
    check.getFile().setLastModified(fifteenMinutes);
    // time is truncated on setLastModfied
    fifteenMinutes = check.getFile().lastModified();
    // never checked before
    manager.checkArtifact(session, check);
    assertEquals(true, check.isRequired());
    // just checked
    check.setLocalLastUpdated(0);
    long lastUpdate = new Date().getTime();
    check.getFile().setLastModified(lastUpdate);
    lastUpdate = check.getFile().lastModified();
    manager.checkArtifact(session, check);
    assertEquals(false, check.isRequired());
    // no local file, no repo timestamp
    check.setLocalLastUpdated(0);
    check.getFile().delete();
    manager.checkArtifact(session, check);
    assertEquals(true, check.isRequired());
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Date(java.util.Date) Test(org.junit.Test)

Example 4 with ArtifactTransferException

use of org.sonatype.aether.transfer.ArtifactTransferException in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckArtifactErrorFromRepoCachingEnabled.

@Test
public void testCheckArtifactErrorFromRepoCachingEnabled() throws Exception {
    artifact.getFile().delete();
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    check.setException(new ArtifactTransferException(artifact, repository, "some error"));
    manager.touchArtifact(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired && previousError -> depends on transfer error caching
    check = newArtifactCheck();
    session.setTransferErrorCachingEnabled(true);
    manager.checkArtifact(session, check);
    assertEquals(false, check.isRequired());
    assertTrue(check.getException() instanceof ArtifactTransferException);
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 5 with ArtifactTransferException

use of org.sonatype.aether.transfer.ArtifactTransferException in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckArtifactNotFoundInRepoCachingEnabled.

@Test
public void testCheckArtifactNotFoundInRepoCachingEnabled() throws Exception {
    artifact.getFile().delete();
    session.setNotFoundCachingEnabled(true);
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    check.setException(new ArtifactNotFoundException(artifact, repository));
    manager.touchArtifact(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired -> artifact not found in remote repo
    check = newArtifactCheck().setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    manager.checkArtifact(session, check);
    assertEquals(false, check.isRequired());
    assertTrue(check.getException() instanceof ArtifactNotFoundException);
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Aggregations

ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)16 Test (org.junit.Test)12 Artifact (org.sonatype.aether.artifact.Artifact)12 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)9 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)7 File (java.io.File)4 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)4 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)4 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)4 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)4 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)4 Collection (java.util.Collection)3 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)3 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)3 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)3 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)3 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 MetadataTransferException (org.sonatype.aether.transfer.MetadataTransferException)2 FileNotFoundException (java.io.FileNotFoundException)1