View Javadoc

1   package org.apache.maven.index;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0    
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.List;
26  
27  import org.apache.lucene.search.Query;
28  import org.apache.maven.index.ArtifactInfo;
29  import org.apache.maven.index.FlatSearchRequest;
30  import org.apache.maven.index.FlatSearchResponse;
31  import org.apache.maven.index.NexusIndexer;
32  
33  public class Nexus2046NexusIndexerTest
34      extends AbstractNexusIndexerTest
35  {
36      protected File repo = new File( getBasedir(), "src/test/nexus-2046" );
37  
38      @Override
39      protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
40          throws Exception
41      {
42          context =
43              nexusIndexer.addIndexingContext( "nexus-2046", "nexus-2046", repo, indexDir, null, null, DEFAULT_CREATORS );
44          nexusIndexer.scan( context );
45      }
46  
47      public void testSearchFlat()
48          throws Exception
49      {
50          // Since 4.0 the original query become illegal
51          // Query q = nexusIndexer.constructQuery( MAVEN.GROUP_ID, "*", SearchType.SCORED );
52          Query q = nexusIndexer.constructQuery( MAVEN.GROUP_ID, "org.maven.ide", SearchType.SCORED );
53          FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
54          Collection<ArtifactInfo> r = response.getResults();
55  
56          assertEquals( 1, r.size() );
57  
58          List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( r );
59  
60          ArtifactInfo ai = null;
61  
62          // g a v p c #1
63          ai = list.get( 0 );
64  
65          assertEquals( "org.maven.ide.eclipse", ai.groupId );
66          assertEquals( "org.maven.ide.eclipse.feature", ai.artifactId );
67          assertEquals( "0.9.7", ai.version );
68          assertEquals( "eclipse-feature", ai.packaging );
69          assertEquals( null, ai.classifier );
70          assertEquals( "nexus-2046", ai.repository );
71          assertEquals( "jar", ai.fextension );
72      }
73  }