1 package org.apache.maven.archiva.database.constraints;
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 java.util.Calendar;
23 import java.util.Date;
24 import java.util.List;
26 import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
27 import org.apache.maven.archiva.database.ArchivaDAO;
28 import org.apache.maven.archiva.database.ArtifactDAO;
29 import org.apache.maven.archiva.model.ArchivaArtifact;
32 * ArtifactVersionsConstraintTest
34 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
37 public class ArtifactVersionsConstraintTest
38 extends AbstractArchivaDatabaseTestCase
40 private ArtifactDAO artifactDao;
42 public static final String TEST_REPO = "test-repo";
49 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
50 artifactDao = dao.getArtifactDAO();
53 private ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
55 ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, null, "jar" );
56 artifact.getModel().setLastModified( new Date() );
57 artifact.getModel().setRepositoryId( TEST_REPO );
62 private void populateDb()
65 Date whenGathered = Calendar.getInstance().getTime();
66 whenGathered.setTime( 123456789 );
68 ArchivaArtifact artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0" );
69 artifact.getModel().setWhenGathered( null );
70 artifactDao.saveArtifact( artifact );
72 artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.1" );
73 artifact.getModel().setWhenGathered( whenGathered );
74 artifactDao.saveArtifact( artifact );
76 artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.2" );
77 artifact.getModel().setWhenGathered( whenGathered );
78 artifactDao.saveArtifact( artifact );
80 artifact = createArtifact( "org.apache.archiva", "artifact-one", "2.0" );
81 artifact.getModel().setRepositoryId( "different-repo" );
82 artifact.getModel().setWhenGathered( whenGathered );
83 artifactDao.saveArtifact( artifact );
86 public void testQueryAllVersionsOfArtifactAcrossRepos() throws Exception
89 assertConstraint( "Artifacts By Repository", 3,
90 new ArtifactVersionsConstraint( null, "org.apache.archiva", "artifact-one" ) );
93 public void testQueryAllVersionsOfArtifactInARepo() throws Exception
96 assertConstraint( "Artifacts By Repository", 2,
97 new ArtifactVersionsConstraint( TEST_REPO, "org.apache.archiva", "artifact-one" ) );
100 private void assertConstraint( String msg, int count, ArtifactVersionsConstraint constraint )
103 List<ArchivaArtifact> results = artifactDao.queryArtifacts( constraint );
104 assertNotNull( msg + ": Not Null", results );
105 assertEquals( msg + ": Results.size", count, results.size() );