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 * ArtifactsByRepositoryConstraintTest
34 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
37 public class ArtifactsByRepositoryConstraintTest
38 extends AbstractArchivaDatabaseTestCase
40 private ArtifactDAO artifactDao;
47 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
48 artifactDao = dao.getArtifactDAO();
51 private ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
53 ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, null, "jar" );
54 artifact.getModel().setLastModified( new Date() );
55 artifact.getModel().setRepositoryId( "test-repo" );
60 public void testQueryAllArtifactsInRepo()
63 Date whenGathered = Calendar.getInstance().getTime();
64 whenGathered.setTime( 123456789 );
66 ArchivaArtifact artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0" );
67 artifact.getModel().setWhenGathered( whenGathered );
68 artifactDao.saveArtifact( artifact );
70 artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.1" );
71 artifact.getModel().setWhenGathered( whenGathered );
72 artifactDao.saveArtifact( artifact );
74 artifact = createArtifact( "org.apache.archiva", "artifact-two", "1.0.2" );
75 artifact.getModel().setWhenGathered( whenGathered );
76 artifactDao.saveArtifact( artifact );
78 artifact = createArtifact( "org.apache.archiva", "artifact-one", "2.0" );
79 artifact.getModel().setRepositoryId( "different-repo" );
80 artifact.getModel().setWhenGathered( whenGathered );
81 artifactDao.saveArtifact( artifact );
83 assertConstraint( "Artifacts By Repository", 3, new ArtifactsByRepositoryConstraint( "test-repo" ) );
86 public void testQueryArtifactsInRepoWithWhenGathered()
89 Date whenGathered = Calendar.getInstance().getTime();
91 ArchivaArtifact artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0" );
92 artifact.getModel().setWhenGathered( whenGathered );
93 artifactDao.saveArtifact( artifact );
95 artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.1" );
96 artifact.getModel().setWhenGathered( whenGathered );
97 artifactDao.saveArtifact( artifact );
99 artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.2" );
100 artifact.getModel().setWhenGathered( whenGathered );
101 artifactDao.saveArtifact( artifact );
103 artifact = createArtifact( "org.apache.archiva", "artifact-one", "2.0" );
104 artifact.getModel().setRepositoryId( "different-repo" );
105 artifact.getModel().setWhenGathered( whenGathered );
106 artifactDao.saveArtifact( artifact );
108 artifact = createArtifact( "org.apache.archiva", "artifact-two", "1.1-SNAPSHOT" );
109 artifact.getModel().setWhenGathered( whenGathered );
110 artifactDao.saveArtifact( artifact );
112 artifact = createArtifact( "org.apache.archiva", "artifact-three", "2.0-beta-1" );
113 artifact.getModel().setWhenGathered( whenGathered );
114 artifactDao.saveArtifact( artifact );
116 assertConstraint( "Artifacts By Repository and When Gathered", 5,
117 new ArtifactsByRepositoryConstraint( "test-repo" ) );
120 private void assertConstraint( String msg, int count, ArtifactsByRepositoryConstraint constraint )
123 List results = artifactDao.queryArtifacts( constraint );
124 assertNotNull( msg + ": Not Null", results );
125 assertEquals( msg + ": Results.size", count, results.size() );