1 package org.apache.archiva.indexer.maven.search;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import junit.framework.TestCase;
22 import org.apache.archiva.indexer.search.SearchResultHit;
23 import org.apache.archiva.indexer.search.SearchResultLimits;
24 import org.apache.archiva.indexer.search.SearchResults;
25 import org.apache.archiva.indexer.util.SearchUtil;
26 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
27 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
28 import org.junit.After;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.test.context.ContextConfiguration;
34 import java.util.Arrays;
37 * @author Olivier Lamy
39 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
40 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
41 public class MavenRepositorySearchPaginateTest
46 ArchivaRepositoryRegistry repositoryRegistry;
49 public void endTests() {
50 assert repositoryRegistry!=null;
51 repositoryRegistry.destroy();
55 public void nonPaginatedResult()
58 MavenRepositorySearch search = new MavenRepositorySearch();
60 SearchResults searchResults = build( 10, new SearchResultLimits( 0 ) );
62 searchResults = search.paginate( searchResults );
64 assertEquals( 10, searchResults.getReturnedHitsCount() );
69 public void nonPaginatedHugeResult()
72 MavenRepositorySearch search = new MavenRepositorySearch();
74 SearchResults origSearchResults = build( 63, new SearchResultLimits( 0 ) );
76 SearchResults searchResults = search.paginate( origSearchResults );
78 assertEquals( 30, searchResults.getReturnedHitsCount() );
80 origSearchResults = build( 63, new SearchResultLimits( 1 ) );
82 searchResults = search.paginate( origSearchResults );
84 assertEquals( 30, searchResults.getReturnedHitsCount() );
89 public void paginatedResult()
92 MavenRepositorySearch search = new MavenRepositorySearch();
94 SearchResults searchResults = build( 32, new SearchResultLimits( 1 ) );
96 searchResults = search.paginate( searchResults );
98 assertEquals( 2, searchResults.getReturnedHitsCount() );
103 SearchResults build( int number, SearchResultLimits limits )
105 SearchResults searchResults = new SearchResults();
106 searchResults.setLimits( limits );
107 for ( int i = 0; i < number; i++ )
109 SearchResultHit hit = new SearchResultHit();
110 hit.setGroupId( "commons-foo" );
111 hit.setArtifactId( "commons-bar-" + i );
112 hit.setPackaging( "jar" );
113 hit.setVersions( Arrays.asList( "1.0" ) );
115 SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(), hit.getPackaging() );
116 searchResults.addHit( id, hit );
119 searchResults.setTotalHits( number );
120 return searchResults;