* 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;
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;
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 );
import org.apache.maven.archiva.model.ArchivaArtifact;
import java.util.Date;
+import java.util.List;
/**
* 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" );
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
{
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()
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();
}
}