View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.internal;
20  
21  import javax.inject.Inject;
22  
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.artifact.DefaultArtifact;
25  import org.eclipse.aether.resolution.VersionRequest;
26  import org.eclipse.aether.resolution.VersionResult;
27  import org.junit.jupiter.api.Test;
28  
29  import static org.junit.jupiter.api.Assertions.assertEquals;
30  
31  class DefaultVersionResolverTest extends AbstractRepositoryTestCase {
32      @Inject
33      private DefaultVersionResolver versionResolver;
34  
35      @Test
36      void testResolveSeparateInstalledClassifiedNonUniqueVersionedArtifacts() throws Exception {
37          VersionRequest requestB = new VersionRequest();
38          requestB.addRepository(newTestRepository());
39          Artifact artifactB =
40                  new DefaultArtifact("org.apache.maven.its", "dep-mng5324", "classifierB", "jar", "07.20.3-SNAPSHOT");
41          requestB.setArtifact(artifactB);
42  
43          VersionResult resultB = versionResolver.resolveVersion(session, requestB);
44          assertEquals("07.20.3-20120809.112920-97", resultB.getVersion());
45  
46          VersionRequest requestA = new VersionRequest();
47          requestA.addRepository(newTestRepository());
48  
49          Artifact artifactA =
50                  new DefaultArtifact("org.apache.maven.its", "dep-mng5324", "classifierA", "jar", "07.20.3-SNAPSHOT");
51          requestA.setArtifact(artifactA);
52  
53          VersionResult resultA = versionResolver.resolveVersion(session, requestA);
54          assertEquals("07.20.3-20120809.112124-88", resultA.getVersion());
55      }
56  
57      @Test
58      void testResolveSeparateInstalledClassifiedNonVersionedArtifacts() throws Exception {
59          VersionRequest requestA = new VersionRequest();
60          requestA.addRepository(newTestRepository());
61          String versionA = "07.20.3-20120809.112124-88";
62          Artifact artifactA = new DefaultArtifact("org.apache.maven.its", "dep-mng5324", "classifierA", "jar", versionA);
63          requestA.setArtifact(artifactA);
64  
65          VersionResult resultA = versionResolver.resolveVersion(session, requestA);
66          assertEquals(versionA, resultA.getVersion());
67  
68          VersionRequest requestB = new VersionRequest();
69          requestB.addRepository(newTestRepository());
70          String versionB = "07.20.3-20120809.112920-97";
71          Artifact artifactB = new DefaultArtifact("org.apache.maven.its", "dep-mng5324", "classifierB", "jar", versionB);
72          requestB.setArtifact(artifactB);
73  
74          VersionResult resultB = versionResolver.resolveVersion(session, requestB);
75          assertEquals(versionB, resultB.getVersion());
76      }
77  }