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.RepositoryHandlerDependencies;
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;
49 @SuppressWarnings( "unused" )
51 RepositoryHandlerDependencies repositoryHandlerDependencies;
54 public void endTests() {
55 assert repositoryRegistry!=null;
56 repositoryRegistry.destroy();
60 public void nonPaginatedResult()
63 MavenRepositorySearch search = new MavenRepositorySearch();
65 SearchResults searchResults = build( 10, new SearchResultLimits( 0 ) );
67 searchResults = search.paginate( searchResults );
69 assertEquals( 10, searchResults.getReturnedHitsCount() );
74 public void nonPaginatedHugeResult()
77 MavenRepositorySearch search = new MavenRepositorySearch();
79 SearchResults origSearchResults = build( 63, new SearchResultLimits( 0 ) );
81 SearchResults searchResults = search.paginate( origSearchResults );
83 assertEquals( 30, searchResults.getReturnedHitsCount() );
85 origSearchResults = build( 63, new SearchResultLimits( 1 ) );
87 searchResults = search.paginate( origSearchResults );
89 assertEquals( 30, searchResults.getReturnedHitsCount() );
94 public void paginatedResult()
97 MavenRepositorySearch search = new MavenRepositorySearch();
99 SearchResults searchResults = build( 32, new SearchResultLimits( 1 ) );
101 searchResults = search.paginate( searchResults );
103 assertEquals( 2, searchResults.getReturnedHitsCount() );
108 SearchResults build( int number, SearchResultLimits limits )
110 SearchResults searchResults = new SearchResults();
111 searchResults.setLimits( limits );
112 for ( int i = 0; i < number; i++ )
114 SearchResultHit hit = new SearchResultHit();
115 hit.setGroupId( "commons-foo" );
116 hit.setArtifactId( "commons-bar-" + i );
117 hit.setPackaging( "jar" );
118 hit.setVersions( Arrays.asList( "1.0" ) );
120 SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(), hit.getPackaging() );
121 searchResults.addHit( id, hit );
124 searchResults.setTotalHits( number );
125 return searchResults;