View Javadoc
1   package org.apache.maven.shared.transfer.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.io.File;
23  
24  import org.apache.maven.project.DefaultProjectBuildingRequest;
25  import org.apache.maven.project.ProjectBuildingRequest;
26  import org.apache.maven.repository.internal.MavenRepositorySystemSession;
27  import org.apache.maven.shared.transfer.repository.internal.Maven30RepositoryManager;
28  import org.codehaus.plexus.PlexusTestCase;
29  import org.sonatype.aether.RepositorySystem;
30  import org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager;
31  import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
32  
33  public class Maven30RepositoryManagerTest extends PlexusTestCase
34  {
35  
36      private final File localRepo = new File( "target/tests/local-repo" );
37      
38      private RepositorySystem repositorySystem;
39  
40      @Override
41      public void setUp() throws Exception
42      {
43          super.setUp();
44          repositorySystem = lookup( RepositorySystem.class );
45      }
46      
47      public void testSetLocalRepositoryBasedirSimple()
48      {
49          DefaultProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
50          MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
51          repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
52          buildingRequest.setRepositorySession( repositorySession );
53  
54          File basedir = new File( "NEW/LOCAL/REPO" );
55          
56          Maven30RepositoryManager repositoryManager =
57              new Maven30RepositoryManager( repositorySystem, buildingRequest.getRepositorySession() );
58          
59          ProjectBuildingRequest newBuildingRequest = repositoryManager.setLocalRepositoryBasedir( buildingRequest, basedir );
60          
61          assertEquals( basedir.getAbsoluteFile(), newBuildingRequest.getRepositorySession().getLocalRepository().getBasedir() );
62          
63      }
64  
65      public void testSetLocalRepositoryBasedirEnhanced()
66      {
67          DefaultProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
68          MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
69          repositorySession.setLocalRepositoryManager( new EnhancedLocalRepositoryManager( localRepo ) );
70          buildingRequest.setRepositorySession( repositorySession );
71  
72          File basedir = new File( "NEW/LOCAL/REPO" );
73          
74          Maven30RepositoryManager repositoryManager =
75              new Maven30RepositoryManager( repositorySystem, buildingRequest.getRepositorySession() );
76          
77          ProjectBuildingRequest newBuildingRequest = repositoryManager.setLocalRepositoryBasedir( buildingRequest, basedir );
78          
79          assertEquals( basedir.getAbsoluteFile(), newBuildingRequest.getRepositorySession().getLocalRepository().getBasedir() );
80          
81      }
82  
83  }