[MRM-1046]

o more tests


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@741444 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2009-02-06 07:15:03 +00:00
parent 2fb9f49983
commit e0d6da5cc6
2 changed files with 125 additions and 27 deletions

View File

@ -33,6 +33,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.Constraint; import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint; import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
import org.apache.maven.archiva.indexer.RepositoryIndexException; import org.apache.maven.archiva.indexer.RepositoryIndexException;
@ -344,7 +345,9 @@ public class SearchAction
} }
Constraint constraint = new ArtifactsByChecksumConstraint( q ); Constraint constraint = new ArtifactsByChecksumConstraint( q );
databaseResults = dao.getArtifactDAO().queryArtifacts( constraint );
ArtifactDAO artifactDao = dao.getArtifactDAO();
databaseResults = artifactDao.queryArtifacts( constraint );
if ( databaseResults.isEmpty() ) if ( databaseResults.isEmpty() )
{ {

View File

@ -28,10 +28,13 @@ import org.apache.archiva.indexer.search.SearchFields;
import org.apache.archiva.indexer.util.SearchUtil; import org.apache.archiva.indexer.util.SearchUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
import org.apache.maven.archiva.indexer.search.SearchResultHit; import org.apache.maven.archiva.indexer.search.SearchResultHit;
import org.apache.maven.archiva.indexer.search.SearchResultLimits; import org.apache.maven.archiva.indexer.search.SearchResultLimits;
import org.apache.maven.archiva.indexer.search.SearchResults; import org.apache.maven.archiva.indexer.search.SearchResults;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.security.ArchivaXworkUser; import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.plexus.spring.PlexusInSpringTestCase;
@ -68,6 +71,10 @@ public class SearchActionTest
private RepositorySearch search; private RepositorySearch search;
private MockControl artifactDaoControl;
private ArtifactDAO artifactDao;
@Override @Override
protected void setUp() protected void setUp()
throws Exception throws Exception
@ -76,17 +83,14 @@ public class SearchActionTest
action = new SearchAction(); action = new SearchAction();
archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock(); archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock();
daoControl = MockControl.createControl( ArchivaDAO.class ); daoControl = MockControl.createControl( ArchivaDAO.class );
daoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); daoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
dao = ( ArchivaDAO ) daoControl.getMock(); dao = ( ArchivaDAO ) daoControl.getMock();
userReposControl = MockControl.createControl( UserRepositories.class ); userReposControl = MockControl.createControl( UserRepositories.class );
userRepos = ( UserRepositories ) userReposControl.getMock(); userRepos = ( UserRepositories ) userReposControl.getMock();
archivaXworkUserControl = MockClassControl.createControl( ArchivaXworkUser.class ); archivaXworkUserControl = MockClassControl.createControl( ArchivaXworkUser.class );
@ -96,9 +100,12 @@ public class SearchActionTest
searchControl = MockControl.createControl( RepositorySearch.class ); searchControl = MockControl.createControl( RepositorySearch.class );
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
search = ( RepositorySearch ) searchControl.getMock(); search = ( RepositorySearch ) searchControl.getMock();
artifactDaoControl = MockControl.createControl( ArtifactDAO.class );
artifactDaoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock();
action.setArchivaConfiguration( archivaConfig ); action.setArchivaConfiguration( archivaConfig );
action.setArchivaXworkUser( archivaXworkUser ); action.setArchivaXworkUser( archivaXworkUser );
action.setUserRepositories( userRepos ); action.setUserRepositories( userRepos );
@ -344,13 +351,6 @@ public class SearchActionTest
searchControl.verify(); searchControl.verify();
} }
// TODO include this?
public void testAdvancedSearchSelectedRepositoryNotInManagedReposList()
throws Exception
{
}
public void testAdvancedSearchAllRepositories() public void testAdvancedSearchAllRepositories()
throws Exception throws Exception
{ {
@ -404,17 +404,46 @@ public class SearchActionTest
searchControl.verify(); searchControl.verify();
userReposControl.verify(); userReposControl.verify();
} }
public void testAdvancedSearchPagination()
throws Exception
{
}
public void testAdvancedSearchNoSearchHits() public void testAdvancedSearchNoSearchHits()
throws Exception throws Exception
{ {
List<String> managedRepos = new ArrayList<String>();
managedRepos.add( "internal" );
managedRepos.add( "snapshots" );
action.setRepositoryId( "internal" );
action.setManagedRepositoryList( managedRepos );
action.setCurrentPage( 0 );
action.setRowCount( 30 );
action.setGroupId( "org" );
SearchResultLimits limits = new SearchResultLimits( action.getCurrentPage() );
limits.setPageSize( 30 );
SearchResults results = new SearchResults();
List<String> selectedRepos = new ArrayList<String>();
selectedRepos.add( "internal" );
selectedRepos.add( "snapshots" );
SearchFields searchFields = new SearchFields( "org", null, null, null, null, selectedRepos );
archivaXworkUserControl.expectAndReturn( archivaXworkUser.getActivePrincipal( new HashMap() ), "user" );
searchControl.expectAndReturn( search.search( "user", searchFields, limits ), results );
archivaXworkUserControl.replay();
searchControl.replay();
String result = action.filteredSearch();
assertEquals( Action.INPUT, result );
assertFalse( action.getActionErrors().isEmpty() );
assertEquals( "No results found",( String ) action.getActionErrors().iterator().next() );
archivaXworkUserControl.verify();
searchControl.verify();
} }
public void testAdvancedSearchUserHasNoAccessToAnyRepository() public void testAdvancedSearchUserHasNoAccessToAnyRepository()
@ -434,19 +463,85 @@ public class SearchActionTest
public void testFindArtifactWithOneHit() public void testFindArtifactWithOneHit()
throws Exception throws Exception
{ {
action.setQ( "afbcdeaadbcffceabbba1" );
List<ArchivaArtifact> dbResults = new ArrayList<ArchivaArtifact>();
dbResults.add( new ArchivaArtifact( "org.apache.archiva", "archiva-configuration", "1.0",
null, "jar" ) );
daoControl.expectAndReturn( dao.getArtifactDAO(), artifactDao );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts( new ArtifactsByChecksumConstraint( action.getQ() ) ), dbResults );
daoControl.replay();
artifactDaoControl.replay();
String result = action.findArtifact();
assertEquals( "artifact", result );
assertFalse( action.getDatabaseResults().isEmpty() );
assertEquals( 1, action.getDatabaseResults().size() );
daoControl.verify();
artifactDaoControl.verify();
} }
public void testFindArtifactWithMultipleHits() public void testFindArtifactWithMultipleHits()
throws Exception throws Exception
{ {
action.setQ( "afbcdeaadbcffceabbba1" );
List<ArchivaArtifact> dbResults = new ArrayList<ArchivaArtifact>();
dbResults.add( new ArchivaArtifact( "org.apache.archiva", "archiva-configuration", "1.0",
null, "jar" ) );
dbResults.add( new ArchivaArtifact( "org.apache.archiva", "archiva-indexer", "1.0",
null, "jar" ) );
daoControl.expectAndReturn( dao.getArtifactDAO(), artifactDao );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts( new ArtifactsByChecksumConstraint( action.getQ() ) ), dbResults );
daoControl.replay();
artifactDaoControl.replay();
String result = action.findArtifact();
assertEquals( "results", result );
assertFalse( action.getDatabaseResults().isEmpty() );
assertEquals( 2, action.getDatabaseResults().size() );
daoControl.verify();
artifactDaoControl.verify();
} }
public void testFindArtifactNoChecksumSpecified() public void testFindArtifactNoChecksumSpecified()
throws Exception throws Exception
{ {
String result = action.findArtifact();
assertEquals( Action.INPUT, result );
assertFalse( action.getActionErrors().isEmpty() );
assertEquals( "Unable to search for a blank checksum", ( String ) action.getActionErrors().iterator().next() );
} }
public void testFindArtifactNoResults()
throws Exception
{
action.setQ( "afbcdeaadbcffceabbba1" );
List<ArchivaArtifact> dbResults = new ArrayList<ArchivaArtifact>();
daoControl.expectAndReturn( dao.getArtifactDAO(), artifactDao );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts( new ArtifactsByChecksumConstraint( action.getQ() ) ), dbResults );
daoControl.replay();
artifactDaoControl.replay();
String result = action.findArtifact();
assertEquals( Action.INPUT, result );
assertFalse( action.getActionErrors().isEmpty() );
assertEquals( "No results found", ( String )action.getActionErrors().iterator().next() );
daoControl.verify();
artifactDaoControl.verify();
}
} }