diff options
author | Olivier Lamy <olamy@apache.org> | 2014-04-24 11:35:35 +1000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2014-04-24 11:52:24 +1000 |
commit | 641e04909f6921be57c0650131f471a8b3e277d3 (patch) | |
tree | 8d8ff7633ff60af2081e8cd4498f7bcc4b62bd2c /archiva-modules | |
parent | c52eb2c0426bd64cfbff925ea9b4070f395f9aa4 (diff) | |
download | archiva-641e04909f6921be57c0650131f471a8b3e277d3.tar.gz archiva-641e04909f6921be57c0650131f471a8b3e277d3.zip |
fix unit test for pagination
Diffstat (limited to 'archiva-modules')
3 files changed, 44 insertions, 25 deletions
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java index 1968cef02..c126fd740 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java @@ -160,8 +160,8 @@ public class MavenRepositorySearch if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) ) { q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, - new UserInputSearchExpression( searchFields.getArtifactId() ) ), - Occur.MUST ); + new UserInputSearchExpression( searchFields.getArtifactId() ) ), Occur.MUST + ); } if ( StringUtils.isNotBlank( searchFields.getVersion() ) ) @@ -187,35 +187,40 @@ public class MavenRepositorySearch { q.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME, new UserInputSearchExpression( searchFields.getBundleSymbolicName() ) ), - Occur.MUST ); + Occur.MUST + ); } if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) ) { q.add( indexer.constructQuery( OSGI.VERSION, new UserInputSearchExpression( searchFields.getBundleVersion() ) ), - Occur.MUST ); + Occur.MUST + ); } if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) ) { q.add( indexer.constructQuery( OSGI.EXPORT_PACKAGE, new UserInputSearchExpression( searchFields.getBundleExportPackage() ) ), - Occur.MUST ); + Occur.MUST + ); } if ( StringUtils.isNotBlank( searchFields.getBundleExportService() ) ) { q.add( indexer.constructQuery( OSGI.EXPORT_SERVICE, new UserInputSearchExpression( searchFields.getBundleExportService() ) ), - Occur.MUST ); + Occur.MUST + ); } if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) ) { q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE, new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ), - Occur.MUST ); + Occur.MUST + ); } if ( StringUtils.isNotBlank( searchFields.getBundleName() ) ) @@ -228,21 +233,23 @@ public class MavenRepositorySearch { q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE, new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ), - Occur.MUST ); + Occur.MUST + ); } if ( StringUtils.isNotBlank( searchFields.getBundleRequireBundle() ) ) { q.add( indexer.constructQuery( OSGI.REQUIRE_BUNDLE, new UserInputSearchExpression( searchFields.getBundleRequireBundle() ) ), - Occur.MUST ); + Occur.MUST + ); } if ( StringUtils.isNotBlank( searchFields.getClassifier() ) ) { q.add( indexer.constructQuery( MAVEN.CLASSIFIER, - new UserInputSearchExpression( searchFields.getClassifier() ) ), - Occur.MUST ); + new UserInputSearchExpression( searchFields.getClassifier() ) ), Occur.MUST + ); } if ( q.getClauses() == null || q.getClauses().length <= 0 ) @@ -265,7 +272,13 @@ public class MavenRepositorySearch FlatSearchRequest request = new FlatSearchRequest( q ); request.setContexts( getIndexingContexts( indexingContextIds ) ); - request.setCount(limits.getPageSize()*(Math.max(1, limits.getSelectedPage()))); + if ( limits != null ) + { + if ( limits.getSelectedPage() < 1 ) + { + request.setCount( limits.getPageSize() * ( Math.max( 1, limits.getSelectedPage() ) ) ); + } + } FlatSearchResponse response = indexer.searchFlat( request ); @@ -627,6 +640,8 @@ public class MavenRepositorySearch SearchResultLimits limits = results.getLimits(); SearchResults paginated = new SearchResults(); + // ( limits.getPageSize() * ( Math.max( 1, limits.getSelectedPage() ) ) ); + int fetchCount = limits.getPageSize(); int offset = ( limits.getSelectedPage() * limits.getPageSize() ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java index bdb4de4ae..0a0c922ee 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java @@ -28,9 +28,9 @@ public class SearchUtil { public static String getHitId( String groupId, String artifactId, String classifier, String packaging ) { - return ( StringUtils.isBlank( groupId ) ? "" : StringUtils.trim( groupId ) ) + ":" - + ( StringUtils.isBlank( artifactId ) ? "" : StringUtils.trim( artifactId ) ) + ":" - + ( StringUtils.isBlank( classifier ) ? "" : StringUtils.trim( classifier ) ) + ":" + ( StringUtils.isBlank( - packaging ) ? "" : StringUtils.trim( packaging ) ); + return ( StringUtils.isBlank( groupId ) ? "" : StringUtils.trim( groupId ) ) + ":" // + + ( StringUtils.isBlank( artifactId ) ? "" : StringUtils.trim( artifactId ) ) + ":" // + + ( StringUtils.isBlank( classifier ) ? "" : StringUtils.trim( classifier ) ) + ":" // + + ( StringUtils.isBlank( packaging ) ? "" : StringUtils.trim( packaging ) ); } } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java index 83d19380c..c3c8bfa0c 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java @@ -29,6 +29,10 @@ import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -36,8 +40,8 @@ import java.util.Collections; import java.util.List; -@RunWith ( ArchivaSpringJUnit4ClassRunner.class ) -@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) +@RunWith(ArchivaSpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" }) public class MavenRepositorySearchTest extends AbstractMavenRepositorySearch { @@ -47,12 +51,12 @@ public class MavenRepositorySearchTest throws Exception { List<File> files = new ArrayList<>(); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 - + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 - + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "/src/test/" + TEST_REPO_1 - + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) ); + files.add( Paths.get( FileUtil.getBasedir(), "src/test", TEST_REPO_1, + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ).toFile() ); + files.add( Paths.get( FileUtil.getBasedir(), "src/test", TEST_REPO_1, + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ).toFile() ); + files.add( Paths.get( FileUtil.getBasedir(), "src/test", TEST_REPO_1, + "org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ).toFile() ); createIndex( TEST_REPO_1, files, scan ); } @@ -286,7 +290,7 @@ public class MavenRepositorySearchTest archivaConfigControl.replay(); - SearchResults results = search.search( "user", selectedRepos, "org", limits, new ArrayList<String>() ); + SearchResults results = search.search( "user", selectedRepos, "org", limits, Collections.<String>emptyList() ); archivaConfigControl.verify(); |