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  
31  /**
32   * @author Juven Xu http://issues.sonatype.org/browse/NEXUS-687
33   */
34  public class Nexus687NexusIndexerTest extends AbstractNexusIndexerTest {
35      protected File repo = new File(getBasedir(), "src/test/nexus-687");
36  
37      @Override
38      protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
39          context =
40                  nexusIndexer.addIndexingContext("nexus-687", "nexus-687", repo, indexDir, null, null, DEFAULT_CREATORS);
41          nexusIndexer.scan(context);
42      }
43  
44      @Test
45      public void testSearchFlat() throws Exception {
46          Query q = nexusIndexer.constructQuery(MAVEN.GROUP_ID, "xstream", SearchType.SCORED);
47  
48          FlatSearchResponse response = nexusIndexer.searchFlat(new FlatSearchRequest(q));
49  
50          Collection<ArtifactInfo> r = response.getResults();
51  
52          assertEquals(1, r.size());
53  
54          List<ArtifactInfo> list = new ArrayList<>(r);
55  
56          assertEquals(1, list.size());
57  
58          ArtifactInfo ai = list.get(0);
59  
60          assertEquals("xstream", ai.getGroupId());
61  
62          assertEquals("xstream", ai.getArtifactId());
63  
64          assertEquals("1.2.2", ai.getVersion());
65  
66          assertEquals("jar", ai.getPackaging());
67      }
68  }