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.repository.base.group.RepositoryGroupHandler;
28 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
29 import org.junit.After;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.springframework.test.context.ContextConfiguration;
34 import javax.inject.Inject;
35 import java.util.Arrays;
38 * @author Olivier Lamy
40 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
41 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
42 public class MavenRepositorySearchPaginateTest
47 ArchivaRepositoryRegistry repositoryRegistry;
50 RepositoryGroupHandler repositoryGroupHandler;
53 public void endTests() {
54 assert repositoryRegistry!=null;
55 repositoryRegistry.destroy();
59 public void nonPaginatedResult()
62 MavenRepositorySearch search = new MavenRepositorySearch();
64 SearchResults searchResults = build( 10, new SearchResultLimits( 0 ) );
66 searchResults = search.paginate( searchResults );
68 assertEquals( 10, searchResults.getReturnedHitsCount() );
73 public void nonPaginatedHugeResult()
76 MavenRepositorySearch search = new MavenRepositorySearch();
78 SearchResults origSearchResults = build( 63, new SearchResultLimits( 0 ) );
80 SearchResults searchResults = search.paginate( origSearchResults );
82 assertEquals( 30, searchResults.getReturnedHitsCount() );
84 origSearchResults = build( 63, new SearchResultLimits( 1 ) );
86 searchResults = search.paginate( origSearchResults );
88 assertEquals( 30, searchResults.getReturnedHitsCount() );
93 public void paginatedResult()
96 MavenRepositorySearch search = new MavenRepositorySearch();
98 SearchResults searchResults = build( 32, new SearchResultLimits( 1 ) );
100 searchResults = search.paginate( searchResults );
102 assertEquals( 2, searchResults.getReturnedHitsCount() );
107 SearchResults build( int number, SearchResultLimits limits )
109 SearchResults searchResults = new SearchResults();
110 searchResults.setLimits( limits );
111 for ( int i = 0; i < number; i++ )
113 SearchResultHit hit = new SearchResultHit();
114 hit.setGroupId( "commons-foo" );
115 hit.setArtifactId( "commons-bar-" + i );
116 hit.setPackaging( "jar" );
117 hit.setVersions( Arrays.asList( "1.0" ) );
119 SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(), hit.getPackaging() );
120 searchResults.addHit( id, hit );
123 searchResults.setTotalHits( number );
124 return searchResults;