1 package org.apache.archiva.indexer.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.util.SearchUtil;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.JUnit4;
27 import java.util.Arrays;
30 * @author Olivier Lamy
32 @RunWith( JUnit4.class )
33 public class NexusRepositorySearchPaginateTest
37 public void nonPaginatedResult()
40 NexusRepositorySearch search = new NexusRepositorySearch();
42 SearchResults searchResults = build( 10, new SearchResultLimits( 0 ) );
44 searchResults = search.paginate( searchResults );
46 assertEquals( 10, searchResults.getReturnedHitsCount() );
51 public void nonPaginatedHugeResult()
54 NexusRepositorySearch search = new NexusRepositorySearch();
56 SearchResults origSearchResults = build( 63, new SearchResultLimits( 0 ) );
58 SearchResults searchResults = search.paginate( origSearchResults );
60 assertEquals( 30, searchResults.getReturnedHitsCount() );
62 origSearchResults = build( 63, new SearchResultLimits( 1 ) );
64 searchResults = search.paginate( origSearchResults );
66 assertEquals( 30, searchResults.getReturnedHitsCount() );
71 public void paginatedResult()
74 NexusRepositorySearch search = new NexusRepositorySearch();
76 SearchResults searchResults = build( 32, new SearchResultLimits( 1 ) );
78 searchResults = search.paginate( searchResults );
80 assertEquals( 2, searchResults.getReturnedHitsCount() );
85 SearchResults build( int number, SearchResultLimits limits )
87 SearchResults searchResults = new SearchResults();
88 searchResults.setLimits( limits );
89 for ( int i = 0; i < number; i++ )
91 SearchResultHit hit = new SearchResultHit();
92 hit.setGroupId( "commons-foo" );
93 hit.setArtifactId( "commons-bar-" + i );
94 hit.setPackaging( "jar" );
95 hit.setVersions( Arrays.asList( "1.0" ) );
97 SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(), hit.getPackaging() );
98 searchResults.addHit( id, hit );
101 searchResults.setTotalHits( number );
102 return searchResults;