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.apache.maven.index;
20  
21  import java.io.File;
22  import java.util.Collection;
23  import java.util.Set;
24  
25  import org.junit.Test;
26  
27  import static org.junit.Assert.assertEquals;
28  import static org.junit.Assert.assertTrue;
29  
30  public class SubPathReindexTest extends AbstractNexusIndexerTest {
31      protected File repo = new File(getBasedir(), "src/test/repo");
32  
33      @Override
34      protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
35          context = nexusIndexer.addIndexingContext("test-minimal", "test", repo, indexDir, null, null, MIN_CREATORS);
36  
37          nexusIndexer.scan(context, "/org/slf4j/slf4j-api", null, false);
38      }
39  
40      @Test
41      public void testRootGroups() throws Exception {
42          Set<String> rootGroups = context.getRootGroups();
43          assertEquals(rootGroups.toString(), 1, rootGroups.size());
44  
45          assertGroup(0, "com.adobe", context);
46          assertGroup(0, "com.adobe.flexunit", context);
47  
48          assertGroup(0, "qdox", context);
49  
50          assertGroup(0, "proptest", context);
51  
52          assertGroup(0, "junit", context);
53  
54          assertGroup(0, "commons-logging", context);
55  
56          assertGroup(0, "regexp", context);
57  
58          assertGroup(0, "commons-cli", context);
59  
60          assertGroup(4, "org", context);
61  
62          assertGroup(4, "org.slf4j", context);
63  
64          assertGroup(0, "org.testng", context);
65  
66          assertGroup(0, "org.apache", context);
67  
68          assertGroup(0, "org.apache.directory", context);
69          assertGroup(0, "org.apache.directory.server", context);
70  
71          assertGroup(0, "org.apache.maven", context);
72          assertGroup(0, "org.apache.maven.plugins", context);
73          assertGroup(0, "org.apache.maven.plugins.maven-core-it-plugin", context);
74      }
75  
76      @Test
77      public void testIdentify() throws Exception {
78          Collection<ArtifactInfo> ais;
79          File artifact;
80  
81          // Using a file: this one should be unknown
82          artifact = new File(repo, "qdox/qdox/1.5/qdox-1.5.jar");
83  
84          ais = nexusIndexer.identify(artifact);
85  
86          assertTrue("Should not be able to identify it!", ais.isEmpty());
87  
88          // Using a file: this one should be known
89          artifact = new File(repo, "org/slf4j/slf4j-api/1.4.2/slf4j-api-1.4.2.jar");
90  
91          ais = nexusIndexer.identify(artifact);
92  
93          assertEquals("Should not be able to identify it!", 1, ais.size());
94      }
95  }