View Javadoc
1   package org.apache.maven.plugins.dependency;
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 org.apache.maven.execution.MavenSession;
23  import org.apache.maven.plugin.LegacySupport;
24  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
25  import org.apache.maven.settings.Server;
26  import org.apache.maven.settings.Settings;
27  
28  import java.io.File;
29  
30  public class TestListClassesMojo
31          extends AbstractDependencyMojoTestCase
32  {
33      private ListClassesMojo mojo;
34  
35      protected void setUp()
36              throws Exception
37      {
38          super.setUp( "markers", false );
39          File testPom = new File( getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml" );
40  
41          assertTrue( testPom.exists() );
42          mojo = (ListClassesMojo) lookupMojo( "list-classes", testPom );
43  
44          assertNotNull( mojo );
45  
46          LegacySupport legacySupport = lookup( LegacySupport.class );
47          MavenSession session = newMavenSession( new MavenProjectStub() );
48          Settings settings = session.getSettings();
49          Server server = new Server();
50          server.setId( "myserver" );
51          server.setUsername( "foo" );
52          server.setPassword( "bar" );
53          settings.addServer( server );
54          legacySupport.setSession( session );
55  
56          installLocalRepository( legacySupport );
57  
58          setVariableValueToObject( mojo, "session", legacySupport.getSession() );
59      }
60      
61      public void testListClassesNotTransitive()
62              throws Exception
63      {
64          setVariableValueToObject( mojo, "remoteRepositories", "central::default::https://repo.maven.apache.org/maven2,"
65                  + "central::::https://repo.maven.apache.org/maven2," + "https://repo.maven.apache.org/maven2" );
66          setVariableValueToObject( mojo, "artifact", "org.apache.commons:commons-lang3:3.6" );
67          setVariableValueToObject( mojo, "transitive", Boolean.FALSE );
68  
69          mojo.execute();
70      }
71  
72      public void testListClassesTransitive()
73              throws Exception
74      {
75          setVariableValueToObject( mojo, "remoteRepositories", "central::default::https://repo.maven.apache.org/maven2,"
76                  + "central::::https://repo.maven.apache.org/maven2," + "https://repo.maven.apache.org/maven2" );
77          setVariableValueToObject( mojo, "artifact", "org.apache.commons:commons-lang3:3.6" );
78          setVariableValueToObject( mojo, "transitive", Boolean.TRUE );
79  
80          mojo.execute();
81      }
82  }