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.eclipse.aether.util.graph.transformer;
20  
21  import org.eclipse.aether.collection.DependencyGraphTransformer;
22  import org.eclipse.aether.graph.DependencyNode;
23  import org.eclipse.aether.internal.test.util.DependencyGraphParser;
24  import org.junit.Test;
25  
26  import static org.junit.Assert.*;
27  
28  /**
29   */
30  public class JavaDependencyContextRefinerTest extends AbstractDependencyGraphTransformerTest {
31  
32      @Override
33      protected DependencyGraphTransformer newTransformer() {
34          return new JavaDependencyContextRefiner();
35      }
36  
37      @Override
38      protected DependencyGraphParser newParser() {
39          return new DependencyGraphParser("transformer/context-refiner/");
40      }
41  
42      @Test
43      public void testDoNotRefineOtherContext() throws Exception {
44          DependencyNode node = parseLiteral("gid:aid:cls:ver");
45          node.setRequestContext("otherContext");
46  
47          DependencyNode refinedNode = transform(node);
48          assertEquals(node, refinedNode);
49      }
50  
51      @Test
52      public void testRefineToCompile() throws Exception {
53          String expected = "project/compile";
54  
55          DependencyNode node = parseLiteral("gid:aid:ver compile");
56          node.setRequestContext("project");
57          DependencyNode refinedNode = transform(node);
58          assertEquals(expected, refinedNode.getRequestContext());
59  
60          node = parseLiteral("gid:aid:ver system");
61          node.setRequestContext("project");
62          refinedNode = transform(node);
63          assertEquals(expected, refinedNode.getRequestContext());
64  
65          node = parseLiteral("gid:aid:ver provided");
66          node.setRequestContext("project");
67          refinedNode = transform(node);
68          assertEquals(expected, refinedNode.getRequestContext());
69      }
70  
71      @Test
72      public void testRefineToTest() throws Exception {
73          String expected = "project/test";
74  
75          DependencyNode node = parseLiteral("gid:aid:ver test");
76          node.setRequestContext("project");
77          DependencyNode refinedNode = transform(node);
78          assertEquals(expected, refinedNode.getRequestContext());
79      }
80  
81      @Test
82      public void testRefineToRuntime() throws Exception {
83          String expected = "project/runtime";
84  
85          DependencyNode node = parseLiteral("gid:aid:ver runtime");
86          node.setRequestContext("project");
87          DependencyNode refinedNode = transform(node);
88          assertEquals(expected, refinedNode.getRequestContext());
89      }
90  
91      @Test
92      public void testDoNotRefineUnknownScopes() throws Exception {
93          String expected = "project";
94  
95          DependencyNode node = parseLiteral("gid:aid:ver unknownScope");
96          node.setRequestContext("project");
97          DependencyNode refinedNode = transform(node);
98          assertEquals(expected, refinedNode.getRequestContext());
99      }
100 }