1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.treeview;
20
21 import java.io.File;
22
23 import org.apache.maven.index.AbstractNexusIndexerTest;
24 import org.apache.maven.index.NexusIndexer;
25 import org.junit.Test;
26
27 import static org.junit.Assert.assertEquals;
28
29 public class IndexTreeViewTest extends AbstractNexusIndexerTest {
30 protected File repo = new File(getBasedir(), "src/test/repo");
31
32 protected IndexTreeView indexTreeView;
33
34 protected boolean debug = false;
35
36 @Override
37 public void setUp() throws Exception {
38 super.setUp();
39
40 indexTreeView = lookup(IndexTreeView.class);
41 }
42
43 @Override
44 protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
45 context = nexusIndexer.addIndexingContext("test-minimal", "test", repo, indexDir, null, null, MIN_CREATORS);
46 nexusIndexer.scan(context);
47 }
48
49 protected int prettyPrint(boolean debug, TreeNode node, int level) throws Exception {
50 if (debug) {
51 System.out.print(node.getPath() + " := " + node.getNodeName() + ", type=" + node.getType());
52 System.out.println();
53 }
54
55 int files = node.isLeaf() ? 1 : 0;
56
57 if (!node.isLeaf()) {
58 for (TreeNode child : node.listChildren()) {
59 files += prettyPrint(debug, child, level + 2);
60 }
61 }
62
63 if (debug && level == 0) {
64 System.out.println(" ===== ");
65 System.out.println(" TOTAL LEAFS: " + files);
66 }
67
68 return files;
69 }
70
71 @Test
72 public void testRoot() throws Exception {
73 TreeViewRequest req = new TreeViewRequest(new DefaultTreeNodeFactory(context.getRepositoryId()), "/", context);
74 TreeNode root = indexTreeView.listNodes(req);
75
76 int leafsFound = prettyPrint(debug, root, 0);
77
78 assertEquals("The group name should be here", "/", root.getNodeName());
79 assertEquals(12, root.getChildren().size());
80 assertEquals(49, leafsFound);
81 }
82
83 @Test
84 public void testPathIsAboveRealGroup() throws Exception {
85 TreeViewRequest req =
86 new TreeViewRequest(new DefaultTreeNodeFactory(context.getRepositoryId()), "/org/", context);
87 TreeNode root = indexTreeView.listNodes(req);
88
89 int leafsFound = prettyPrint(debug, root, 0);
90
91 assertEquals("The group name should be here", "org", root.getNodeName());
92 assertEquals(4, root.getChildren().size());
93 assertEquals(22, leafsFound);
94 }
95
96 @Test
97 public void testPathIsRealGroup() throws Exception {
98 TreeViewRequest req =
99 new TreeViewRequest(new DefaultTreeNodeFactory(context.getRepositoryId()), "/org/slf4j/", context);
100 TreeNode root = indexTreeView.listNodes(req);
101
102 int leafsFound = prettyPrint(debug, root, 0);
103
104 assertEquals("The group name should be here", "slf4j", root.getNodeName());
105 assertEquals(3, root.getChildren().size());
106 assertEquals(10, leafsFound);
107 }
108
109 @Test
110 public void testPathIsRealGroupArtifact() throws Exception {
111 TreeViewRequest req = new TreeViewRequest(
112 new DefaultTreeNodeFactory(context.getRepositoryId()), "/org/slf4j/slf4j-log4j12/", context);
113 TreeNode root = indexTreeView.listNodes(req);
114
115 int leafsFound = prettyPrint(debug, root, 0);
116
117 assertEquals("slf4j-log4j12", root.getNodeName());
118 assertEquals(1, root.getChildren().size());
119 assertEquals(4, leafsFound);
120 }
121
122 @Test
123 public void testPathIsRealGroupArtifactVersion() throws Exception {
124 TreeViewRequest req = new TreeViewRequest(
125 new DefaultTreeNodeFactory(context.getRepositoryId()), "/org/slf4j/slf4j-log4j12/1.4.1/", context);
126 TreeNode root = indexTreeView.listNodes(req);
127
128 int leafsFound = prettyPrint(debug, root, 0);
129
130 assertEquals("The group name should be here", "1.4.1", root.getNodeName());
131 assertEquals(1, root.getChildren().size());
132 assertEquals(4, leafsFound);
133 }
134 }