aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaria Odea B. Ching <oching@apache.org>2009-02-05 09:00:31 +0000
committerMaria Odea B. Ching <oching@apache.org>2009-02-05 09:00:31 +0000
commit8cbe20762768d23be58fa19b00a4e5a7983d5646 (patch)
tree5682bdb2645481404d927b12891aa4432f130960
parentc9cdca72bbfa747d0e296357988debaf9e1531d3 (diff)
downloadarchiva-8cbe20762768d23be58fa19b00a4e5a7983d5646.tar.gz
archiva-8cbe20762768d23be58fa19b00a4e5a7983d5646.zip
[MRM-1046]
o added test cases for SearchActionTest git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@741051 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java45
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java219
2 files changed, 259 insertions, 5 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
index a4acd865d..652d0d467 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
@@ -297,13 +297,18 @@ public class SearchAction
//Lets get the versions for the artifact we just found and display them
//Yes, this is in the lucene index but its more challenging to get them out when we are searching by project
- for (SearchResultHit resultHit : results.getHits())
+
+ // TODO: do we still need to do this? all hits are already filtered in the NexusRepositorySearch
+ // before being returned as search results
+ for ( SearchResultHit resultHit : results.getHits() )
{
- final List<String> versions = dao.query(new UniqueVersionConstraint(getObservableRepos(), resultHit.getGroupId(), resultHit.getArtifactId()));
- if (versions != null && !versions.isEmpty())
+ final List<String> versions =
+ dao.query( new UniqueVersionConstraint( getObservableRepos(), resultHit.getGroupId(),
+ resultHit.getArtifactId() ) );
+ if ( versions != null && !versions.isEmpty() )
{
- resultHit.setVersion(null);
- resultHit.setVersions(filterTimestampedSnapshots(versions));
+ resultHit.setVersion( null );
+ resultHit.setVersions( filterTimestampedSnapshots( versions ) );
}
}
@@ -602,4 +607,34 @@ public class SearchAction
{
this.nexusSearch = nexusSearch;
}
+
+ public ArchivaDAO getDao()
+ {
+ return dao;
+ }
+
+ public void setDao( ArchivaDAO dao )
+ {
+ this.dao = dao;
+ }
+
+ public UserRepositories getUserRepositories()
+ {
+ return userRepositories;
+ }
+
+ public void setUserRepositories( UserRepositories userRepositories )
+ {
+ this.userRepositories = userRepositories;
+ }
+
+ public ArchivaXworkUser getArchivaXworkUser()
+ {
+ return archivaXworkUser;
+ }
+
+ public void setArchivaXworkUser( ArchivaXworkUser archivaXworkUser )
+ {
+ this.archivaXworkUser = archivaXworkUser;
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java
new file mode 100644
index 000000000..617ca3b24
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java
@@ -0,0 +1,219 @@
+package org.apache.maven.archiva.web.action;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.archiva.indexer.search.RepositorySearch;
+import org.apache.archiva.indexer.util.SearchUtil;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
+import org.apache.maven.archiva.indexer.search.SearchResultHit;
+import org.apache.maven.archiva.indexer.search.SearchResultLimits;
+import org.apache.maven.archiva.indexer.search.SearchResults;
+import org.apache.maven.archiva.security.ArchivaXworkUser;
+import org.apache.maven.archiva.security.UserRepositories;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
+import org.easymock.classextension.MockClassControl;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ *
+ */
+public class SearchActionTest
+ extends PlexusInSpringTestCase
+{
+ private SearchAction action;
+
+ private MockControl archivaConfigControl;
+
+ private ArchivaConfiguration archivaConfig;
+
+ private MockControl daoControl;
+
+ private ArchivaDAO dao;
+
+ private MockControl userReposControl;
+
+ private UserRepositories userRepos;
+
+ private MockControl archivaXworkUserControl;
+
+ private ArchivaXworkUser archivaXworkUser;
+
+ private MockControl searchControl;
+
+ private RepositorySearch search;
+
+ @Override
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ action = new SearchAction();
+
+ archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
+
+ archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock();
+
+ daoControl = MockControl.createControl( ArchivaDAO.class );
+ daoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+
+ dao = ( ArchivaDAO ) daoControl.getMock();
+
+ userReposControl = MockControl.createControl( UserRepositories.class );
+
+ userRepos = ( UserRepositories ) userReposControl.getMock();
+
+ archivaXworkUserControl = MockClassControl.createControl( ArchivaXworkUser.class );
+ archivaXworkUserControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+
+ archivaXworkUser = ( ArchivaXworkUser ) archivaXworkUserControl.getMock();
+
+ searchControl = MockControl.createControl( RepositorySearch.class );
+ searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+
+ search = ( RepositorySearch ) searchControl.getMock();
+
+ action.setArchivaConfiguration( archivaConfig );
+ action.setArchivaXworkUser( archivaXworkUser );
+ action.setUserRepositories( userRepos );
+ action.setDao( dao );
+ action.setNexusSearch( search );
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ }
+
+ public void testQuickSearch()
+ throws Exception
+ {
+ action.setQ( "archiva" );
+ action.setCurrentPage( 0 );
+ action.setSearchResultsOnly( false );
+ action.setCompleteQueryString( "" );
+
+ List<String> selectedRepos = new ArrayList<String>();
+ selectedRepos.add( "internal" );
+ selectedRepos.add( "snapshots" );
+
+ SearchResultLimits limits = new SearchResultLimits( action.getCurrentPage() );
+ limits.setPageSize( 30 );
+
+ SearchResultHit hit = new SearchResultHit();
+ hit.setGroupId( "org.apache.archiva" );
+ hit.setArtifactId( "archiva-configuration" );
+ hit.setUrl( "url" );
+ hit.addVersion( "1.0" );
+ hit.addVersion( "1.1" );
+
+ SearchResults results = new SearchResults();
+ results.setLimits( limits );
+ results.setTotalHits( 1 );
+ results.addHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-configuration" ), hit );
+
+ List<String> versions = new ArrayList<String>();
+ versions.add( "1.0" );
+ versions.add( "1.1" );
+
+ archivaXworkUserControl.expectAndReturn( archivaXworkUser.getActivePrincipal( new HashMap() ), "user", 3 );
+
+ userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos, 2 );
+
+ searchControl.expectAndReturn( search.search( "user", selectedRepos, "archiva", limits, null ), results );
+
+ daoControl.expectAndReturn( dao.query( new UniqueVersionConstraint( selectedRepos, hit.getGroupId(), hit.getArtifactId() ) ), versions );
+
+ archivaXworkUserControl.replay();
+ userReposControl.replay();
+ searchControl.replay();
+ daoControl.replay();
+
+ String result = action.quickSearch();
+
+ assertEquals( Action.SUCCESS, result );
+
+ archivaXworkUserControl.verify();
+ userReposControl.verify();
+ searchControl.verify();
+ daoControl.verify();
+ }
+
+ public void testSearchWithinSearchResults()
+ throws Exception
+ {
+ // test filter of completeQueryString?
+ // test no need to filter completeQueryString?
+ }
+
+ public void testAdvancedSearch()
+ throws Exception
+ {
+
+ }
+
+ public void testSearchUserHasNoAccessToAnyRepository()
+ throws Exception
+ {
+
+ }
+
+ public void testNoSearchHits()
+ throws Exception
+ {
+
+ }
+
+ // test pagination or just totalPages?
+ public void testPagination()
+ throws Exception
+ {
+
+ }
+
+ public void testFindArtifactWithOneHit()
+ throws Exception
+ {
+
+ }
+
+ public void testFindArtifactWithMultipleHits()
+ throws Exception
+ {
+
+ }
+
+ public void testFindArtifactNoChecksumSpecified()
+ throws Exception
+ {
+
+ }
+
+}