]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1230] Type of artifact is always "pom"
authorMarecor M. Baclay <mbaclay@apache.org>
Fri, 2 Jul 2010 08:02:35 +0000 (08:02 +0000)
committerMarecor M. Baclay <mbaclay@apache.org>
Fri, 2 Jul 2010 08:02:35 +0000 (08:02 +0000)
- 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

archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java

index 654e8237a53a23ba2a95304518e92b98e4d8c138..ad50cd2ba729cba080d8ddb07db326910a45a792 100644 (file)
@@ -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<String> observableRepoIds = new ArrayList<String>();
+        observableRepoIds.add( "repo1.mirror" );
+
+        userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
+        
+        SearchResults results = new SearchResults();        
+        List<String> versions = new ArrayList<String>();
+        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<Artifact> 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<String> observableRepoIds = new ArrayList<String>();
+        observableRepoIds.add( "repo1.mirror" );
+
+        userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
+        
+        SearchResults results = new SearchResults();        
+        List<String> versions = new ArrayList<String>();
+        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<Artifact> 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
+}