]> source.dussan.org Git - archiva.git/blob
b79a116e798313d5e61b53d7f0eeaa3fa8168fab
[archiva.git] /
1 package org.apache.archiva.indexer.search;
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.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.apache.commons.io.FileUtils;
28 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
29 import org.apache.maven.archiva.configuration.Configuration;
30 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
32 import org.easymock.MockControl;
33 import org.sonatype.nexus.index.ArtifactContext;
34 import org.sonatype.nexus.index.ArtifactContextProducer;
35 import org.sonatype.nexus.index.NexusIndexer;
36 import org.sonatype.nexus.index.context.DefaultIndexingContext;
37 import org.sonatype.nexus.index.context.IndexingContext;
38 import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
39 import org.sonatype.nexus.index.IndexerEngine;
40
41 public class NexusRepositorySearchTest
42     extends PlexusInSpringTestCase
43 {
44     private RepositorySearch search;
45
46     private ArchivaConfiguration archivaConfig;
47
48     private NexusIndexer indexer;
49
50     private IndexingContext context;
51
52     private IndexerEngine indexerEngine;
53
54     private ArtifactContextProducer artifactContextProducer;
55
56     private MockControl archivaConfigControl;
57
58     private Configuration config;
59
60     private final static String TEST_REPO_1 = "nexus-search-test-repo";
61
62     private final static String TEST_REPO_2 = "nexus-search-test-repo-2";
63
64     @Override
65     protected void setUp()
66         throws Exception
67     {
68         super.setUp();
69
70         indexer = (NexusIndexer) lookup( NexusIndexer.class );
71
72         archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
73
74         archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
75
76         search = new NexusRepositorySearch( indexer, archivaConfig );
77
78         indexerEngine = (IndexerEngine) lookup( IndexerEngine.class );
79
80         artifactContextProducer = (ArtifactContextProducer) lookup( ArtifactContextProducer.class );
81
82         config = new Configuration();
83         config.addManagedRepository( createRepositoryConfig( TEST_REPO_1 ) );
84         config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
85     }
86
87     private void createIndexForQuickSearch()
88         throws IOException, UnsupportedExistingLuceneIndexException
89     {
90         List<File> files = new ArrayList<File>();
91         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
92             "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
93         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
94             "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
95         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
96             "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
97
98         createIndex( TEST_REPO_1, files );
99     }
100
101     private ManagedRepositoryConfiguration createRepositoryConfig( String repository )
102     {
103         ManagedRepositoryConfiguration repositoryConfig = new ManagedRepositoryConfiguration();
104         repositoryConfig.setId( repository );
105         repositoryConfig.setLocation( getBasedir() + "/target/test-classes/" + repository );
106         repositoryConfig.setLayout( "default" );
107         repositoryConfig.setName( repository );
108         repositoryConfig.setScanned( true );
109         repositoryConfig.setSnapshots( false );
110         repositoryConfig.setReleases( true );
111
112         return repositoryConfig;
113     }
114
115     @Override
116     protected void tearDown()
117         throws Exception
118     {
119         FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ) );
120         assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 + "/.indexer" ).exists() );
121         
122         FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ) );
123         assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer" ).exists() );
124
125         super.tearDown();
126     }
127
128     private void createIndex( String repository, List<File> filesToBeIndexed )
129         throws IOException, UnsupportedExistingLuceneIndexException
130     {
131         context = new DefaultIndexingContext( repository, repository, new File( getBasedir(), "/target/test-classes/" +
132                     repository ), new File( getBasedir(), "/target/test-classes/" + repository + "/.indexer" ), null, null,
133                     NexusIndexer.FULL_INDEX, false );
134             //indexer.addIndexingContext( repository, repository, new File( getBasedir(), "/target/test-classes/" +
135             //    repository ), new File( getBasedir(), "/target/test-classes/" + repository + "/.indexer" ), null, null,
136             //                            NexusIndexer.FULL_INDEX );
137         context.setSearchable( true );
138
139         //indexerEngine.beginIndexing( context );
140
141         for ( File artifactFile : filesToBeIndexed )
142         {
143             ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
144             indexerEngine.index( context, ac );
145         }
146
147         context.close( false );
148         //indexerEngine.endIndexing( context );
149         //indexer.removeIndexingContext( context, false );
150         
151         assertTrue( new File( getBasedir(), "/target/test-classes/" + repository + "/.indexer" ).exists() );
152     }
153
154     public void testQuickSearch()
155         throws Exception
156     {   
157         createIndexForQuickSearch();
158         
159         List<String> selectedRepos = new ArrayList<String>();
160         selectedRepos.add( TEST_REPO_1 );
161
162         // search artifactId
163         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
164
165         archivaConfigControl.replay();
166
167         SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
168
169         archivaConfigControl.verify();
170
171         assertNotNull( results );
172         assertEquals( 1, results.getTotalHits() );
173
174         SearchResultHit hit = results.getHits().get( 0 );
175         assertEquals( "org.apache.archiva", hit.getGroupId() );
176         assertEquals( "archiva-search", hit.getArtifactId() );
177         assertEquals( "1.0", hit.getVersions().get( 0 ) );
178         
179         archivaConfigControl.reset();
180
181         // search groupId
182         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
183
184         archivaConfigControl.replay();
185
186         results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
187
188         archivaConfigControl.verify();
189
190         assertNotNull( results );
191         assertEquals( 2, results.getTotalHits() );
192
193         //TODO: search for class & package names
194     }
195     
196     public void testQuickSearchWithPagination()
197         throws Exception
198     {   
199         createIndexForQuickSearch();
200         
201         List<String> selectedRepos = new ArrayList<String>();
202         selectedRepos.add( TEST_REPO_1 );
203
204         // page 1
205         SearchResultLimits limits = new SearchResultLimits( 0 );
206         limits.setPageSize( 1 );
207
208         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
209
210         archivaConfigControl.replay();
211
212         SearchResults results = search.search( "user", selectedRepos, "org", limits, new ArrayList<String>() );
213
214         archivaConfigControl.verify();
215
216         assertNotNull( results );
217         assertEquals( 1, results.getHits().size() );
218         assertEquals( 2, results.getTotalHits() );
219         assertEquals( limits, results.getLimits() );
220
221         archivaConfigControl.reset();
222
223         // page 2
224         limits = new SearchResultLimits( 1 );
225         limits.setPageSize( 1 );
226
227         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
228
229         archivaConfigControl.replay();
230
231         results = search.search( "user", selectedRepos, "org", limits, null );
232
233         archivaConfigControl.verify();
234
235         assertNotNull( results );
236         assertEquals( 1, results.getHits().size() );
237         assertEquals( 2, results.getTotalHits() );
238         assertEquals( limits, results.getLimits() );
239     }
240
241     public void testArtifactFoundInMultipleRepositories()
242         throws Exception
243     {
244         createIndexForQuickSearch();
245         
246         List<File> files = new ArrayList<File>();
247         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 +
248             "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
249         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 +
250             "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
251         createIndex( TEST_REPO_2, files );
252
253         List<String> selectedRepos = new ArrayList<String>();
254         selectedRepos.add( TEST_REPO_1 );
255         selectedRepos.add( TEST_REPO_2 );
256
257         config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
258
259         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
260
261         archivaConfigControl.replay();
262
263         SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
264
265         archivaConfigControl.verify();
266
267         assertNotNull( results );
268         assertEquals( 1, results.getTotalHits() );
269
270         SearchResultHit hit = results.getHits().get( 0 );
271         assertEquals( "org.apache.archiva", hit.getGroupId() );
272         assertEquals( "archiva-search", hit.getArtifactId() );
273         assertEquals( 2, hit.getVersions().size() );
274         assertTrue( hit.getVersions().contains( "1.0" ) );
275         assertTrue( hit.getVersions().contains( "1.1" ) );
276
277         archivaConfigControl.reset();
278
279         // TODO: [BROWSE] in artifact info from browse, display all the repositories where the artifact is found
280     }
281
282     public void testNoMatchFound()
283         throws Exception
284     {
285         createIndexForQuickSearch();
286         
287         List<String> selectedRepos = new ArrayList<String>();
288         selectedRepos.add( TEST_REPO_1 );
289         
290         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
291
292         archivaConfigControl.replay();
293
294         SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null, null );
295
296         archivaConfigControl.verify();
297
298         assertNotNull( results );
299         assertEquals( 0, results.getTotalHits() );
300     }
301
302     public void testNoIndexFound()
303         throws Exception
304     {
305         List<String> selectedRepos = new ArrayList<String>();
306         selectedRepos.add( TEST_REPO_1 );
307         
308         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
309
310         archivaConfigControl.replay();
311
312         SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
313         assertNotNull( results );
314         assertEquals( 0, results.getTotalHits() );
315         
316         archivaConfigControl.verify();            
317     }
318
319     public void testRepositoryNotFound()
320         throws Exception
321     {
322         List<String> selectedRepos = new ArrayList<String>();
323         selectedRepos.add( "non-existing-repo" );
324         
325         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
326
327         archivaConfigControl.replay();
328
329         SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
330         assertNotNull( results );
331         assertEquals( 0, results.getTotalHits() );
332         
333         archivaConfigControl.verify();          
334     }
335     
336     public void testSearchWithinSearchResults()
337         throws Exception
338     {
339         createIndexForQuickSearch();
340         
341         List<String> selectedRepos = new ArrayList<String>();
342         selectedRepos.add( TEST_REPO_1 );
343         
344         List<String> previousSearchTerms = new ArrayList<String>();
345         previousSearchTerms.add( "archiva-test" );
346         
347         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
348
349         archivaConfigControl.replay();
350
351         SearchResults results = search.search( "user", selectedRepos, "1.0", null, previousSearchTerms );
352
353         archivaConfigControl.verify();
354
355         assertNotNull( results );
356         assertEquals( 1, results.getTotalHits() );
357         
358         SearchResultHit hit = results.getHits().get( 0 );
359         assertEquals( "org.apache.archiva", hit.getGroupId() );
360         assertEquals( "archiva-test", hit.getArtifactId() );
361         assertEquals( 1, hit.getVersions().size() );
362         assertEquals( "1.0", hit.getVersions().get( 0 ) );
363     }
364     
365     // tests for advanced search
366     
367     public void testAdvancedSearch()
368         throws Exception
369     {
370         List<File> files = new ArrayList<File>();
371         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 +
372             "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
373         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 +
374             "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
375         createIndex( TEST_REPO_2, files );
376
377         List<String> selectedRepos = new ArrayList<String>();        
378         selectedRepos.add( TEST_REPO_2 );
379         
380         SearchFields searchFields = new SearchFields();
381         searchFields.setGroupId( "org.apache.archiva" );
382         searchFields.setVersion( "1.0" );
383         searchFields.setRepositories( selectedRepos );        
384         
385         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
386
387         archivaConfigControl.replay();
388
389         SearchResults results = search.search( "user", searchFields, null );
390
391         archivaConfigControl.verify();
392
393         assertNotNull( results );
394         assertEquals( 1, results.getTotalHits() );
395         
396         SearchResultHit hit = results.getHits().get( 0 );
397         assertEquals( "org.apache.archiva", hit.getGroupId() );
398         assertEquals( "archiva-search", hit.getArtifactId() );
399         assertEquals( "1.0", hit.getVersions().get( 0 ) );       
400     }
401     
402     public void testAdvancedSearchWithPagination()
403         throws Exception
404     {
405         List<File> files = new ArrayList<File>();
406         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
407             "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
408         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
409             "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
410         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
411             "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
412         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
413             "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
414         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
415             "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
416         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
417             "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
418         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
419             "/com/classname-search/1.0/classname-search-1.0.jar" ) );
420         
421         createIndex( TEST_REPO_1, files );
422
423         List<String> selectedRepos = new ArrayList<String>();
424         selectedRepos.add( TEST_REPO_1 );
425         
426         SearchFields searchFields = new SearchFields();
427         searchFields.setGroupId( "org.apache.archiva" );
428         searchFields.setRepositories( selectedRepos );        
429         
430         // page 1
431         
432         SearchResultLimits limits = new SearchResultLimits( 0 );
433         limits.setPageSize( 1 );
434         
435         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
436
437         archivaConfigControl.replay();
438
439         SearchResults results = search.search( "user", searchFields, limits );
440
441         archivaConfigControl.verify();
442
443         assertNotNull( results );
444         assertEquals( 3, results.getTotalHits() );
445         assertEquals( 1, results.getHits().size() );
446         
447         // page 2
448         archivaConfigControl.reset();
449         
450         limits = new SearchResultLimits( 1 );
451         limits.setPageSize( 1 );
452         
453         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
454
455         archivaConfigControl.replay();
456
457         results = search.search( "user", searchFields, limits );
458
459         archivaConfigControl.verify();
460
461         assertNotNull( results );
462         assertEquals( 3, results.getTotalHits() );
463         assertEquals( 1, results.getHits().size() );        
464     }
465     
466     // MRM-981 - artifactIds with numeric characters aren't found in advanced search
467     public void testAdvancedSearchArtifactIdHasNumericChar()
468         throws Exception
469     {
470         List<File> files = new ArrayList<File>();
471         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
472             "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
473         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
474             "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
475         createIndex( TEST_REPO_1, files );
476
477         List<String> selectedRepos = new ArrayList<String>();
478         selectedRepos.add( TEST_REPO_1 );
479         
480         SearchFields searchFields = new SearchFields();
481         searchFields.setArtifactId( "artifactid-numeric" );
482         searchFields.setRepositories( selectedRepos );        
483         
484         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1 );
485
486         archivaConfigControl.replay();
487
488         SearchResults results = search.search( "user", searchFields, null );
489
490         archivaConfigControl.verify();
491
492         assertNotNull( results );
493         assertEquals( 2, results.getTotalHits() );               
494     }
495     
496     public void testAdvancedSearchNoRepositoriesConfigured()
497         throws Exception
498     {
499         SearchFields searchFields = new SearchFields();
500         searchFields.setArtifactId( "archiva" );
501         searchFields.setRepositories( null );        
502
503         try
504         {
505             search.search( "user", searchFields, null );
506             fail( "A RepositorySearchExcecption should have been thrown." );
507         }
508         catch( RepositorySearchException e )
509         {
510             assertEquals( "Repositories cannot be null.", e.getMessage() );
511         }
512     }
513     
514     public void testAdvancedSearchSearchFieldsAreNull()
515         throws Exception
516     {
517         List<String> selectedRepos = new ArrayList<String>();
518         selectedRepos.add( TEST_REPO_1 );
519         
520         SearchFields searchFields = new SearchFields();
521         searchFields.setRepositories( selectedRepos );        
522
523         try
524         {
525             archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1 );
526
527             archivaConfigControl.replay();
528
529             search.search( "user", searchFields, null );
530             
531             archivaConfigControl.verify();
532             
533             fail( "A RepositorySearchExcecption should have been thrown." );
534         }
535         catch( RepositorySearchException e )
536         {
537             assertEquals( "No search fields set.", e.getMessage() );
538         }
539     }
540     
541     public void testAdvancedSearchSearchFieldsAreBlank()
542         throws Exception
543     {
544         List<String> selectedRepos = new ArrayList<String>();
545         selectedRepos.add( TEST_REPO_1 );
546         
547         SearchFields searchFields = new SearchFields();
548         searchFields.setGroupId( "" );
549         searchFields.setArtifactId( "" );
550         searchFields.setVersion( "" );
551         searchFields.setPackaging( "" );
552         searchFields.setClassName( "" );
553         
554         searchFields.setRepositories( selectedRepos );        
555     
556         try
557         {
558             archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1 );
559     
560             archivaConfigControl.replay();
561     
562             search.search( "user", searchFields, null );
563             
564             archivaConfigControl.verify();
565             
566             fail( "A RepositorySearchExcecption should have been thrown." );
567         }
568         catch( RepositorySearchException e )
569         {
570             assertEquals( "No search fields set.", e.getMessage() );
571         }
572     }
573     
574     public void testAdvancedSearchJarArtifacts()
575         throws Exception
576     {
577         List<File> files = new ArrayList<File>();
578         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
579             "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
580         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
581             "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
582         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
583             "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
584         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
585         "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
586         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
587             "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
588         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
589             "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
590         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
591             "/com/classname-search/1.0/classname-search-1.0.jar" ) );
592         
593         createIndex( TEST_REPO_1, files );
594     
595         List<String> selectedRepos = new ArrayList<String>();
596         selectedRepos.add( TEST_REPO_1 );
597         
598         SearchFields searchFields = new SearchFields();
599         searchFields.setPackaging( "jar" );
600         searchFields.setRepositories( selectedRepos );        
601         
602         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
603     
604         archivaConfigControl.replay();
605     
606         SearchResults results = search.search( "user", searchFields, null );
607     
608         archivaConfigControl.verify();
609     
610         assertNotNull( results );
611         assertEquals( 5, results.getTotalHits() );        
612     }
613     
614     public void testAdvancedSearchClassname()
615         throws Exception
616     {
617         List<File> files = new ArrayList<File>();
618         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
619             "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
620         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
621             "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
622         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
623             "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
624         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
625         "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
626         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
627             "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
628         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
629             "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
630         files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
631             "/com/classname-search/1.0/classname-search-1.0.jar" ) );
632         
633         createIndex( TEST_REPO_1, files );
634     
635         List<String> selectedRepos = new ArrayList<String>();
636         selectedRepos.add( TEST_REPO_1 );
637         
638         SearchFields searchFields = new SearchFields();
639         searchFields.setClassName( "com.classname.search.App" );
640         searchFields.setRepositories( selectedRepos );        
641         
642         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
643     
644         archivaConfigControl.replay();
645     
646         SearchResults results = search.search( "user", searchFields, null );
647     
648         archivaConfigControl.verify();
649     
650         assertNotNull( results );
651         assertEquals( 1, results.getTotalHits() );
652         
653         SearchResultHit hit = results.getHits().get( 0 );
654         assertEquals( "com", hit.getGroupId() );
655         assertEquals( "classname-search", hit.getArtifactId() );
656         assertEquals( "1.0", hit.getVersions().get( 0 ) );
657     }
658     
659     public void testAdvancedSearchNoIndexFound()
660         throws Exception
661     {
662         List<String> selectedRepos = new ArrayList<String>();
663         selectedRepos.add( TEST_REPO_1 );
664         
665         SearchFields searchFields = new SearchFields();
666         searchFields.setGroupId( "org.apache.archiva" );
667         searchFields.setRepositories( selectedRepos );        
668         
669         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
670     
671         archivaConfigControl.replay();
672     
673         SearchResults results = search.search( "user", searchFields, null );
674     
675         archivaConfigControl.verify();
676     
677         assertNotNull( results );assertEquals( 0, results.getTotalHits() );                
678     }
679 }