Search in sources :

Example 1 with TestRepositorySystemSession

use of org.sonatype.aether.test.impl.TestRepositorySystemSession in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testResolveFromWorkspace.

@Test
public void testResolveFromWorkspace() throws IOException, ArtifactResolutionException {
    session = new TestRepositorySystemSession() {

        @Override
        public WorkspaceReader getWorkspaceReader() {
            return new WorkspaceReader() {

                public WorkspaceRepository getRepository() {
                    return new WorkspaceRepository("default");
                }

                public List<String> findVersions(Artifact artifact) {
                    return Arrays.asList(artifact.getVersion());
                }

                public File findArtifact(Artifact artifact) {
                    try {
                        return TestFileUtils.createTempFile(artifact.toString());
                    } catch (IOException e) {
                        throw new RuntimeException(e.getMessage(), e);
                    }
                }
            };
        }
    };
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    ArtifactResult result = resolver.resolveArtifact(session, request);
    assertTrue(result.getExceptions().isEmpty());
    Artifact resolved = result.getArtifact();
    assertNotNull(resolved.getFile());
    byte[] expected = resolved.toString().getBytes("UTF-8");
    TestFileUtils.assertContent(expected, resolved.getFile());
    resolved = resolved.setFile(null);
    assertEquals(artifact, resolved);
    connector.assertSeenExpected();
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) IOException(java.io.IOException) WorkspaceReader(org.sonatype.aether.repository.WorkspaceReader) 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) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) WorkspaceRepository(org.sonatype.aether.repository.WorkspaceRepository) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 2 with TestRepositorySystemSession

use of org.sonatype.aether.test.impl.TestRepositorySystemSession in project sonatype-aether by sonatype.

the class DefaultDependencyCollectorTest method setup.

@Before
public void setup() throws IOException {
    session = new TestRepositorySystemSession();
    collector = new DefaultDependencyCollector();
    collector.setArtifactDescriptorReader(new IniArtifactDescriptorReader("artifact-descriptions/"));
    collector.setVersionRangeResolver(new StubVersionRangeResolver());
    collector.setRemoteRepositoryManager(new StubRemoteRepositoryManager());
    parser = new DependencyGraphParser("artifact-descriptions/");
    repository = new RemoteRepository("id", "default", "file:///");
}
Also used : TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) DependencyGraphParser(org.sonatype.aether.test.util.DependencyGraphParser) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Before(org.junit.Before)

Example 3 with TestRepositorySystemSession

use of org.sonatype.aether.test.impl.TestRepositorySystemSession in project sonatype-aether by sonatype.

the class DefaultMetadataResolverTest method setup.

@Before
public void setup() throws Exception {
    session = new TestRepositorySystemSession();
    // session.setLocalRepositoryManager( new EnhancedLocalRepositoryManager( TestFileUtils.createTempDir() ) );
    lrm = (TestLocalRepositoryManager) session.getLocalRepositoryManager();
    manager = new StubRemoteRepositoryManager();
    resolver = new DefaultMetadataResolver();
    resolver.setUpdateCheckManager(new StaticUpdateCheckManager(true));
    resolver.setRepositoryEventDispatcher(new StubRepositoryEventDispatcher());
    resolver.setRemoteRepositoryManager(manager);
    resolver.setSyncContextFactory(new StubSyncContextFactory());
    repository = new RemoteRepository("test-DMRT", "default", TestFileUtils.createTempDir().toURI().toURL().toString());
    metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
    connector = new RecordingRepositoryConnector();
    manager.setConnector(connector);
}
Also used : TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Before(org.junit.Before)

Example 4 with TestRepositorySystemSession

use of org.sonatype.aether.test.impl.TestRepositorySystemSession in project sonatype-aether by sonatype.

the class DefaultRepositoryEventDispatcherTest method testDispatchHandlesAllEventTypes.

@Test
public void testDispatchHandlesAllEventTypes() throws Exception {
    DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher();
    ListenerHandler handler = new ListenerHandler();
    RepositoryListener listener = (RepositoryListener) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { RepositoryListener.class }, handler);
    TestRepositorySystemSession session = new TestRepositorySystemSession();
    session.setRepositoryListener(listener);
    for (RepositoryEvent.EventType type : RepositoryEvent.EventType.values()) {
        DefaultRepositoryEvent event = new DefaultRepositoryEvent(type, session, null);
        handler.methodName = null;
        dispatcher.dispatch(event);
        assertNotNull("not handled: " + type, handler.methodName);
        assertEquals("badly handled: " + type, type.name().replace("_", "").toLowerCase(Locale.ENGLISH), handler.methodName.toLowerCase(Locale.ENGLISH));
    }
}
Also used : RepositoryListener(org.sonatype.aether.RepositoryListener) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) DefaultRepositoryEvent(org.sonatype.aether.util.listener.DefaultRepositoryEvent) RepositoryEvent(org.sonatype.aether.RepositoryEvent) DefaultRepositoryEvent(org.sonatype.aether.util.listener.DefaultRepositoryEvent) Test(org.junit.Test)

Example 5 with TestRepositorySystemSession

use of org.sonatype.aether.test.impl.TestRepositorySystemSession in project sonatype-aether by sonatype.

the class EnhancedLocalRepositoryManagerTest method setup.

@Before
public void setup() throws Exception {
    repository = new RemoteRepository("enhanced-remote-repo", "default", TestFileUtils.createTempDir("enhanced-remote-repo").toURI().toURL().toString());
    repository.setRepositoryManager(true);
    artifact = new DefaultArtifact("gid", "aid", "", "jar", "1-test", Collections.<String, String>emptyMap(), TestFileUtils.createTempFile("artifact"));
    metadata = new DefaultMetadata("gid", "aid", "1-test", "maven-metadata.xml", Nature.RELEASE, TestFileUtils.createTempFile("metadata"));
    noVerMetadata = new DefaultMetadata("gid", "aid", null, "maven-metadata.xml", Nature.RELEASE, TestFileUtils.createTempFile("metadata"));
    basedir = TestFileUtils.createTempDir("enhanced-repo");
    manager = new EnhancedLocalRepositoryManager(basedir);
    artifactFile = new File(basedir, manager.getPathForLocalArtifact(artifact));
    session = new TestRepositorySystemSession();
}
Also used : TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) DefaultMetadata(org.sonatype.aether.util.metadata.DefaultMetadata) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) File(java.io.File) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) Before(org.junit.Before)

Aggregations

TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)17 Before (org.junit.Before)14 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)9 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)6 File (java.io.File)5 Test (org.junit.Test)3 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)3 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)3 DefaultMetadata (org.sonatype.aether.util.metadata.DefaultMetadata)3 List (java.util.List)2 Artifact (org.sonatype.aether.artifact.Artifact)2 UpdateCheckManager (org.sonatype.aether.impl.UpdateCheckManager)2 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)2 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)2 WorkspaceReader (org.sonatype.aether.repository.WorkspaceReader)2 WorkspaceRepository (org.sonatype.aether.repository.WorkspaceRepository)2 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)2 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)2 RecordingRepositoryListener (org.sonatype.aether.test.impl.RecordingRepositoryListener)2 SysoutLogger (org.sonatype.aether.test.impl.SysoutLogger)2