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 java.util.Collection;
25  import java.util.LinkedList;
26  import java.util.List;
27  import java.util.Queue;
28  
29  import org.eclipse.aether.collection.DependencyGraphTransformer;
30  import org.eclipse.aether.graph.DependencyNode;
31  import org.eclipse.aether.internal.test.util.DependencyGraphParser;
32  import org.eclipse.aether.util.graph.transformer.ConflictIdSorter;
33  import org.eclipse.aether.util.graph.transformer.TransformationContextKeys;
34  import org.junit.Test;
35  
36  /**
37   */
38  public class ConflictIdSorterTest
39      extends AbstractDependencyGraphTransformerTest
40  {
41  
42      @Override
43      protected DependencyGraphTransformer newTransformer()
44      {
45          return new ChainedDependencyGraphTransformer( new SimpleConflictMarker(), new ConflictIdSorter() );
46      }
47  
48      @Override
49      protected DependencyGraphParser newParser()
50      {
51          return new DependencyGraphParser( "transformer/conflict-id-sorter/" );
52      }
53  
54      private void expectOrder( List<String> sorted, String... ids )
55      {
56          Queue<String> queue = new LinkedList<>( sorted );
57  
58          for ( String id : ids )
59          {
60              String item = queue.poll();
61              assertNotNull( String.format( "not enough conflict groups (no match for '%s'", id ), item );
62  
63              if ( !"*".equals( id ) )
64              {
65                  assertEquals( id, item );
66              }
67          }
68  
69          assertTrue( String.format( "leftover conflict groups (remaining: '%s')", queue ), queue.isEmpty() );
70      }
71  
72      private void expectOrder( String... id )
73      {
74          @SuppressWarnings( "unchecked" )
75          List<String> sorted = (List<String>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS );
76          expectOrder( sorted, id );
77      }
78  
79      private void expectCycle( boolean cycle )
80      {
81          Collection<?> cycles = (Collection<?>) context.get( TransformationContextKeys.CYCLIC_CONFLICT_IDS );
82          assertEquals( cycle, !cycles.isEmpty() );
83      }
84  
85      @Test
86      public void testSimple()
87          throws Exception
88      {
89          DependencyNode node = parseResource( "simple.txt" );
90          assertSame( node, transform( node ) );
91  
92          expectOrder( "gid2:aid::jar", "gid:aid::jar", "gid:aid2::jar" );
93          expectCycle( false );
94      }
95  
96      @Test
97      public void testCycle()
98          throws Exception
99      {
100         DependencyNode node = parseResource( "cycle.txt" );
101         assertSame( node, transform( node ) );
102 
103         expectOrder( "gid:aid::jar", "gid2:aid::jar" );
104         expectCycle( true );
105     }
106 
107     @Test
108     public void testCycles()
109         throws Exception
110     {
111         DependencyNode node = parseResource( "cycles.txt" );
112         assertSame( node, transform( node ) );
113 
114         expectOrder( "*", "*", "*", "gid:aid::jar" );
115         expectCycle( true );
116     }
117 
118     @Test
119     public void testNoConflicts()
120         throws Exception
121     {
122         DependencyNode node = parseResource( "no-conflicts.txt" );
123         assertSame( node, transform( node ) );
124 
125         expectOrder( "gid:aid::jar", "gid3:aid::jar", "gid2:aid::jar", "gid4:aid::jar" );
126         expectCycle( false );
127     }
128 
129 }