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;
26 import org.apache.maven.archiva.model.ArchivaProjectModel;
28 import java.util.ArrayList;
29 import java.util.Date;
30 import java.util.List;
33 * RepositoryBrowsingTest
37 public class RepositoryBrowsingTest
38 extends AbstractArchivaDatabaseTestCase
40 private static final List<String> GUEST_REPO_IDS;
42 private static final String USER_GUEST = "guest";
46 GUEST_REPO_IDS = new ArrayList<String>();
47 GUEST_REPO_IDS.add( "central" );
48 GUEST_REPO_IDS.add( "snapshots" );
51 private ArtifactDAO artifactDao;
53 public ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
55 ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar", "central" );
56 artifact.getModel().setLastModified( new Date() ); // mandatory field.
57 artifact.getModel().setRepositoryId( "central" );
61 public RepositoryBrowsing lookupBrowser()
64 RepositoryBrowsing browser = (RepositoryBrowsing) lookup( RepositoryBrowsing.class );
65 assertNotNull( "RepositoryBrowsing should not be null.", browser );
69 public void saveTestData()
72 ArchivaArtifact artifact;
74 // Setup artifacts in fresh DB.
75 artifact = createArtifact( "commons-lang", "commons-lang", "2.0" );
76 artifactDao.saveArtifact( artifact );
78 artifact = createArtifact( "commons-lang", "commons-lang", "2.1" );
79 artifactDao.saveArtifact( artifact );
81 artifact = createArtifact( "org.apache.maven.test", "test-one", "1.2" );
82 artifactDao.saveArtifact( artifact );
84 artifact = createArtifact( "org.apache.maven.test.foo", "test-two", "1.0" );
85 artifactDao.saveArtifact( artifact );
87 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.0" );
88 artifactDao.saveArtifact( artifact );
90 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-SNAPSHOT" );
91 artifactDao.saveArtifact( artifact );
93 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-20070522.143249-1" );
94 artifactDao.saveArtifact( artifact );
96 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-20070522.153141-2" );
97 artifactDao.saveArtifact( artifact );
99 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1.1" );
100 artifactDao.saveArtifact( artifact );
102 artifact = createArtifact( "org.apache.maven.shared", "test-two", "2.1-alpha-1" );
103 artifactDao.saveArtifact( artifact );
105 artifact = createArtifact( "org.apache.maven.shared", "test-bar", "2.1" );
106 artifactDao.saveArtifact( artifact );
108 artifact = createArtifact( "org.codehaus.modello", "modellong", "3.0" );
109 artifactDao.saveArtifact( artifact );
112 public void testBrowseIntoGroupWithSubgroups()
117 RepositoryBrowsing browser = lookupBrowser();
118 BrowsingResults results = browser.selectGroupId( USER_GUEST, GUEST_REPO_IDS, "org.apache.maven.test" );
119 assertNotNull( "Browsing Results should not be null.", results );
121 String expectedSubGroupIds[] = new String[] { "org.apache.maven.test.foo" };
122 assertGroupIds( "Browsing Results (subgroup org.apache.maven.test)", results.getGroupIds(), expectedSubGroupIds );
125 public void testSimpleBrowse()
130 RepositoryBrowsing browser = lookupBrowser();
131 BrowsingResults results = browser.getRoot( USER_GUEST, GUEST_REPO_IDS );
132 assertNotNull( "Browsing Results should not be null.", results );
134 String expectedRootGroupIds[] = new String[] { "commons-lang", "org" };
136 assertGroupIds( "Browsing Results (root)", results.getGroupIds(), expectedRootGroupIds );
139 public void testViewArtifact()
144 RepositoryBrowsing browser = lookupBrowser();
145 ArchivaProjectModel artifact = browser.selectVersion( USER_GUEST, GUEST_REPO_IDS, "org.apache.commons", "commons-lang", "2.0" );
146 assertNotNull( "Artifact should not be null.", artifact );
147 assertEquals( "org.apache.commons", artifact.getGroupId() );
148 assertEquals( "commons-lang", artifact.getArtifactId() );
149 assertEquals( "2.0", artifact.getVersion() );
152 public void testSelectArtifactId()
157 RepositoryBrowsing browser = lookupBrowser();
158 BrowsingResults results =
159 browser.selectArtifactId( USER_GUEST, GUEST_REPO_IDS, "org.apache.maven.shared", "test-two" );
160 assertNotNull( "Browsing results should not be null.", results );
161 assertEquals( 4, results.getVersions().size() );
162 assertTrue( results.getVersions().contains( "2.0" ) );
163 assertTrue( results.getVersions().contains( "2.1-SNAPSHOT" ) );
164 assertTrue( results.getVersions().contains( "2.1.1" ) );
165 assertTrue( results.getVersions().contains( "2.1-alpha-1" ) );
168 public void testGetOtherSnapshotVersionsRequestedVersionIsGeneric()
173 RepositoryBrowsing browser = lookupBrowser();
174 List<String> results =
175 browser.getOtherSnapshotVersions( GUEST_REPO_IDS, "org.apache.maven.shared", "test-two", "2.1-SNAPSHOT" );
176 assertNotNull( "Returned list of versions should not be null.", results );
177 assertEquals( 3, results.size() );
178 assertTrue( results.contains( "2.1-SNAPSHOT" ) );
179 assertTrue( results.contains( "2.1-20070522.143249-1" ) );
180 assertTrue( results.contains( "2.1-20070522.153141-2" ) );
183 public void testGetOtherSnapshotVersionsRequestedVersionIsUnique()
188 RepositoryBrowsing browser = lookupBrowser();
189 List<String> results =
190 browser.getOtherSnapshotVersions( GUEST_REPO_IDS, "org.apache.maven.shared", "test-two", "2.1-20070522.143249-1" );
191 assertNotNull( "Returned list of versions should not be null.", results );
192 assertEquals( 3, results.size() );
193 assertTrue( results.contains( "2.1-SNAPSHOT" ) );
194 assertTrue( results.contains( "2.1-20070522.143249-1" ) );
195 assertTrue( results.contains( "2.1-20070522.153141-2" ) );
198 private void assertGroupIds( String msg, List actualGroupIds, String[] expectedGroupIds )
200 assertEquals( msg + ": groupIds.length", expectedGroupIds.length, actualGroupIds.size() );
202 for ( int i = 0; i < expectedGroupIds.length; i++ )
204 String expectedGroupId = expectedGroupIds[i];
205 assertTrue( msg + ": actual groupIds.contains(" + expectedGroupId + ")", actualGroupIds
206 .contains( expectedGroupId ) );
211 protected void setUp()
216 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
217 artifactDao = dao.getArtifactDAO();