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