1 package org.apache.archiva.indexer.search;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.archiva.common.utils.FileUtil;
23 import org.apache.archiva.indexer.util.SearchUtil;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.springframework.test.context.ContextConfiguration;
27 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collection;
33 import java.util.List;
36 @RunWith( SpringJUnit4ClassRunner.class )
37 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
38 public class NexusRepositorySearchTest
39 extends AbstractNexusRepositorySearch
43 private void createSimpleIndex( boolean scan )
46 List<File> files = new ArrayList<File>();
47 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
48 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
49 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
50 + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
51 files.add( new File( FileUtil.getBasedir(), "/src/test/" + TEST_REPO_1
52 + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
54 createIndex( TEST_REPO_1, files, scan );
57 private void createIndexContainingMoreArtifacts( boolean scan )
60 List<File> files = new ArrayList<File>();
61 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
62 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
63 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
64 + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
65 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
66 + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
67 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
68 + "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
69 files.add( new File( FileUtil.getBasedir(),
70 "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
71 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
72 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
73 files.add( new File( FileUtil.getBasedir(),
74 "src/test/" + TEST_REPO_1 + "/com/classname-search/1.0/classname-search-1.0.jar" ) );
76 createIndex( TEST_REPO_1, files, scan );
79 private void createIndexContainingMultipleArtifactsSameVersion( boolean scan )
82 List<File> files = new ArrayList<File>();
84 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
85 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
86 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
87 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar" ) );
89 createIndex( TEST_REPO_1, files, scan );
93 public void testQuickSearch()
96 createSimpleIndex( false );
98 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
101 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 );
103 archivaConfigControl.replay();
105 SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
107 archivaConfigControl.verify();
109 assertNotNull( results );
111 SearchResultHit hit =
112 results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
113 assertNotNull( "hit null in result " + results.getHits(), hit );
114 assertEquals( "org.apache.archiva", hit.getGroupId() );
115 assertEquals( "archiva-search", hit.getArtifactId() );
116 assertEquals( "1.0", hit.getVersions().get( 0 ) );
118 archivaConfigControl.reset();
121 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2);
123 archivaConfigControl.replay();
125 results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
127 archivaConfigControl.verify();
129 assertNotNull( results );
130 assertEquals( "total hints not 1", 1, results.getTotalHits() );
132 //TODO: search for class & package names
136 public void testQuickSearchNotWithClassifier()
139 createSimpleIndex( true );
141 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
144 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
146 archivaConfigControl.replay();
148 SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
150 archivaConfigControl.verify();
152 assertNotNull( results );
154 SearchResultHit hit =
155 results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
156 assertNotNull( "hit null in result " + results.getHits(), hit );
157 assertEquals( "org.apache.archiva", hit.getGroupId() );
158 assertEquals( "archiva-search", hit.getArtifactId() );
159 assertEquals( "1.0", hit.getVersions().get( 0 ) );
161 archivaConfigControl.reset();
164 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
166 archivaConfigControl.replay();
168 results = search.search( "user", selectedRepos, "archiva-search", null, null );
170 archivaConfigControl.verify();
172 assertNotNull( results );
173 assertEquals( "total hints not 3 hits " + results.getHits(), 3, results.getTotalHits() );
175 //TODO: search for class & package names
179 public void testQuickSearchMultipleArtifactsSameVersion()
182 createIndexContainingMultipleArtifactsSameVersion( false );
184 List<String> selectedRepos = new ArrayList<String>();
185 selectedRepos.add( TEST_REPO_1 );
188 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
190 archivaConfigControl.replay();
192 SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
194 archivaConfigControl.verify();
196 assertNotNull( results );
197 assertEquals( 1, results.getTotalHits() );
199 SearchResultHit hit = results.getHits().get( 0 );
200 assertEquals( "org.apache.archiva", hit.getGroupId() );
201 assertEquals( "archiva-search", hit.getArtifactId() );
202 assertEquals( "1.0", hit.getVersions().get( 0 ) );
204 //only 1 version of 1.0 is retrieved
205 assertEquals( 1, hit.getVersions().size() );
209 public void testMultipleArtifactsSameVersionWithClassifier()
212 createIndexContainingMultipleArtifactsSameVersion( true );
214 List<String> selectedRepos = new ArrayList<String>();
215 selectedRepos.add( TEST_REPO_1 );
218 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
220 archivaConfigControl.replay();
222 SearchFields searchFields = new SearchFields();
223 searchFields.setGroupId( "org.apache.archiva" );
224 searchFields.setArtifactId( "archiva-search" );
225 searchFields.setClassifier( "sources" );
226 searchFields.setRepositories( selectedRepos );
228 SearchResults results = search.search( "user", searchFields, null );
230 archivaConfigControl.verify();
232 assertNotNull( results );
233 assertEquals( 1, results.getTotalHits() );
235 SearchResultHit hit = results.getHits().get( 0 );
236 assertEquals( "org.apache.archiva", hit.getGroupId() );
237 assertEquals( "archiva-search", hit.getArtifactId() );
238 assertEquals( "1.0", hit.getVersions().get( 0 ) );
240 //only 1 version of 1.0 is retrieved
241 assertEquals( 1, hit.getVersions().size() );
244 // search for existing artifact using multiple keywords
246 public void testQuickSearchWithMultipleKeywords()
249 createSimpleIndex( false );
251 List<String> selectedRepos = new ArrayList<String>();
252 selectedRepos.add( TEST_REPO_1 );
254 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
255 archivaConfigControl.replay();
257 SearchResults results = search.search( "user", selectedRepos, "archiva search", null, null );
259 archivaConfigControl.verify();
261 assertNotNull( results );
262 assertEquals( 1, results.getTotalHits() );
266 public void testQuickSearchWithPagination()
269 createSimpleIndex( true );
271 List<String> selectedRepos = new ArrayList<String>();
272 selectedRepos.add( TEST_REPO_1 );
275 SearchResultLimits limits = new SearchResultLimits( 0 );
276 limits.setPageSize( 1 );
278 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
280 archivaConfigControl.replay();
282 SearchResults results = search.search( "user", selectedRepos, "org", limits, new ArrayList<String>() );
284 archivaConfigControl.verify();
286 assertNotNull( results );
287 assertEquals( 1, results.getHits().size() );
288 assertEquals( "total hits not 8 for page1 " + results, 8, results.getTotalHits() );
289 assertEquals( "returned hits not 1 for page1 " + results, 1, results.getReturnedHitsCount() );
290 assertEquals( limits, results.getLimits() );
292 archivaConfigControl.reset();
295 limits = new SearchResultLimits( 1 );
296 limits.setPageSize( 1 );
298 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
300 archivaConfigControl.replay();
302 results = search.search( "user", selectedRepos, "org", limits, null );
304 archivaConfigControl.verify();
306 assertNotNull( results );
308 assertEquals( "hits not 1", 1, results.getHits().size() );
309 assertEquals( "total hits not 8 for page 2 " + results, 8, results.getTotalHits() );
310 assertEquals( "returned hits not 1 for page2 " + results, 1, results.getReturnedHitsCount() );
311 assertEquals( limits, results.getLimits() );
315 public void testArtifactFoundInMultipleRepositories()
318 createSimpleIndex( true );
320 List<File> files = new ArrayList<File>();
321 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2
322 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
323 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2
324 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
325 createIndex( TEST_REPO_2, files, false );
327 List<String> selectedRepos = new ArrayList<String>();
328 selectedRepos.add( TEST_REPO_1 );
329 selectedRepos.add( TEST_REPO_2 );
331 config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
333 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 5 );
335 archivaConfigControl.replay();
337 // wait lucene flush.....
338 Thread.sleep( 2000 );
340 SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
342 archivaConfigControl.verify();
344 assertNotNull( results );
346 SearchResultHit hit =
347 results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
348 assertEquals( "org.apache.archiva", hit.getGroupId() );
349 assertEquals( "archiva-search", hit.getArtifactId() );
350 assertEquals( "not 2 version for hit " + hit + "::" + niceDisplay( results ), 2, hit.getVersions().size() );
351 assertTrue( hit.getVersions().contains( "1.0" ) );
352 assertTrue( hit.getVersions().contains( "1.1" ) );
354 archivaConfigControl.reset();
356 // TODO: [BROWSE] in artifact info from browse, display all the repositories where the artifact is found
360 public void testNoMatchFound()
363 createSimpleIndex( false );
365 List<String> selectedRepos = new ArrayList<String>();
366 selectedRepos.add( TEST_REPO_1 );
368 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
370 archivaConfigControl.replay();
372 SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null, null );
374 archivaConfigControl.verify();
376 assertNotNull( results );
377 assertEquals( 0, results.getTotalHits() );
381 public void testNoIndexFound()
384 List<String> selectedRepos = new ArrayList<String>();
385 selectedRepos.add( TEST_REPO_1 );
387 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
389 archivaConfigControl.replay();
391 SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
392 assertNotNull( results );
393 assertEquals( 0, results.getTotalHits() );
395 archivaConfigControl.verify();
399 public void testRepositoryNotFound()
402 List<String> selectedRepos = new ArrayList<String>();
403 selectedRepos.add( "non-existing-repo" );
405 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
407 archivaConfigControl.replay();
409 SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
410 assertNotNull( results );
411 assertEquals( 0, results.getTotalHits() );
413 archivaConfigControl.verify();
417 public void testSearchWithinSearchResults()
420 createSimpleIndex( true );
422 List<String> selectedRepos = new ArrayList<String>();
423 selectedRepos.add( TEST_REPO_1 );
425 List<String> previousSearchTerms = new ArrayList<String>();
426 previousSearchTerms.add( "archiva-test" );
428 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
430 archivaConfigControl.replay();
432 SearchResults results = search.search( "user", selectedRepos, "1.0", null, previousSearchTerms );
434 archivaConfigControl.verify();
436 assertNotNull( results );
437 assertEquals( "total hints not 1", 1, results.getTotalHits() );
439 SearchResultHit hit = results.getHits().get( 0 );
440 assertEquals( "org.apache.archiva", hit.getGroupId() );
441 assertEquals( "archiva-test", hit.getArtifactId() );
442 assertEquals( "versions not 1", 1, hit.getVersions().size() );
443 assertEquals( "1.0", hit.getVersions().get( 0 ) );
446 // tests for advanced search
448 public void testAdvancedSearch()
451 List<File> files = new ArrayList<File>();
452 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2
453 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
454 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2
455 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
456 createIndex( TEST_REPO_2, files, false );
458 List<String> selectedRepos = new ArrayList<String>();
459 selectedRepos.add( TEST_REPO_2 );
461 SearchFields searchFields = new SearchFields();
462 searchFields.setGroupId( "org.apache.archiva" );
463 searchFields.setVersion( "1.0" );
464 searchFields.setRepositories( selectedRepos );
466 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
468 archivaConfigControl.replay();
470 SearchResults results = search.search( "user", searchFields, null );
472 archivaConfigControl.verify();
474 assertNotNull( results );
475 assertEquals( 1, results.getTotalHits() );
477 SearchResultHit hit = results.getHits().get( 0 );
478 assertEquals( "org.apache.archiva", hit.getGroupId() );
479 assertEquals( "archiva-search", hit.getArtifactId() );
480 assertEquals( "1.0", hit.getVersions().get( 0 ) );
484 public void testAdvancedSearchWithPagination()
487 createIndexContainingMoreArtifacts( false );
489 List<String> selectedRepos = new ArrayList<String>();
490 selectedRepos.add( TEST_REPO_1 );
492 SearchFields searchFields = new SearchFields();
493 searchFields.setGroupId( "org.apache.archiva" );
494 searchFields.setRepositories( selectedRepos );
498 SearchResultLimits limits = new SearchResultLimits( 0 );
499 limits.setPageSize( 1 );
501 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
503 archivaConfigControl.replay();
505 SearchResults results = search.search( "user", searchFields, limits );
507 archivaConfigControl.verify();
509 assertNotNull( results );
510 assertEquals( 4, results.getTotalHits() );
511 assertEquals( 1, results.getHits().size() );
514 archivaConfigControl.reset();
516 limits = new SearchResultLimits( 1 );
517 limits.setPageSize( 1 );
519 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
521 archivaConfigControl.replay();
523 results = search.search( "user", searchFields, limits );
525 archivaConfigControl.verify();
527 assertNotNull( results );
528 assertEquals( 4, results.getTotalHits() );
529 assertEquals( 1, results.getHits().size() );
532 // MRM-981 - artifactIds with numeric characters aren't found in advanced search
534 public void testAdvancedSearchArtifactIdHasNumericChar()
537 List<File> files = new ArrayList<File>();
538 files.add( new File( FileUtil.getBasedir(),
539 "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
540 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
541 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
542 createIndex( TEST_REPO_1, files, true );
544 List<String> selectedRepos = new ArrayList<String>();
545 selectedRepos.add( TEST_REPO_1 );
547 SearchFields searchFields = new SearchFields();
548 searchFields.setArtifactId( "artifactid-numeric" );
549 searchFields.setRepositories( selectedRepos );
551 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
553 archivaConfigControl.replay();
555 SearchResults results = search.search( "user", searchFields, null );
557 archivaConfigControl.verify();
559 assertNotNull( results );
560 assertEquals( 2, results.getTotalHits() );
564 public void testAdvancedSearchNoRepositoriesConfigured()
567 SearchFields searchFields = new SearchFields();
568 searchFields.setArtifactId( "archiva" );
569 searchFields.setRepositories( null );
573 search.search( "user", searchFields, null );
574 fail( "A RepositorySearchExcecption should have been thrown." );
576 catch ( RepositorySearchException e )
578 assertEquals( "Repositories cannot be null.", e.getMessage() );
583 public void testAdvancedSearchSearchFieldsAreNull()
586 List<String> selectedRepos = new ArrayList<String>();
587 selectedRepos.add( TEST_REPO_1 );
589 SearchFields searchFields = new SearchFields();
590 searchFields.setRepositories( selectedRepos );
594 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
596 archivaConfigControl.replay();
598 search.search( "user", searchFields, null );
600 archivaConfigControl.verify();
602 fail( "A RepositorySearchExcecption should have been thrown." );
604 catch ( RepositorySearchException e )
606 assertEquals( "No search fields set.", e.getMessage() );
611 public void testAdvancedSearchSearchFieldsAreBlank()
614 List<String> selectedRepos = new ArrayList<String>();
615 selectedRepos.add( TEST_REPO_1 );
617 SearchFields searchFields = new SearchFields();
618 searchFields.setGroupId( "" );
619 searchFields.setArtifactId( "" );
620 searchFields.setVersion( "" );
621 searchFields.setPackaging( "" );
622 searchFields.setClassName( "" );
624 searchFields.setRepositories( selectedRepos );
628 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
630 archivaConfigControl.replay();
632 search.search( "user", searchFields, null );
634 archivaConfigControl.verify();
636 fail( "A RepositorySearchExcecption should have been thrown." );
638 catch ( RepositorySearchException e )
640 assertEquals( "No search fields set.", e.getMessage() );
645 public void testAdvancedSearchAllSearchCriteriaSpecified()
648 createSimpleIndex( true );
650 List<String> selectedRepos = new ArrayList<String>();
651 selectedRepos.add( TEST_REPO_1 );
653 SearchFields searchFields = new SearchFields();
654 searchFields.setGroupId( "org.apache.archiva" );
655 searchFields.setArtifactId( "archiva-test" );
656 searchFields.setVersion( "2.0" );
657 searchFields.setPackaging( "jar" );
658 searchFields.setClassName( "org.apache.archiva.test.App" );
659 searchFields.setRepositories( selectedRepos );
661 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
663 archivaConfigControl.replay();
665 SearchResults results = search.search( "user", searchFields, null );
667 archivaConfigControl.verify();
669 assertNotNull( results );
671 assertEquals( "total hints not 1" + results, 1, results.getTotalHits() );
673 SearchResultHit hit = results.getHits().get( 0 );
674 assertEquals( "org.apache.archiva", hit.getGroupId() );
675 assertEquals( "archiva-test", hit.getArtifactId() );
676 assertEquals( "version not 2.0", "2.0", hit.getVersions().get( 0 ) );
680 public void testAdvancedSearchJarArtifacts()
683 createIndexContainingMoreArtifacts( true );
685 List<String> selectedRepos = new ArrayList<String>();
686 selectedRepos.add( TEST_REPO_1 );
688 SearchFields searchFields = new SearchFields();
689 searchFields.setPackaging( "jar" );
690 searchFields.setRepositories( selectedRepos );
692 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
694 archivaConfigControl.replay();
696 SearchResults results = search.search( "user", searchFields, null );
698 archivaConfigControl.verify();
700 assertNotNull( results );
701 assertEquals( "not 8 but " + results.getTotalHits() + ":" + niceDisplay( results ), 8, results.getTotalHits() );
705 public void testAdvancedSearchWithIncorrectPackaging()
708 createSimpleIndex( true );
710 List<String> selectedRepos = new ArrayList<String>();
711 selectedRepos.add( TEST_REPO_1 );
713 SearchFields searchFields = new SearchFields();
714 searchFields.setGroupId( "org.apache.archiva" );
715 searchFields.setArtifactId( "archiva-test" );
716 searchFields.setVersion( "2.0" );
717 searchFields.setPackaging( "war" );
718 searchFields.setRepositories( selectedRepos );
720 archivaConfigControl.expectAndDefaultReturn( archivaConfig.getConfiguration(), config );
721 archivaConfigControl.replay();
723 SearchResults results = search.search( "user", searchFields, null );
725 archivaConfigControl.verify();
727 assertNotNull( results );
728 assertEquals( 0, results.getTotalHits() );
732 public void testAdvancedSearchClassname()
735 createIndexContainingMoreArtifacts( true );
737 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
739 SearchFields searchFields = new SearchFields();
740 searchFields.setClassName( "com.classname.search.App" );
741 searchFields.setRepositories( selectedRepos );
743 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
745 archivaConfigControl.replay();
747 SearchResults results = search.search( "user", searchFields, null );
749 archivaConfigControl.verify();
751 assertNotNull( results );
752 assertEquals( "totalHits not 1 results " + results, 1, results.getTotalHits() );
754 SearchResultHit hit = results.getHits().get( 0 );
755 assertEquals( "groupId not com", "com", hit.getGroupId() );
756 assertEquals( "arttifactId not classname-search", "classname-search", hit.getArtifactId() );
757 assertEquals( " hits.version(0) not 1.0", "1.0", hit.getVersions().get( 0 ) );
761 public void testAdvancedSearchNoIndexFound()
764 List<String> selectedRepos = new ArrayList<String>();
765 selectedRepos.add( TEST_REPO_1 );
767 SearchFields searchFields = new SearchFields();
768 searchFields.setGroupId( "org.apache.archiva" );
769 searchFields.setRepositories( selectedRepos );
771 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
773 archivaConfigControl.replay();
775 SearchResults results = search.search( "user", searchFields, null );
777 archivaConfigControl.verify();
779 assertNotNull( results );
780 assertEquals( 0, results.getTotalHits() );
784 public void testAdvancedSearchClassNameInWar()
787 createIndexContainingMoreArtifacts( true );
789 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
791 SearchFields searchFields = new SearchFields();
792 searchFields.setClassName( "SomeClass" );
793 searchFields.setRepositories( selectedRepos );
795 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
797 archivaConfigControl.replay();
799 SearchResults results = search.search( "user", searchFields, null );
801 archivaConfigControl.verify();
803 assertNotNull( results );
804 assertEquals( 1, results.getHits().size() );
805 assertEquals( "test-webapp", results.getHits().get( 0 ).getArtifactId() );
809 public void getAllGroupIds() throws Exception
811 createIndexContainingMoreArtifacts( true );
813 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
815 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 0 , 2 );
817 archivaConfigControl.replay();
819 Collection<String> groupIds = search.getAllGroupIds( "user", selectedRepos );
821 archivaConfigControl.verify();
823 log.info( "groupIds: " + groupIds );
825 assertEquals( 3, groupIds.size() );
826 assertTrue( groupIds.contains( "com" ));
827 assertTrue( groupIds.contains( "org.apache.felix") );
828 assertTrue( groupIds.contains( "org.apache.archiva" ) );