1 package org.apache.archiva.consumers.core;
3 import org.apache.archiva.admin.model.beans.ManagedRepository;
4 import org.apache.archiva.checksum.ChecksumAlgorithm;
5 import org.apache.archiva.checksum.ChecksummedFile;
6 import org.apache.commons.io.FileUtils;
7 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
8 import org.junit.Before;
12 import java.util.Calendar;
15 * Licensed to the Apache Software Foundation (ASF) under one
16 * or more contributor license agreements. See the NOTICE file
17 * distributed with this work for additional information
18 * regarding copyright ownership. The ASF licenses this file
19 * to you under the Apache License, Version 2.0 (the
20 * "License"); you may not use this file except in compliance
21 * with the License. You may obtain a copy of the License at
23 * http://www.apache.org/licenses/LICENSE-2.0
25 * Unless required by applicable law or agreed to in writing,
26 * software distributed under the License is distributed on an
27 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
28 * KIND, either express or implied. See the License for the
29 * specific language governing permissions and limitations
33 public class ArtifactMissingChecksumsConsumerTest
34 extends AbstractArtifactConsumerTest
36 private ManagedRepository repoConfig;
44 repoConfig = new ManagedRepository();
45 repoConfig.setId( "test-repo" );
46 repoConfig.setName( "Test Repository" );
47 repoConfig.setLayout( "default" );
48 repoConfig.setLocation( new File( "target/test-classes/test-repo/" ).getPath() );
50 consumer = applicationContext.getBean( "knownRepositoryContentConsumer#create-missing-checksums",
51 KnownRepositoryContentConsumer.class );
55 public void testNoExistingChecksums()
58 String path = "/no-checksums-artifact/1.0/no-checksums-artifact-1.0.jar";
60 File sha1File = new File( repoConfig.getLocation(), path + ".sha1" );
61 File md5File = new File( repoConfig.getLocation(), path + ".md5" );
66 assertFalse( sha1File.exists() );
67 assertFalse( md5File.exists() );
69 consumer.beginScan( repoConfig, Calendar.getInstance().getTime() );
71 consumer.processFile( path );
73 assertTrue( sha1File.exists() );
74 assertTrue( md5File.exists() );
78 public void testExistingIncorrectChecksums()
81 File newLocation = new File( "target/test-repo" );
82 FileUtils.deleteDirectory( newLocation );
83 FileUtils.copyDirectory( new File( repoConfig.getLocation() ), newLocation );
84 repoConfig.setLocation( newLocation.getAbsolutePath() );
86 String path = "/incorrect-checksums/1.0/incorrect-checksums-1.0.jar";
88 File sha1File = new File( repoConfig.getLocation(), path + ".sha1" );
89 File md5File = new File( repoConfig.getLocation(), path + ".md5" );
91 ChecksummedFile checksum = new ChecksummedFile( new File( repoConfig.getLocation(), path ) );
93 assertTrue( sha1File.exists() );
94 assertTrue( md5File.exists() );
95 assertFalse( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) );
97 consumer.beginScan( repoConfig, Calendar.getInstance().getTime() );
99 consumer.processFile( path );
101 assertTrue( sha1File.exists() );
102 assertTrue( md5File.exists() );
103 assertTrue( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) );