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 java.util.Map;
22  
23  import org.eclipse.aether.collection.DependencyGraphTransformer;
24  import org.eclipse.aether.graph.DependencyNode;
25  import org.eclipse.aether.internal.test.util.DependencyGraphParser;
26  import org.junit.Test;
27  
28  import static org.junit.Assert.*;
29  
30  /**
31   */
32  public class ConflictMarkerTest extends AbstractDependencyGraphTransformerTest {
33  
34      @Override
35      protected DependencyGraphTransformer newTransformer() {
36          return new ConflictMarker();
37      }
38  
39      @Override
40      protected DependencyGraphParser newParser() {
41          return new DependencyGraphParser("transformer/conflict-marker/");
42      }
43  
44      @Test
45      public void testSimple() throws Exception {
46          DependencyNode root = parseResource("simple.txt");
47  
48          assertSame(root, transform(root));
49  
50          Map<?, ?> ids = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
51          assertNotNull(ids);
52  
53          assertNull(ids.get(root));
54          assertNotNull(ids.get(root.getChildren().get(0)));
55          assertNotNull(ids.get(root.getChildren().get(1)));
56          assertNotSame(
57                  ids.get(root.getChildren().get(0)), ids.get(root.getChildren().get(1)));
58          assertNotEquals(
59                  ids.get(root.getChildren().get(0)), ids.get(root.getChildren().get(1)));
60      }
61  
62      @Test
63      public void testRelocation1() throws Exception {
64          DependencyNode root = parseResource("relocation1.txt");
65  
66          assertSame(root, transform(root));
67  
68          Map<?, ?> ids = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
69          assertNotNull(ids);
70  
71          assertNull(ids.get(root));
72          assertNotNull(ids.get(root.getChildren().get(0)));
73          assertNotNull(ids.get(root.getChildren().get(1)));
74          assertSame(
75                  ids.get(root.getChildren().get(0)), ids.get(root.getChildren().get(1)));
76      }
77  
78      @Test
79      public void testRelocation2() throws Exception {
80          DependencyNode root = parseResource("relocation2.txt");
81  
82          assertSame(root, transform(root));
83  
84          Map<?, ?> ids = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
85          assertNotNull(ids);
86  
87          assertNull(ids.get(root));
88          assertNotNull(ids.get(root.getChildren().get(0)));
89          assertNotNull(ids.get(root.getChildren().get(1)));
90          assertSame(
91                  ids.get(root.getChildren().get(0)), ids.get(root.getChildren().get(1)));
92      }
93  
94      @Test
95      public void testRelocation3() throws Exception {
96          DependencyNode root = parseResource("relocation3.txt");
97  
98          assertSame(root, transform(root));
99  
100         Map<?, ?> ids = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
101         assertNotNull(ids);
102 
103         assertNull(ids.get(root));
104         assertNotNull(ids.get(root.getChildren().get(0)));
105         assertNotNull(ids.get(root.getChildren().get(1)));
106         assertNotNull(ids.get(root.getChildren().get(2)));
107         assertSame(
108                 ids.get(root.getChildren().get(0)), ids.get(root.getChildren().get(1)));
109         assertSame(
110                 ids.get(root.getChildren().get(1)), ids.get(root.getChildren().get(2)));
111     }
112 }