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.List;
35 @RunWith( SpringJUnit4ClassRunner.class )
36 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
37 public class NexusRepositorySearchTest
38 extends AbstractNexusRepositorySearch
42 private void createSimpleIndex( boolean scan )
45 List<File> files = new ArrayList<File>();
46 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
47 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
48 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
49 + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
50 files.add( new File( FileUtil.getBasedir(), "/src/test/" + TEST_REPO_1
51 + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
53 createIndex( TEST_REPO_1, files, scan );
56 private void createIndexContainingMoreArtifacts( boolean scan )
59 List<File> files = new ArrayList<File>();
60 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
61 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
62 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
63 + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
64 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
65 + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
66 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
67 + "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) );
68 files.add( new File( FileUtil.getBasedir(),
69 "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
70 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
71 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
72 files.add( new File( FileUtil.getBasedir(),
73 "src/test/" + TEST_REPO_1 + "/com/classname-search/1.0/classname-search-1.0.jar" ) );
75 createIndex( TEST_REPO_1, files, scan );
78 private void createIndexContainingMultipleArtifactsSameVersion( boolean scan )
81 List<File> files = new ArrayList<File>();
83 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
84 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
85 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
86 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar" ) );
88 createIndex( TEST_REPO_1, files, scan );
92 public void testQuickSearch()
95 createSimpleIndex( false );
97 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
100 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 1, 2 );
102 archivaConfigControl.replay();
104 SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
106 archivaConfigControl.verify();
108 assertNotNull( results );
110 SearchResultHit hit =
111 results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
112 assertNotNull( "hit null in result " + results.getHits(), hit );
113 assertEquals( "org.apache.archiva", hit.getGroupId() );
114 assertEquals( "archiva-search", hit.getArtifactId() );
115 assertEquals( "1.0", hit.getVersions().get( 0 ) );
117 archivaConfigControl.reset();
120 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2);
122 archivaConfigControl.replay();
124 results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
126 archivaConfigControl.verify();
128 assertNotNull( results );
129 assertEquals( "total hints not 1", 1, results.getTotalHits() );
131 //TODO: search for class & package names
135 public void testQuickSearchNotWithClassifier()
138 createSimpleIndex( true );
140 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
143 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
145 archivaConfigControl.replay();
147 SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
149 archivaConfigControl.verify();
151 assertNotNull( results );
153 SearchResultHit hit =
154 results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
155 assertNotNull( "hit null in result " + results.getHits(), hit );
156 assertEquals( "org.apache.archiva", hit.getGroupId() );
157 assertEquals( "archiva-search", hit.getArtifactId() );
158 assertEquals( "1.0", hit.getVersions().get( 0 ) );
160 archivaConfigControl.reset();
163 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
165 archivaConfigControl.replay();
167 results = search.search( "user", selectedRepos, "archiva-search", null, null );
169 archivaConfigControl.verify();
171 assertNotNull( results );
172 assertEquals( "total hints not 3 hits " + results.getHits(), 3, results.getTotalHits() );
174 //TODO: search for class & package names
178 public void testQuickSearchMultipleArtifactsSameVersion()
181 createIndexContainingMultipleArtifactsSameVersion( false );
183 List<String> selectedRepos = new ArrayList<String>();
184 selectedRepos.add( TEST_REPO_1 );
187 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
189 archivaConfigControl.replay();
191 SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
193 archivaConfigControl.verify();
195 assertNotNull( results );
196 assertEquals( 1, results.getTotalHits() );
198 SearchResultHit hit = results.getHits().get( 0 );
199 assertEquals( "org.apache.archiva", hit.getGroupId() );
200 assertEquals( "archiva-search", hit.getArtifactId() );
201 assertEquals( "1.0", hit.getVersions().get( 0 ) );
203 //only 1 version of 1.0 is retrieved
204 assertEquals( 1, hit.getVersions().size() );
208 public void testMultipleArtifactsSameVersionWithClassifier()
211 createIndexContainingMultipleArtifactsSameVersion( true );
213 List<String> selectedRepos = new ArrayList<String>();
214 selectedRepos.add( TEST_REPO_1 );
217 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
219 archivaConfigControl.replay();
221 SearchFields searchFields = new SearchFields();
222 searchFields.setGroupId( "org.apache.archiva" );
223 searchFields.setArtifactId( "archiva-search" );
224 searchFields.setClassifier( "sources" );
225 searchFields.setRepositories( selectedRepos );
227 SearchResults results = search.search( "user", searchFields, null );
229 archivaConfigControl.verify();
231 assertNotNull( results );
232 assertEquals( 1, results.getTotalHits() );
234 SearchResultHit hit = results.getHits().get( 0 );
235 assertEquals( "org.apache.archiva", hit.getGroupId() );
236 assertEquals( "archiva-search", hit.getArtifactId() );
237 assertEquals( "1.0", hit.getVersions().get( 0 ) );
239 //only 1 version of 1.0 is retrieved
240 assertEquals( 1, hit.getVersions().size() );
243 // search for existing artifact using multiple keywords
245 public void testQuickSearchWithMultipleKeywords()
248 createSimpleIndex( false );
250 List<String> selectedRepos = new ArrayList<String>();
251 selectedRepos.add( TEST_REPO_1 );
253 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
254 archivaConfigControl.replay();
256 SearchResults results = search.search( "user", selectedRepos, "archiva search", null, null );
258 archivaConfigControl.verify();
260 assertNotNull( results );
261 assertEquals( 1, results.getTotalHits() );
265 public void testQuickSearchWithPagination()
268 createSimpleIndex( true );
270 List<String> selectedRepos = new ArrayList<String>();
271 selectedRepos.add( TEST_REPO_1 );
274 SearchResultLimits limits = new SearchResultLimits( 0 );
275 limits.setPageSize( 1 );
277 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
279 archivaConfigControl.replay();
281 SearchResults results = search.search( "user", selectedRepos, "org", limits, new ArrayList<String>() );
283 archivaConfigControl.verify();
285 assertNotNull( results );
286 assertEquals( 1, results.getHits().size() );
287 assertEquals( "total hits not 8 for page1 " + results, 8, results.getTotalHits() );
288 assertEquals( "returned hits not 1 for page1 " + results, 1, results.getReturnedHitsCount() );
289 assertEquals( limits, results.getLimits() );
291 archivaConfigControl.reset();
294 limits = new SearchResultLimits( 1 );
295 limits.setPageSize( 1 );
297 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
299 archivaConfigControl.replay();
301 results = search.search( "user", selectedRepos, "org", limits, null );
303 archivaConfigControl.verify();
305 assertNotNull( results );
307 assertEquals( "hits not 1", 1, results.getHits().size() );
308 assertEquals( "total hits not 8 for page 2 " + results, 8, results.getTotalHits() );
309 assertEquals( "returned hits not 1 for page2 " + results, 1, results.getReturnedHitsCount() );
310 assertEquals( limits, results.getLimits() );
314 public void testArtifactFoundInMultipleRepositories()
317 createSimpleIndex( true );
319 List<File> files = new ArrayList<File>();
320 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2
321 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
322 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2
323 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
324 createIndex( TEST_REPO_2, files, false );
326 List<String> selectedRepos = new ArrayList<String>();
327 selectedRepos.add( TEST_REPO_1 );
328 selectedRepos.add( TEST_REPO_2 );
330 config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
332 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 5 );
334 archivaConfigControl.replay();
336 // wait lucene flush.....
337 Thread.sleep( 2000 );
339 SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
341 archivaConfigControl.verify();
343 assertNotNull( results );
345 SearchResultHit hit =
346 results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
347 assertEquals( "org.apache.archiva", hit.getGroupId() );
348 assertEquals( "archiva-search", hit.getArtifactId() );
349 assertEquals( "not 2 version for hit " + hit + "::" + niceDisplay( results ), 2, hit.getVersions().size() );
350 assertTrue( hit.getVersions().contains( "1.0" ) );
351 assertTrue( hit.getVersions().contains( "1.1" ) );
353 archivaConfigControl.reset();
355 // TODO: [BROWSE] in artifact info from browse, display all the repositories where the artifact is found
359 public void testNoMatchFound()
362 createSimpleIndex( false );
364 List<String> selectedRepos = new ArrayList<String>();
365 selectedRepos.add( TEST_REPO_1 );
367 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
369 archivaConfigControl.replay();
371 SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null, null );
373 archivaConfigControl.verify();
375 assertNotNull( results );
376 assertEquals( 0, results.getTotalHits() );
380 public void testNoIndexFound()
383 List<String> selectedRepos = new ArrayList<String>();
384 selectedRepos.add( TEST_REPO_1 );
386 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
388 archivaConfigControl.replay();
390 SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
391 assertNotNull( results );
392 assertEquals( 0, results.getTotalHits() );
394 archivaConfigControl.verify();
398 public void testRepositoryNotFound()
401 List<String> selectedRepos = new ArrayList<String>();
402 selectedRepos.add( "non-existing-repo" );
404 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
406 archivaConfigControl.replay();
408 SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
409 assertNotNull( results );
410 assertEquals( 0, results.getTotalHits() );
412 archivaConfigControl.verify();
416 public void testSearchWithinSearchResults()
419 createSimpleIndex( true );
421 List<String> selectedRepos = new ArrayList<String>();
422 selectedRepos.add( TEST_REPO_1 );
424 List<String> previousSearchTerms = new ArrayList<String>();
425 previousSearchTerms.add( "archiva-test" );
427 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
429 archivaConfigControl.replay();
431 SearchResults results = search.search( "user", selectedRepos, "1.0", null, previousSearchTerms );
433 archivaConfigControl.verify();
435 assertNotNull( results );
436 assertEquals( "total hints not 1", 1, results.getTotalHits() );
438 SearchResultHit hit = results.getHits().get( 0 );
439 assertEquals( "org.apache.archiva", hit.getGroupId() );
440 assertEquals( "archiva-test", hit.getArtifactId() );
441 assertEquals( "versions not 1", 1, hit.getVersions().size() );
442 assertEquals( "1.0", hit.getVersions().get( 0 ) );
445 // tests for advanced search
447 public void testAdvancedSearch()
450 List<File> files = new ArrayList<File>();
451 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2
452 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
453 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2
454 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) );
455 createIndex( TEST_REPO_2, files, false );
457 List<String> selectedRepos = new ArrayList<String>();
458 selectedRepos.add( TEST_REPO_2 );
460 SearchFields searchFields = new SearchFields();
461 searchFields.setGroupId( "org.apache.archiva" );
462 searchFields.setVersion( "1.0" );
463 searchFields.setRepositories( selectedRepos );
465 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
467 archivaConfigControl.replay();
469 SearchResults results = search.search( "user", searchFields, null );
471 archivaConfigControl.verify();
473 assertNotNull( results );
474 assertEquals( 1, results.getTotalHits() );
476 SearchResultHit hit = results.getHits().get( 0 );
477 assertEquals( "org.apache.archiva", hit.getGroupId() );
478 assertEquals( "archiva-search", hit.getArtifactId() );
479 assertEquals( "1.0", hit.getVersions().get( 0 ) );
483 public void testAdvancedSearchWithPagination()
486 createIndexContainingMoreArtifacts( false );
488 List<String> selectedRepos = new ArrayList<String>();
489 selectedRepos.add( TEST_REPO_1 );
491 SearchFields searchFields = new SearchFields();
492 searchFields.setGroupId( "org.apache.archiva" );
493 searchFields.setRepositories( selectedRepos );
497 SearchResultLimits limits = new SearchResultLimits( 0 );
498 limits.setPageSize( 1 );
500 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
502 archivaConfigControl.replay();
504 SearchResults results = search.search( "user", searchFields, limits );
506 archivaConfigControl.verify();
508 assertNotNull( results );
509 assertEquals( 4, results.getTotalHits() );
510 assertEquals( 1, results.getHits().size() );
513 archivaConfigControl.reset();
515 limits = new SearchResultLimits( 1 );
516 limits.setPageSize( 1 );
518 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
520 archivaConfigControl.replay();
522 results = search.search( "user", searchFields, limits );
524 archivaConfigControl.verify();
526 assertNotNull( results );
527 assertEquals( 4, results.getTotalHits() );
528 assertEquals( 1, results.getHits().size() );
531 // MRM-981 - artifactIds with numeric characters aren't found in advanced search
533 public void testAdvancedSearchArtifactIdHasNumericChar()
536 List<File> files = new ArrayList<File>();
537 files.add( new File( FileUtil.getBasedir(),
538 "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) );
539 files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1
540 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) );
541 createIndex( TEST_REPO_1, files, true );
543 List<String> selectedRepos = new ArrayList<String>();
544 selectedRepos.add( TEST_REPO_1 );
546 SearchFields searchFields = new SearchFields();
547 searchFields.setArtifactId( "artifactid-numeric" );
548 searchFields.setRepositories( selectedRepos );
550 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
552 archivaConfigControl.replay();
554 SearchResults results = search.search( "user", searchFields, null );
556 archivaConfigControl.verify();
558 assertNotNull( results );
559 assertEquals( 2, results.getTotalHits() );
563 public void testAdvancedSearchNoRepositoriesConfigured()
566 SearchFields searchFields = new SearchFields();
567 searchFields.setArtifactId( "archiva" );
568 searchFields.setRepositories( null );
572 search.search( "user", searchFields, null );
573 fail( "A RepositorySearchExcecption should have been thrown." );
575 catch ( RepositorySearchException e )
577 assertEquals( "Repositories cannot be null.", e.getMessage() );
582 public void testAdvancedSearchSearchFieldsAreNull()
585 List<String> selectedRepos = new ArrayList<String>();
586 selectedRepos.add( TEST_REPO_1 );
588 SearchFields searchFields = new SearchFields();
589 searchFields.setRepositories( selectedRepos );
593 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
595 archivaConfigControl.replay();
597 search.search( "user", searchFields, null );
599 archivaConfigControl.verify();
601 fail( "A RepositorySearchExcecption should have been thrown." );
603 catch ( RepositorySearchException e )
605 assertEquals( "No search fields set.", e.getMessage() );
610 public void testAdvancedSearchSearchFieldsAreBlank()
613 List<String> selectedRepos = new ArrayList<String>();
614 selectedRepos.add( TEST_REPO_1 );
616 SearchFields searchFields = new SearchFields();
617 searchFields.setGroupId( "" );
618 searchFields.setArtifactId( "" );
619 searchFields.setVersion( "" );
620 searchFields.setPackaging( "" );
621 searchFields.setClassName( "" );
623 searchFields.setRepositories( selectedRepos );
627 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
629 archivaConfigControl.replay();
631 search.search( "user", searchFields, null );
633 archivaConfigControl.verify();
635 fail( "A RepositorySearchExcecption should have been thrown." );
637 catch ( RepositorySearchException e )
639 assertEquals( "No search fields set.", e.getMessage() );
644 public void testAdvancedSearchAllSearchCriteriaSpecified()
647 createSimpleIndex( true );
649 List<String> selectedRepos = new ArrayList<String>();
650 selectedRepos.add( TEST_REPO_1 );
652 SearchFields searchFields = new SearchFields();
653 searchFields.setGroupId( "org.apache.archiva" );
654 searchFields.setArtifactId( "archiva-test" );
655 searchFields.setVersion( "2.0" );
656 searchFields.setPackaging( "jar" );
657 searchFields.setClassName( "org.apache.archiva.test.App" );
658 searchFields.setRepositories( selectedRepos );
660 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
662 archivaConfigControl.replay();
664 SearchResults results = search.search( "user", searchFields, null );
666 archivaConfigControl.verify();
668 assertNotNull( results );
670 assertEquals( "total hints not 1" + results, 1, results.getTotalHits() );
672 SearchResultHit hit = results.getHits().get( 0 );
673 assertEquals( "org.apache.archiva", hit.getGroupId() );
674 assertEquals( "archiva-test", hit.getArtifactId() );
675 assertEquals( "version not 2.0", "2.0", hit.getVersions().get( 0 ) );
679 public void testAdvancedSearchJarArtifacts()
682 createIndexContainingMoreArtifacts( true );
684 List<String> selectedRepos = new ArrayList<String>();
685 selectedRepos.add( TEST_REPO_1 );
687 SearchFields searchFields = new SearchFields();
688 searchFields.setPackaging( "jar" );
689 searchFields.setRepositories( selectedRepos );
691 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
693 archivaConfigControl.replay();
695 SearchResults results = search.search( "user", searchFields, null );
697 archivaConfigControl.verify();
699 assertNotNull( results );
700 assertEquals( "not 8 but " + results.getTotalHits() + ":" + niceDisplay( results ), 8, results.getTotalHits() );
704 public void testAdvancedSearchWithIncorrectPackaging()
707 createSimpleIndex( true );
709 List<String> selectedRepos = new ArrayList<String>();
710 selectedRepos.add( TEST_REPO_1 );
712 SearchFields searchFields = new SearchFields();
713 searchFields.setGroupId( "org.apache.archiva" );
714 searchFields.setArtifactId( "archiva-test" );
715 searchFields.setVersion( "2.0" );
716 searchFields.setPackaging( "war" );
717 searchFields.setRepositories( selectedRepos );
719 archivaConfigControl.expectAndDefaultReturn( archivaConfig.getConfiguration(), config );
720 archivaConfigControl.replay();
722 SearchResults results = search.search( "user", searchFields, null );
724 archivaConfigControl.verify();
726 assertNotNull( results );
727 assertEquals( 0, results.getTotalHits() );
731 public void testAdvancedSearchClassname()
734 createIndexContainingMoreArtifacts( true );
736 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
738 SearchFields searchFields = new SearchFields();
739 searchFields.setClassName( "com.classname.search.App" );
740 searchFields.setRepositories( selectedRepos );
742 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
744 archivaConfigControl.replay();
746 SearchResults results = search.search( "user", searchFields, null );
748 archivaConfigControl.verify();
750 assertNotNull( results );
751 assertEquals( "totalHits not 1 results " + results, 1, results.getTotalHits() );
753 SearchResultHit hit = results.getHits().get( 0 );
754 assertEquals( "groupId not com", "com", hit.getGroupId() );
755 assertEquals( "arttifactId not classname-search", "classname-search", hit.getArtifactId() );
756 assertEquals( " hits.version(0) not 1.0", "1.0", hit.getVersions().get( 0 ) );
760 public void testAdvancedSearchNoIndexFound()
763 List<String> selectedRepos = new ArrayList<String>();
764 selectedRepos.add( TEST_REPO_1 );
766 SearchFields searchFields = new SearchFields();
767 searchFields.setGroupId( "org.apache.archiva" );
768 searchFields.setRepositories( selectedRepos );
770 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
772 archivaConfigControl.replay();
774 SearchResults results = search.search( "user", searchFields, null );
776 archivaConfigControl.verify();
778 assertNotNull( results );
779 assertEquals( 0, results.getTotalHits() );
783 public void testAdvancedSearchClassNameInWar()
786 createIndexContainingMoreArtifacts( true );
788 List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
790 SearchFields searchFields = new SearchFields();
791 searchFields.setClassName( "SomeClass" );
792 searchFields.setRepositories( selectedRepos );
794 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
796 archivaConfigControl.replay();
798 SearchResults results = search.search( "user", searchFields, null );
800 archivaConfigControl.verify();
802 assertNotNull( results );
803 assertEquals( 1, results.getHits().size() );
804 assertEquals( "test-webapp", results.getHits().get( 0 ).getArtifactId() );