[MRM-403]: when browsing, groups list incorrect sub-groups

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@549578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-06-21 18:22:48 +00:00
parent 7db9b8b693
commit 66fa6ce2c3
2 changed files with 49 additions and 18 deletions

View File

@ -19,6 +19,9 @@ package org.apache.maven.archiva.database.browsing;
* under the License. * under the License.
*/ */
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.PredicateUtils;
import org.apache.commons.collections.functors.NotPredicate;
import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.database.ObjectNotFoundException;
@ -69,14 +72,11 @@ public class DefaultRepositoryBrowsing
public BrowsingResults selectArtifactId( String groupId, String artifactId ) public BrowsingResults selectArtifactId( String groupId, String artifactId )
{ {
// List groups = dao.query( new UniqueGroupIdConstraint( groupId ) ); // NOTE: No group Id or artifact Id's should be returned here.
// List artifacts = dao.query( new UniqueArtifactIdConstraint( groupId ) );
List versions = dao.query( new UniqueVersionConstraint( groupId, artifactId ) ); List versions = dao.query( new UniqueVersionConstraint( groupId, artifactId ) );
BrowsingResults results = new BrowsingResults( groupId, artifactId ); BrowsingResults results = new BrowsingResults( groupId, artifactId );
// results.setGroupIds( groups );
// results.setArtifacts( artifacts );
results.setVersions( versions ); results.setVersions( versions );
return results; return results;
@ -88,6 +88,11 @@ public class DefaultRepositoryBrowsing
List artifacts = dao.query( new UniqueArtifactIdConstraint( groupId ) ); List artifacts = dao.query( new UniqueArtifactIdConstraint( groupId ) );
BrowsingResults results = new BrowsingResults( groupId ); BrowsingResults results = new BrowsingResults( groupId );
// Remove searched for groupId from groups list.
// Easier to do this here, vs doing it in the SQL query.
CollectionUtils.filter( groups, NotPredicate.getInstance( PredicateUtils.equalPredicate( groupId ) ) );
results.setGroupIds( groups ); results.setGroupIds( groups );
results.setArtifacts( artifacts ); results.setArtifacts( artifacts );

View File

@ -25,6 +25,7 @@ import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifact;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* RepositoryBrowsingTest * RepositoryBrowsingTest
@ -37,15 +38,6 @@ public class RepositoryBrowsingTest
{ {
private ArtifactDAO artifactDao; private ArtifactDAO artifactDao;
protected void setUp()
throws Exception
{
super.setUp();
ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
artifactDao = dao.getArtifactDAO();
}
public ArchivaArtifact createArtifact( String groupId, String artifactId, String version ) public ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
{ {
ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar" ); ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar" );
@ -54,6 +46,14 @@ public class RepositoryBrowsingTest
return artifact; return artifact;
} }
public RepositoryBrowsing lookupBrowser()
throws Exception
{
RepositoryBrowsing browser = (RepositoryBrowsing) lookup( RepositoryBrowsing.class.getName() );
assertNotNull( "RepositoryBrowsing should not be null.", browser );
return browser;
}
public void saveTestData() public void saveTestData()
throws Exception throws Exception
{ {
@ -91,12 +91,17 @@ public class RepositoryBrowsingTest
artifactDao.saveArtifact( artifact ); artifactDao.saveArtifact( artifact );
} }
public RepositoryBrowsing lookupBrowser() public void testBrowseIntoGroupWithSubgroups()
throws Exception throws Exception
{ {
RepositoryBrowsing browser = (RepositoryBrowsing) lookup( RepositoryBrowsing.class.getName() ); saveTestData();
assertNotNull( "RepositoryBrowsing should not be null.", browser );
return browser; RepositoryBrowsing browser = lookupBrowser();
BrowsingResults results = browser.selectGroupId( "org.apache.maven.test" );
assertNotNull( "Browsing Results should not be null.", results );
String expectedSubGroupIds[] = new String[] { "org.apache.maven.test.foo" };
assertGroupIds( "Browsing Results (subgroup org.apache.maven.test)", results.getGroupIds(), expectedSubGroupIds );
} }
public void testSimpleBrowse() public void testSimpleBrowse()
@ -110,6 +115,27 @@ public class RepositoryBrowsingTest
String expectedRootGroupIds[] = new String[] { "commons-lang", "org" }; String expectedRootGroupIds[] = new String[] { "commons-lang", "org" };
assertEquals( "Browsing Results: groupIds on root.", expectedRootGroupIds.length, results.getGroupIds().size() ); assertGroupIds( "Browsing Results (root)", results.getGroupIds(), expectedRootGroupIds );
}
private void assertGroupIds( String msg, List actualGroupIds, String[] expectedGroupIds )
{
assertEquals( msg + ": groupIds.length", expectedGroupIds.length, actualGroupIds.size() );
for ( int i = 0; i < expectedGroupIds.length; i++ )
{
String expectedGroupId = expectedGroupIds[i];
assertTrue( msg + ": actual groupIds.contains(" + expectedGroupId + ")", actualGroupIds
.contains( expectedGroupId ) );
}
}
protected void setUp()
throws Exception
{
super.setUp();
ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
artifactDao = dao.getArtifactDAO();
} }
} }