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 Nexus2046NexusIndexerTest extends AbstractNexusIndexerTest {
33      protected File repo = new File(getBasedir(), "src/test/nexus-2046");
34  
35      @Override
36      protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
37          context = nexusIndexer.addIndexingContext(
38                  "nexus-2046", "nexus-2046", repo, indexDir, null, null, DEFAULT_CREATORS);
39          nexusIndexer.scan(context);
40      }
41  
42      @Test
43      public void testSearchFlat() throws Exception {
44          // Since 4.0 the original query become illegal
45          // Query q = nexusIndexer.constructQuery( MAVEN.GROUP_ID, "*", SearchType.SCORED );
46          Query q = nexusIndexer.constructQuery(MAVEN.GROUP_ID, "org.maven.ide", SearchType.SCORED);
47          FlatSearchResponse response = nexusIndexer.searchFlat(new FlatSearchRequest(q));
48          Collection<ArtifactInfo> r = response.getResults();
49  
50          assertEquals(1, r.size());
51  
52          List<ArtifactInfo> list = new ArrayList<>(r);
53  
54          ArtifactInfo ai;
55  
56          // g a v p c #1
57          ai = list.get(0);
58  
59          assertEquals("org.maven.ide.eclipse", ai.getGroupId());
60          assertEquals("org.maven.ide.eclipse.feature", ai.getArtifactId());
61          assertEquals("0.9.7", ai.getVersion());
62          assertEquals("eclipse-feature", ai.getPackaging());
63          assertNull(ai.getClassifier());
64          assertEquals("nexus-2046", ai.getRepository());
65          assertEquals("jar", ai.getFileExtension());
66      }
67  }