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.ArrayList;
23  import java.util.Collection;
24  import java.util.List;
25  
26  import org.apache.lucene.search.Query;
27  import org.junit.Test;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.assertNull;
31  
32  public class Nexus1179NexusIndexerTest extends AbstractNexusIndexerTest {
33      protected File repo = new File(getBasedir(), "src/test/nexus-1179");
34  
35      @Override
36      protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
37          context = nexusIndexer.addIndexingContext(
38                  "nexus-1179", "nexus-1179", repo, indexDir, null, null, DEFAULT_CREATORS);
39          nexusIndexer.scan(context);
40      }
41  
42      @Test
43      public void testSearchFlat() throws Exception {
44          // Since 4.0 this query become illegal
45          // This test only performs search and expects to have all the "problematic" ones found too, to prove
46          // they are indexed
47          // Query q = nexusIndexer.constructQuery( MAVEN.GROUP_ID, "*", SearchType.SCORED );
48          // So, we found the "common denominator" and thats version
49          Query q = nexusIndexer.constructQuery(MAVEN.VERSION, "1", SearchType.SCORED);
50          FlatSearchResponse response = nexusIndexer.searchFlat(new FlatSearchRequest(q));
51          Collection<ArtifactInfo> r = response.getResults();
52  
53          assertEquals(4, r.size());
54  
55          List<ArtifactInfo> list = new ArrayList<>(r);
56  
57          ArtifactInfo ai;
58  
59          // g a v p c #1
60          ai = list.get(0);
61  
62          assertEquals("ant", ai.getGroupId());
63          assertEquals("ant", ai.getArtifactId());
64          assertEquals("1.6.5", ai.getVersion());
65          assertNull(ai.getPackaging()); // coz no POM present
66          assertNull(ai.getClassifier());
67          assertEquals("nexus-1179", ai.getRepository());
68          assertEquals("jar", ai.getFileExtension());
69  
70          // g a v p c #2
71          ai = list.get(1);
72  
73          assertEquals("ant", ai.getGroupId());
74          assertEquals("ant", ai.getArtifactId());
75          assertEquals("1.5.1", ai.getVersion());
76          assertEquals("jar", ai.getPackaging()); // coz POM is present and says so
77          assertNull(ai.getClassifier());
78          assertEquals("nexus-1179", ai.getRepository());
79          assertEquals("pom", ai.getFileExtension());
80  
81          // g a v p c #3
82          ai = list.get(2);
83  
84          assertEquals("asm", ai.getGroupId());
85          assertEquals("asm-commons", ai.getArtifactId());
86          assertEquals("3.1", ai.getVersion());
87          assertEquals("jar", ai.getPackaging());
88          assertNull(ai.getClassifier());
89          assertEquals("nexus-1179", ai.getRepository());
90          assertEquals("pom", ai.getFileExtension());
91  
92          // g a v p c #4
93          ai = list.get(3);
94  
95          assertEquals("org", ai.getGroupId());
96          assertEquals("test", ai.getArtifactId());
97          assertEquals("1.0", ai.getVersion());
98          assertEquals("jar", ai.getPackaging()); // coz POM is present and says so
99          assertNull(ai.getClassifier());
100         assertEquals("nexus-1179", ai.getRepository());
101         assertEquals("pom", ai.getFileExtension());
102     }
103 }