From 25c9aa2a6f9ee420e018f0c1214a32bf3411f4db Mon Sep 17 00:00:00 2001 From: "Marecor M. Baclay" Date: Fri, 2 Jul 2010 08:02:35 +0000 Subject: [PATCH] [MRM-1230] Type of artifact is always "pom" - additional unit test (modified the patch since it has not been applied in 1.3 as set in the fixed version) Submitted by: Maria Catherine Tan git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@959907 13f79535-47bb-0310-9956-ffa450edef68 --- .../services/SearchServiceImplTest.java | 116 +++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java index 654e8237a..ad50cd2ba 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java @@ -34,6 +34,7 @@ import org.apache.archiva.web.xmlrpc.api.beans.Artifact; import org.apache.archiva.web.xmlrpc.api.beans.Dependency; import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories; import org.apache.maven.archiva.database.ArchivaDAO; +import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.database.browsing.BrowsingResults; @@ -45,6 +46,7 @@ import org.apache.maven.archiva.model.ArchivaProjectModel; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; import org.easymock.classextension.MockClassControl; +import org.slf4j.Logger; /** * SearchServiceImplTest @@ -76,6 +78,10 @@ public class SearchServiceImplTest private RepositoryBrowsing repoBrowsing; + private MockControl loggerControl; + + private Logger logger; + private static final String ARCHIVA_TEST_ARTIFACT_ID = "archiva-xmlrpc-test"; private static final String ARCHIVA_TEST_GROUP_ID = "org.apache.archiva"; @@ -102,6 +108,10 @@ public class SearchServiceImplTest artifactDAOControl = MockControl.createControl( ArtifactDAO.class ); artifactDAO = ( ArtifactDAO ) artifactDAOControl.getMock(); + + loggerControl = MockControl.createControl( Logger.class ); + logger = ( Logger ) loggerControl.getMock(); + } // MRM-1230 @@ -224,6 +234,110 @@ public class SearchServiceImplTest assertEquals( "jar", artifact.getType() ); assertNull( "Repository should be null since the model was not found in the database!", artifact.getRepositoryId() ); } + + public void testQuickSearchArtifactObjectNotFoundException() + throws Exception + { + List observableRepoIds = new ArrayList(); + observableRepoIds.add( "repo1.mirror" ); + + userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); + + SearchResults results = new SearchResults(); + List versions = new ArrayList(); + versions.add( "1.0" ); + + SearchResultHit resultHit = new SearchResultHit(); + resultHit.setRepositoryId( "repo1.mirror" ); + resultHit.setGroupId( "org.apache.archiva" ); + resultHit.setArtifactId( "archiva-test" ); + resultHit.setVersions( versions ); + + results.addHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-test" ), resultHit ); + + SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); + + searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results ); + + archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), + resultHit.getArtifactId() ) ), null ); + + ObjectNotFoundException exception = new ObjectNotFoundException( "org.apache.archiva.archiva-test:1.0" ); + + repoBrowsingControl.expectAndThrow( repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), exception ); + + logger.debug( "Unable to find pom artifact : " + exception.getMessage() ); + loggerControl.setDefaultVoidCallable(); + + userReposControl.replay(); + searchControl.replay(); + repoBrowsingControl.replay(); + archivaDAOControl.replay(); + loggerControl.replay(); + + List artifacts = searchService.quickSearch( "archiva" ); + + userReposControl.verify(); + searchControl.verify(); + repoBrowsingControl.verify(); + archivaDAOControl.verify(); + loggerControl.verify(); + + assertNotNull( artifacts ); + assertEquals( 0, artifacts.size() ); + } + + public void testQuickSearchArtifactArchivaDatabaseException() + throws Exception + { + List observableRepoIds = new ArrayList(); + observableRepoIds.add( "repo1.mirror" ); + + userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); + + SearchResults results = new SearchResults(); + List versions = new ArrayList(); + versions.add( "1.0" ); + + SearchResultHit resultHit = new SearchResultHit(); + resultHit.setRepositoryId( "repo1.mirror" ); + resultHit.setGroupId( "org.apache.archiva" ); + resultHit.setArtifactId( "archiva-test" ); + resultHit.setVersions( versions ); + + results.addHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-test" ), resultHit ); + + SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); + + searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results ); + + archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), + resultHit.getArtifactId() ) ), null ); + + ArchivaDatabaseException exception = new ArchivaDatabaseException( "org.apache.archiva.archiva-test:1.0" ); + + repoBrowsingControl.expectAndThrow( repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), exception ); + + logger.debug( "Error occurred while getting pom artifact from database : " + exception.getMessage() ); + loggerControl.setDefaultVoidCallable(); + + userReposControl.replay(); + searchControl.replay(); + repoBrowsingControl.replay(); + archivaDAOControl.replay(); + loggerControl.replay(); + + List artifacts = searchService.quickSearch( "archiva" ); + + userReposControl.verify(); + searchControl.verify(); + repoBrowsingControl.verify(); + archivaDAOControl.verify(); + loggerControl.verify(); + + assertNotNull( artifacts ); + assertEquals( 0, artifacts.size() ); + } /* * quick/general text search which returns a list of artifacts @@ -662,4 +776,4 @@ public class SearchServiceImplTest userReposControl.verify(); } } -} \ No newline at end of file +} -- 2.39.5