View Javadoc
1   package org.apache.maven.repository.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.net.MalformedURLException;
23  
24  import org.apache.maven.repository.internal.util.ConsoleRepositoryListener;
25  import org.apache.maven.repository.internal.util.ConsoleTransferListener;
26  import org.codehaus.plexus.ContainerConfiguration;
27  import org.codehaus.plexus.PlexusConstants;
28  import org.codehaus.plexus.PlexusTestCase;
29  import org.eclipse.aether.DefaultRepositorySystemSession;
30  import org.eclipse.aether.RepositorySystem;
31  import org.eclipse.aether.RepositorySystemSession;
32  import org.eclipse.aether.repository.LocalRepository;
33  import org.eclipse.aether.repository.RemoteRepository;
34  
35  public abstract class AbstractRepositoryTestCase
36      extends PlexusTestCase
37  {
38      protected RepositorySystem system;
39  
40      protected RepositorySystemSession session;
41  
42      @Override
43      protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
44      {
45          super.customizeContainerConfiguration( containerConfiguration );
46          containerConfiguration.setAutoWiring( true );
47          containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
48      }
49  
50      @Override
51      protected void setUp()
52          throws Exception
53      {
54          super.setUp();
55          system = lookup( RepositorySystem.class );
56          session = newMavenRepositorySystemSession( system );
57      }
58  
59      @Override
60      protected void tearDown()
61          throws Exception
62      {
63          session = null;
64          system = null;
65          super.tearDown();
66      }
67  
68      public static RepositorySystemSession newMavenRepositorySystemSession( RepositorySystem system )
69      {
70          DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
71  
72          LocalRepository localRepo = new LocalRepository( "target/local-repo" );
73          session.setLocalRepositoryManager( system.newLocalRepositoryManager( session, localRepo ) );
74  
75          session.setTransferListener( new ConsoleTransferListener() );
76          session.setRepositoryListener( new ConsoleRepositoryListener() );
77  
78          return session;
79      }
80  
81      public static RemoteRepository newTestRepository()
82          throws MalformedURLException
83      {
84          return new RemoteRepository.Builder( "repo", "default",
85                                               getTestFile( "target/test-classes/repo" ).toURI().toURL().toString() ).build();
86      }
87  }