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