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