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.visitor;
20  
21  import java.io.File;
22  import java.util.List;
23  
24  import org.eclipse.aether.graph.DependencyNode;
25  import org.eclipse.aether.graph.DependencyVisitor;
26  import org.eclipse.aether.internal.test.util.DependencyGraphParser;
27  import org.junit.Test;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.assertTrue;
31  
32  public abstract class AbstractDepthFirstNodeListGeneratorTestSupport {
33  
34      protected DependencyNode parse(String resource) throws Exception {
35          return new DependencyGraphParser("visitor/ordered-list/").parseResource(resource);
36      }
37  
38      protected void assertSequence(List<DependencyNode> actual, String... expected) {
39          assertEquals(actual.toString(), expected.length, actual.size());
40          for (int i = 0; i < expected.length; i++) {
41              DependencyNode node = actual.get(i);
42              assertEquals(
43                      actual.toString(),
44                      expected[i],
45                      node.getDependency().getArtifact().getArtifactId());
46          }
47      }
48  
49      @Test
50      public void testClasspath() throws Exception {
51          DependencyNode root = parse("simple.txt");
52  
53          PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
54          root.accept(visitor);
55  
56          assertEquals(visitor.getClassPath(), "");
57      }
58  
59      @Test
60      public void testFullyResolverClasspath() throws Exception {
61          DependencyNode root = parse("simple.txt");
62  
63          DependencyVisitor fileSetter = new DependencyVisitor() {
64              @Override
65              public boolean visitEnter(DependencyNode node) {
66                  node.setArtifact(
67                          node.getArtifact().setFile(new File(node.getArtifact().getArtifactId())));
68                  return true;
69              }
70  
71              @Override
72              public boolean visitLeave(DependencyNode node) {
73                  return true;
74              }
75          };
76          root.accept(fileSetter);
77  
78          PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
79          root.accept(visitor);
80  
81          String classpath = visitor.getClassPath();
82          assertEquals(5, classpath.split(File.pathSeparator).length);
83          for (File file : visitor.getFiles()) {
84              assertTrue("missing: " + file, classpath.contains(file.getAbsolutePath()));
85          }
86      }
87  }