mirror of https://github.com/apache/archiva.git
[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:
parent
7db9b8b693
commit
66fa6ce2c3
|
@ -19,6 +19,9 @@ package org.apache.maven.archiva.database.browsing;
|
|||
* 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.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
|
@ -69,14 +72,11 @@ public class DefaultRepositoryBrowsing
|
|||
|
||||
public BrowsingResults selectArtifactId( String groupId, String artifactId )
|
||||
{
|
||||
// List groups = dao.query( new UniqueGroupIdConstraint( groupId ) );
|
||||
// List artifacts = dao.query( new UniqueArtifactIdConstraint( groupId ) );
|
||||
// NOTE: No group Id or artifact Id's should be returned here.
|
||||
List versions = dao.query( new UniqueVersionConstraint( groupId, artifactId ) );
|
||||
|
||||
BrowsingResults results = new BrowsingResults( groupId, artifactId );
|
||||
|
||||
// results.setGroupIds( groups );
|
||||
// results.setArtifacts( artifacts );
|
||||
results.setVersions( versions );
|
||||
|
||||
return results;
|
||||
|
@ -88,6 +88,11 @@ public class DefaultRepositoryBrowsing
|
|||
List artifacts = dao.query( new UniqueArtifactIdConstraint( 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.setArtifacts( artifacts );
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.maven.archiva.database.ArtifactDAO;
|
|||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RepositoryBrowsingTest
|
||||
|
@ -37,15 +38,6 @@ public class RepositoryBrowsingTest
|
|||
{
|
||||
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 )
|
||||
{
|
||||
ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar" );
|
||||
|
@ -54,6 +46,14 @@ public class RepositoryBrowsingTest
|
|||
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()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -91,12 +91,17 @@ public class RepositoryBrowsingTest
|
|||
artifactDao.saveArtifact( artifact );
|
||||
}
|
||||
|
||||
public RepositoryBrowsing lookupBrowser()
|
||||
public void testBrowseIntoGroupWithSubgroups()
|
||||
throws Exception
|
||||
{
|
||||
RepositoryBrowsing browser = (RepositoryBrowsing) lookup( RepositoryBrowsing.class.getName() );
|
||||
assertNotNull( "RepositoryBrowsing should not be null.", browser );
|
||||
return browser;
|
||||
saveTestData();
|
||||
|
||||
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()
|
||||
|
@ -110,6 +115,27 @@ public class RepositoryBrowsingTest
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue