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 org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
23 import org.apache.maven.archiva.database.ArtifactDAO;
24 import org.apache.maven.archiva.database.ArchivaDAO;
25 import org.apache.maven.archiva.model.ArchivaArtifact;
27 import java.util.Date;
28 import java.util.List;
31 * ArtifactsByChecksumConstraintTest
35 public class ArtifactsByChecksumConstraintTest
36 extends AbstractArchivaDatabaseTestCase
38 private static final String SHA1_HASH3 = "f3f653289f3217c65324830ab3415bc92feddefa";
40 private static final String SHA1_HASH2 = "a49810ad3eba8651677ab57cd40a0f76fdef9538";
42 private static final String SHA1_HASH1 = "232f01b24b1617c46a3d4b0ab3415bc9237dcdec";
44 private static final String MD5_HASH3 = "5440efd724c9a5246ddc148662a4f20a";
46 private static final String MD5_HASH2 = "4685525525d82dea68c6a6cd5a08f726";
48 private static final String MD5_HASH1 = "53e3b856aa1a3f3cb7fe0f7ac6163aaf";
50 private ArtifactDAO artifactDao;
53 protected void setUp()
58 ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
59 artifactDao = dao.getArtifactDAO();
62 public ArchivaArtifact createArtifact( String artifactId, String version )
64 ArchivaArtifact artifact =
65 artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version, "", "jar", "testable_repo" );
66 artifact.getModel().setLastModified( new Date() );
67 artifact.getModel().setRepositoryId( "testable_repo" );
71 public void testConstraintSHA1()
74 ArchivaArtifact artifact;
76 // Setup artifacts in fresh DB.
77 artifact = createArtifact( "test-sha1-one", "1.0" );
78 artifact.getModel().setChecksumSHA1( SHA1_HASH1 );
79 artifactDao.saveArtifact( artifact );
81 artifact = createArtifact( "test-sha1-one", "1.1" );
82 artifact.getModel().setChecksumSHA1( SHA1_HASH1 );
83 artifactDao.saveArtifact( artifact );
85 artifact = createArtifact( "test-sha1-one", "1.2" );
86 artifact.getModel().setChecksumSHA1( SHA1_HASH1 );
87 artifactDao.saveArtifact( artifact );
89 artifact = createArtifact( "test-sha1-two", "1.0" );
90 artifact.getModel().setChecksumSHA1( SHA1_HASH1 );
91 artifactDao.saveArtifact( artifact );
93 artifact = createArtifact( "test-sha1-two", "2.0" );
94 artifact.getModel().setChecksumSHA1( SHA1_HASH3 );
95 artifactDao.saveArtifact( artifact );
97 artifact = createArtifact( "test-sha1-two", "2.1" );
98 artifact.getModel().setChecksumSHA1( SHA1_HASH2 );
99 artifactDao.saveArtifact( artifact );
101 artifact = createArtifact( "test-sha1-two", "3.0" );
102 artifact.getModel().setChecksumSHA1( SHA1_HASH2 );
103 artifactDao.saveArtifact( artifact );
105 assertConstraint( "Artifacts by SHA1 Checksum", 4,
106 new ArtifactsByChecksumConstraint( SHA1_HASH1, ArtifactsByChecksumConstraint.SHA1 ) );
107 assertConstraint( "Artifacts by SHA1 Checksum", 2,
108 new ArtifactsByChecksumConstraint( SHA1_HASH2, ArtifactsByChecksumConstraint.SHA1 ) );
109 assertConstraint( "Artifacts by SHA1 Checksum", 1,
110 new ArtifactsByChecksumConstraint( SHA1_HASH3, ArtifactsByChecksumConstraint.SHA1 ) );
113 public void testConstraintMD5()
116 ArchivaArtifact artifact;
118 artifact = createArtifact( "test-md5-one", "1.0" );
119 artifact.getModel().setChecksumMD5( MD5_HASH1 );
120 artifactDao.saveArtifact( artifact );
122 artifact = createArtifact( "test-md5-one", "1.1" );
123 artifact.getModel().setChecksumMD5( MD5_HASH1 );
124 artifactDao.saveArtifact( artifact );
126 artifact = createArtifact( "test-md5-one", "1.2" );
127 artifact.getModel().setChecksumMD5( MD5_HASH1 );
128 artifactDao.saveArtifact( artifact );
130 artifact = createArtifact( "test-md5-two", "1.0" );
131 artifact.getModel().setChecksumMD5( MD5_HASH1 );
132 artifactDao.saveArtifact( artifact );
134 artifact = createArtifact( "test-md5-two", "2.0" );
135 artifact.getModel().setChecksumMD5( MD5_HASH3 );
136 artifactDao.saveArtifact( artifact );
138 artifact = createArtifact( "test-md5-two", "2.1" );
139 artifact.getModel().setChecksumMD5( MD5_HASH2 );
140 artifactDao.saveArtifact( artifact );
142 artifact = createArtifact( "test-md5-two", "3.0" );
143 artifact.getModel().setChecksumMD5( MD5_HASH2 );
144 artifactDao.saveArtifact( artifact );
146 assertConstraint( "Artifacts by MD5 Checksum", 4,
147 new ArtifactsByChecksumConstraint( MD5_HASH1, ArtifactsByChecksumConstraint.MD5 ) );
148 assertConstraint( "Artifacts by MD5 Checksum", 2,
149 new ArtifactsByChecksumConstraint( MD5_HASH2, ArtifactsByChecksumConstraint.MD5 ) );
150 assertConstraint( "Artifacts by MD5 Checksum", 1,
151 new ArtifactsByChecksumConstraint( MD5_HASH3, ArtifactsByChecksumConstraint.MD5 ) );
154 public void testConstraintOR()
157 ArchivaArtifact artifact;
159 artifact = createArtifact( "test-one", "1.0" );
160 artifact.getModel().setChecksumMD5( MD5_HASH1 );
161 artifactDao.saveArtifact( artifact );
163 artifact = createArtifact( "test-one", "1.1" );
164 artifact.getModel().setChecksumMD5( MD5_HASH1 );
165 artifactDao.saveArtifact( artifact );
167 artifact = createArtifact( "test-one", "1.2" );
168 artifact.getModel().setChecksumMD5( MD5_HASH1 );
169 artifactDao.saveArtifact( artifact );
171 artifact = createArtifact( "test-two", "1.0" );
172 artifact.getModel().setChecksumMD5( MD5_HASH1 );
173 artifactDao.saveArtifact( artifact );
175 artifact = createArtifact( "test-two", "2.0" );
176 artifact.getModel().setChecksumMD5( MD5_HASH3 );
177 artifactDao.saveArtifact( artifact );
179 artifact = createArtifact( "test-two", "2.1" );
180 artifact.getModel().setChecksumMD5( MD5_HASH2 );
181 artifactDao.saveArtifact( artifact );
183 artifact = createArtifact( "test-two", "3.0" );
184 artifact.getModel().setChecksumMD5( MD5_HASH2 );
185 artifactDao.saveArtifact( artifact );
187 assertConstraint( "Artifacts by MD5 Checksum", 4, new ArtifactsByChecksumConstraint( MD5_HASH1 ) );
188 assertConstraint( "Artifacts by MD5 Checksum", 2, new ArtifactsByChecksumConstraint( MD5_HASH2 ) );
189 assertConstraint( "Artifacts by MD5 Checksum", 1, new ArtifactsByChecksumConstraint( MD5_HASH3 ) );
193 private void assertConstraint( String msg, int count, ArtifactsByChecksumConstraint constraint )
196 List results = artifactDao.queryArtifacts( constraint );
197 assertNotNull( msg + ": Not Null", results );
198 assertEquals( msg + ": Results.size", count, results.size() );