View Javadoc
1   package org.apache.maven.plugins.dependency.resolvers;
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.IOException;
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.artifact.versioning.VersionRange;
28  import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
29  import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
30  
31  public class ResolveDependenciesMojoTest
32      extends AbstractDependencyMojoTestCase
33  {
34      protected void setUp()
35          throws Exception
36      {
37          // required for mojo lookups to work
38          super.setUp( "dss", true );
39      }
40  
41      public void testDependencyStatusLog()
42          throws IOException
43      {
44          Set<Artifact> artifacts = this.stubFactory.getMixedArtifacts();
45          doTestDependencyStatusLog( artifacts );
46      }
47  
48      public void testDependencyStatusLogNullFiles()
49          throws IOException
50      {
51          this.stubFactory.setCreateFiles( false );
52          Set<Artifact> artifacts = this.stubFactory.getMixedArtifacts();
53          doTestDependencyStatusLog( artifacts );
54      }
55  
56      public void testDependencyStatusEmptySet()
57      {
58          doTestDependencyStatusLog( new HashSet<Artifact>() );
59      }
60      public void testOptionalDependencyFormatting() throws IOException
61      {
62          Set<Artifact> set = new HashSet<>();
63          Artifact artifact = stubFactory.createArtifact("g", "a", VersionRange.createFromVersion( "1.0"),
64                  "test", "jar", null, true);
65          set.add(artifact);
66          doTestDependencyStatusLog( set );
67          ResolveDependenciesMojo mojo = newMojo( new DependencyStatusSets() );
68          mojo.results.setResolvedDependencies( set );
69          String output = mojo.getOutput( false, true, false );
70          assertTrue( output.contains( "g:a:jar:1.0:test (optional)" + System.lineSeparator() ) );
71  
72      }
73  
74      public void doTestDependencyStatusLog( Set<Artifact> artifacts )
75      {
76          // TODO: implement logger to check correct output
77          // this test is just looking for unexpected exceptions.
78  
79          ResolveDependenciesMojo mojo = newMojo( new DependencyStatusSets() );
80          mojo.getOutput( false, true, false );
81          mojo.getOutput( true, true, false );
82  
83          mojo = newMojo( new DependencyStatusSets( artifacts, null, null ) );
84          mojo.getOutput( false, true, false );
85          mojo.getOutput( true, true, false );
86  
87          mojo = newMojo( new DependencyStatusSets( null, artifacts, null ) );
88          mojo.getOutput( false, true, false );
89          mojo.getOutput( true, true, false );
90  
91          mojo = newMojo( new DependencyStatusSets( null, null, artifacts ) );
92          mojo.getOutput( false, true, false );
93          mojo.getOutput( true, true, false );
94  
95          mojo = newMojo( new DependencyStatusSets( artifacts, artifacts, null ) );
96          mojo.getOutput( false, true, false );
97          mojo.getOutput( true, true, false );
98  
99          mojo = newMojo( new DependencyStatusSets( null, artifacts, artifacts ) );
100         mojo.getOutput( false, true, false );
101         mojo.getOutput( true, true, false );
102 
103         mojo = newMojo( new DependencyStatusSets( artifacts, null, artifacts ) );
104         mojo.getOutput( false, true, false );
105         mojo.getOutput( true, true, false );
106 
107         mojo = newMojo( new DependencyStatusSets( artifacts, artifacts, artifacts ) );
108         mojo.getOutput( false, true, false );
109         mojo.getOutput( true, true, false );
110         mojo.getOutput( false, false, false );
111         mojo.getOutput( true, false, false );
112     }
113 
114     private ResolveDependenciesMojo newMojo( final DependencyStatusSets dss )
115     {
116         ResolveDependenciesMojo mojo = new ResolveDependenciesMojo();
117         mojo.results = dss;
118         return mojo;
119     }
120 }