1 package org.apache.maven.archiva.database.browsing;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
23 import org.apache.maven.archiva.database.ArchivaDAO;
24 import org.apache.maven.archiva.database.ArtifactDAO;
25 import org.apache.maven.archiva.model.ArchivaArtifact;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.List;
32 * RepositoryBrowsingTest
36 public class RepositoryBrowsingTest
37 extends AbstractArchivaDatabaseTestCase
39 private static final List<String> GUEST_REPO_IDS;
41 private static final String USER_GUEST = "guest";
45 GUEST_REPO_IDS = new ArrayList<String>();
46 GUEST_REPO_IDS.add( "central" );
47 GUEST_REPO_IDS.add( "snapshots" );
50 private ArtifactDAO artifactDao;
52 public ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
54 ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar", "central" );
55 artifact.getModel().setLastModified( new Date() ); // mandatory field.
56 artifact.getModel().setRepositoryId( "central" );
60 public RepositoryBrowsing lookupBrowser()
63 RepositoryBrowsing browser = (RepositoryBrowsing) lookup( RepositoryBrowsing.class );
64 assertNotNull( "RepositoryBrowsing should not be null.", browser );
68 public void saveTestData()
71 ArchivaArtifact artifact;
73 // Setup artifacts in fresh DB.
74 artifact = createArtifact( "commons-lang", "commons-lang", "2.0" );
75 artifactDao.saveArtifact( artifact );
77 artifact = createArtifact( "commons-lang", "commons-lang", "2.1" );
78 artifactDao.saveArtifact( artifact );
80 artifact = createArtifact( "org.apache.maven.test", "test-one", "1.2" );
81 artifactDao.saveArtifact( artifact );
83 artifact = createArtifact( "org.apache.maven.test.foo", "test-two", "1.0" );
84 artifactDao.saveArtifact( artifact );
86 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.0" );
87 artifactDao.saveArtifact( artifact );
89 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-SNAPSHOT" );
90 artifactDao.saveArtifact( artifact );
92 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1.1" );
93 artifactDao.saveArtifact( artifact );
95 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-alpha-1" );
96 artifactDao.saveArtifact( artifact );
98 artifact = createArtifact( "org.apache.maven.shared", "test-bar", "2.1" );
99 artifactDao.saveArtifact( artifact );
101 artifact = createArtifact( "org.codehaus.modello", "modellong", "3.0" );
102 artifactDao.saveArtifact( artifact );
105 public void testBrowseIntoGroupWithSubgroups()
110 RepositoryBrowsing browser = lookupBrowser();
111 BrowsingResults results = browser.selectGroupId( USER_GUEST, GUEST_REPO_IDS, "org.apache.maven.test" );
112 assertNotNull( "Browsing Results should not be null.", results );
114 String expectedSubGroupIds[] = new String[] { "org.apache.maven.test.foo" };
115 assertGroupIds( "Browsing Results (subgroup org.apache.maven.test)", results.getGroupIds(), expectedSubGroupIds );
118 public void testSimpleBrowse()
123 RepositoryBrowsing browser = lookupBrowser();
124 BrowsingResults results = browser.getRoot( USER_GUEST, GUEST_REPO_IDS );
125 assertNotNull( "Browsing Results should not be null.", results );
127 String expectedRootGroupIds[] = new String[] { "commons-lang", "org" };
129 assertGroupIds( "Browsing Results (root)", results.getGroupIds(), expectedRootGroupIds );
132 private void assertGroupIds( String msg, List actualGroupIds, String[] expectedGroupIds )
134 assertEquals( msg + ": groupIds.length", expectedGroupIds.length, actualGroupIds.size() );
136 for ( int i = 0; i < expectedGroupIds.length; i++ )
138 String expectedGroupId = expectedGroupIds[i];
139 assertTrue( msg + ": actual groupIds.contains(" + expectedGroupId + ")", actualGroupIds
140 .contains( expectedGroupId ) );
145 protected void setUp()
150 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
151 artifactDao = dao.getArtifactDAO();