View Javadoc
1   package org.apache.maven.plugins.assembly.artifact;
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 junit.framework.TestCase;
23  import org.apache.maven.artifact.Artifact;
24  import org.apache.maven.artifact.DefaultArtifact;
25  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
26  import org.apache.maven.artifact.versioning.VersionRange;
27  
28  import java.util.Arrays;
29  import java.util.Collections;
30  import java.util.HashSet;
31  
32  public class ResolutionManagementInfoTest
33      extends TestCase
34  {
35  
36      public void testName()
37          throws Exception
38      {
39  
40      }
41  
42      public void testAddSingleArtifactWithReplacemen()
43          throws Exception
44      {
45          ResolutionManagementInfo rmi = new ResolutionManagementInfo();
46          Artifact a1 = new DefaultArtifact( "groupid", "1", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
47                                             new DefaultArtifactHandler() );
48          rmi.addArtifacts( Collections.singleton( a1 ) );
49          Artifact a2 =
50              new DefaultArtifact( "groupid", "1", VersionRange.createFromVersion( "1.0" ), "compile", "jar", null,
51                                   new DefaultArtifactHandler() );
52          rmi.addArtifacts( Collections.singleton( a2 ) );
53          assertEquals( 1, rmi.getArtifacts().size() );
54          Artifact next = rmi.getArtifacts().iterator().next();
55          assertEquals( "compile", next.getScope() );
56      }
57  
58      public void testAddMultiArtifactWithReplacemen()
59          throws Exception
60      {
61          ResolutionManagementInfo rmi = new ResolutionManagementInfo();
62          Artifact a1 =
63              new DefaultArtifact( "groupid", "a1", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
64                                   new DefaultArtifactHandler() );
65          Artifact a2 =
66              new DefaultArtifact( "groupid", "a2", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
67                                   new DefaultArtifactHandler() );
68          Artifact a3 =
69              new DefaultArtifact( "groupid", "a3", VersionRange.createFromVersion( "1.0" ), "test", "jar", null,
70                                   new DefaultArtifactHandler() );
71          rmi.addArtifacts( new HashSet<>( Arrays.asList( a1, a2, a3 ) ) );
72          Artifact b2 =
73              new DefaultArtifact( "groupid", "a2", VersionRange.createFromVersion( "1.0" ), "compile", "jar", null,
74                                   new DefaultArtifactHandler() );
75          Artifact b3 =
76              new DefaultArtifact( "groupid", "a3", VersionRange.createFromVersion( "1.0" ), "compile", "jar", null,
77                                   new DefaultArtifactHandler() );
78          rmi.addArtifacts( new HashSet<>( Arrays.asList( b2, b3 ) ) );
79          assertEquals( 3, rmi.getArtifacts().size() );
80          int compile = 0;
81          int test = 0;
82          for ( Artifact artifact : rmi.getArtifacts() )
83          {
84              if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
85              {
86                  compile++;
87              }
88              else
89              {
90                  test++;
91              }
92          }
93          assertEquals( 2, compile );
94          assertEquals( 1, test );
95      }
96  }