View Javadoc
1   package org.apache.maven.plugin.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, new DefaultArtifactHandler() );
48          rmi.addArtifacts( Collections.singleton( a1));
49          Artifact a2 = new DefaultArtifact( "groupid", "1", VersionRange.createFromVersion("1.0"), "compile", "jar", null, new DefaultArtifactHandler() );
50          rmi.addArtifacts( Collections.singleton( a2));
51          assertEquals( 1, rmi.getArtifacts().size());
52          Artifact next = rmi.getArtifacts().iterator().next();
53          assertEquals("compile", next.getScope());
54      }
55  
56      public void testAddMultiArtifactWithReplacemen()
57          throws Exception
58      {
59          ResolutionManagementInfo rmi = new ResolutionManagementInfo( new MavenProject(  ) );
60          Artifact a1 = new DefaultArtifact( "groupid", "a1", VersionRange.createFromVersion("1.0"), "test", "jar", null, new DefaultArtifactHandler() );
61          Artifact a2 = new DefaultArtifact( "groupid", "a2", VersionRange.createFromVersion("1.0"), "test", "jar", null, new DefaultArtifactHandler() );
62          Artifact a3 = new DefaultArtifact( "groupid", "a3", VersionRange.createFromVersion("1.0"), "test", "jar", null, new DefaultArtifactHandler() );
63          rmi.addArtifacts( new HashSet<Artifact>( Arrays.asList( a1, a2, a3 )));
64          Artifact b2 = new DefaultArtifact( "groupid", "a2", VersionRange.createFromVersion("1.0"), "compile", "jar", null, new DefaultArtifactHandler() );
65          Artifact b3 = new DefaultArtifact( "groupid", "a3", VersionRange.createFromVersion("1.0"), "compile", "jar", null, new DefaultArtifactHandler() );
66          rmi.addArtifacts( new HashSet<Artifact>( Arrays.asList( b2, b3)));
67          assertEquals( 3, rmi.getArtifacts().size());
68          int compile = 0;
69          int test = 0;
70          for ( Artifact artifact : rmi.getArtifacts() )
71          {
72              if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() )) compile++;
73              else test++;
74          }
75          assertEquals(2, compile);
76          assertEquals(1, test);
77      }
78  }