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.legacy.resolver.conflict;
20  
21  import javax.inject.Inject;
22  
23  import java.util.Collections;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.factory.ArtifactFactory;
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.artifact.resolver.ResolutionNode;
29  import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
30  import org.apache.maven.artifact.versioning.VersionRange;
31  import org.codehaus.plexus.PlexusContainer;
32  import org.codehaus.plexus.testing.PlexusTest;
33  import org.junit.jupiter.api.BeforeEach;
34  
35  import static org.junit.jupiter.api.Assertions.assertEquals;
36  import static org.junit.jupiter.api.Assertions.assertNotNull;
37  
38  /**
39   * Provides a basis for testing conflict resolvers.
40   *
41   */
42  @PlexusTest
43  @Deprecated
44  public abstract class AbstractConflictResolverTest {
45      // constants --------------------------------------------------------------
46  
47      private static final String GROUP_ID = "test";
48  
49      // fields -----------------------------------------------------------------
50  
51      protected Artifact a1;
52  
53      protected Artifact a2;
54  
55      protected Artifact b1;
56  
57      private final String roleHint;
58  
59      @Inject
60      private ArtifactFactory artifactFactory;
61  
62      private ConflictResolver conflictResolver;
63  
64      @Inject
65      protected PlexusContainer container;
66  
67      // constructors -----------------------------------------------------------
68  
69      public AbstractConflictResolverTest(String roleHint) throws Exception {
70          this.roleHint = roleHint;
71      }
72  
73      // TestCase methods -------------------------------------------------------
74  
75      /*
76       * @see junit.framework.TestCase#setUp()
77       */
78      @BeforeEach
79      public void setUp() throws Exception {
80          conflictResolver = (ConflictResolver) container.lookup(ConflictResolver.ROLE, roleHint);
81  
82          a1 = createArtifact("a", "1.0");
83          a2 = createArtifact("a", "2.0");
84          b1 = createArtifact("b", "1.0");
85      }
86  
87      // protected methods ------------------------------------------------------
88  
89      protected ConflictResolver getConflictResolver() {
90          return conflictResolver;
91      }
92  
93      protected void assertResolveConflict(
94              ResolutionNode expectedNode, ResolutionNode actualNode1, ResolutionNode actualNode2) {
95          ResolutionNode resolvedNode = getConflictResolver().resolveConflict(actualNode1, actualNode2);
96  
97          assertNotNull(resolvedNode, "Expected resolvable");
98          assertEquals(expectedNode, resolvedNode, "Resolution node");
99      }
100 
101     protected Artifact createArtifact(String id, String version) throws InvalidVersionSpecificationException {
102         return createArtifact(id, version, Artifact.SCOPE_COMPILE);
103     }
104 
105     protected Artifact createArtifact(String id, String version, String scope)
106             throws InvalidVersionSpecificationException {
107         return createArtifact(id, version, scope, null, false);
108     }
109 
110     protected Artifact createArtifact(String id, String version, String scope, String inheritedScope, boolean optional)
111             throws InvalidVersionSpecificationException {
112         VersionRange versionRange = VersionRange.createFromVersionSpec(version);
113 
114         return artifactFactory.createDependencyArtifact(
115                 GROUP_ID, id, versionRange, "jar", null, scope, inheritedScope, optional);
116     }
117 
118     protected ResolutionNode createResolutionNode(Artifact Artifact) {
119         return new ResolutionNode(Artifact, Collections.<ArtifactRepository>emptyList());
120     }
121 
122     protected ResolutionNode createResolutionNode(Artifact Artifact, ResolutionNode parent) {
123         return new ResolutionNode(Artifact, Collections.<ArtifactRepository>emptyList(), parent);
124     }
125 }