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 Nexus1179NexusIndexerTest
34      extends AbstractNexusIndexerTest
35  {
36      protected File repo = new File( getBasedir(), "src/test/nexus-1179" );
37  
38      @Override
39      protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
40          throws Exception
41      {
42          context =
43              nexusIndexer.addIndexingContext( "nexus-1179", "nexus-1179", repo, indexDir, null, null, DEFAULT_CREATORS );
44          nexusIndexer.scan( context );
45      }
46  
47      public void testSearchFlat()
48          throws Exception
49      {
50          // Since 4.0 this query become illegal
51          // This test only performs search and expects to have all the "problematic" ones found too, to prove
52          // they are indexed
53          // Query q = nexusIndexer.constructQuery( MAVEN.GROUP_ID, "*", SearchType.SCORED );
54          // So, we found the "common denominator" and thats version
55          Query q = nexusIndexer.constructQuery( MAVEN.VERSION, "1", SearchType.SCORED );
56          FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
57          Collection<ArtifactInfo> r = response.getResults();
58  
59          assertEquals( 4, r.size() );
60  
61          List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( r );
62  
63          ArtifactInfo ai = null;
64  
65          // g a v p c #1
66          ai = list.get( 0 );
67  
68          assertEquals( "ant", ai.groupId );
69          assertEquals( "ant", ai.artifactId );
70          assertEquals( "1.6.5", ai.version );
71          assertEquals( "jar", ai.packaging );
72          assertEquals( null, ai.classifier );
73          assertEquals( "nexus-1179", ai.repository );
74          assertEquals( "jar", ai.fextension );
75  
76          // g a v p c #2
77          ai = list.get( 1 );
78  
79          assertEquals( "ant", ai.groupId );
80          assertEquals( "ant", ai.artifactId );
81          assertEquals( "1.5.1", ai.version );
82          assertEquals( null, ai.packaging );
83          assertEquals( null, ai.classifier );
84          assertEquals( "nexus-1179", ai.repository );
85          assertEquals( "pom", ai.fextension );
86  
87          // g a v p c #3
88          ai = list.get( 2 );
89  
90          assertEquals( "asm", ai.groupId );
91          assertEquals( "asm-commons", ai.artifactId );
92          assertEquals( "3.1", ai.version );
93          assertEquals( "jar", ai.packaging );
94          assertEquals( null, ai.classifier );
95          assertEquals( "nexus-1179", ai.repository );
96          assertEquals( "pom", ai.fextension );
97  
98          // g a v p c #4
99          ai = list.get( 3 );
100 
101         assertEquals( "org", ai.groupId );
102         assertEquals( "test", ai.artifactId );
103         assertEquals( "1.0", ai.version );
104         assertEquals( null, ai.packaging );
105         assertEquals( null, ai.classifier );
106         assertEquals( "nexus-1179", ai.repository );
107         assertEquals( "pom", ai.fextension );
108     }
109 }