Search in sources :

Example 11 with Artifact

use of org.sonatype.aether.artifact.Artifact 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 12 with Artifact

use of org.sonatype.aether.artifact.Artifact 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 13 with Artifact

use of org.sonatype.aether.artifact.Artifact 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 14 with Artifact

use of org.sonatype.aether.artifact.Artifact 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)

Example 15 with Artifact

use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckArtifactErrorFromRepoCachingDisabled.

@Test
public void testCheckArtifactErrorFromRepoCachingDisabled() 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(false);
    manager.checkArtifact(session, check);
    assertEquals(true, check.isRequired());
    assertNull(check.getException());
}
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)

Aggregations

Artifact (org.sonatype.aether.artifact.Artifact)116 Test (org.junit.Test)63 File (java.io.File)33 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)30 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)28 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)27 Dependency (org.sonatype.aether.graph.Dependency)22 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)17 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)16 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)15 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)15 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)14 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)13 SubArtifact (org.sonatype.aether.util.artifact.SubArtifact)13 ArrayList (java.util.ArrayList)12 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)12 Metadata (org.sonatype.aether.metadata.Metadata)10 RepositorySystem (org.sonatype.aether.RepositorySystem)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8