1 package org.apache.archiva.consumers.core;
4 import java.util.Calendar;
5 import org.apache.archiva.admin.model.beans.ManagedRepository;
6 import org.apache.archiva.checksum.ChecksumAlgorithm;
7 import org.apache.archiva.checksum.ChecksummedFile;
8 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
9 import org.apache.commons.io.FileUtils;
10 import static org.junit.Assert.*;
11 import org.junit.Before;
12 import org.junit.Test;
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;
45 repoConfig = new ManagedRepository();
46 repoConfig.setId( "test-repo" );
47 repoConfig.setName( "Test Repository" );
48 repoConfig.setLayout( "default" );
49 repoConfig.setLocation( new File( "target/test-classes/test-repo/" ).getPath() );
51 consumer = applicationContext.getBean( "knownRepositoryContentConsumer#create-missing-checksums",
52 KnownRepositoryContentConsumer.class );
56 public void testNoExistingChecksums()
59 String path = "/no-checksums-artifact/1.0/no-checksums-artifact-1.0.jar";
61 File sha1File = new File( repoConfig.getLocation(), path + ".sha1" );
62 File md5File = new File( repoConfig.getLocation(), path + ".md5" );
67 assertFalse( sha1File.exists() );
68 assertFalse( md5File.exists() );
70 consumer.beginScan( repoConfig, Calendar.getInstance().getTime() );
72 consumer.processFile( path );
74 assertTrue( sha1File.exists() );
75 assertTrue( md5File.exists() );
79 public void testExistingIncorrectChecksums()
82 File newLocation = new File( "target/test-repo" );
83 FileUtils.deleteDirectory( newLocation );
84 FileUtils.copyDirectory( new File( repoConfig.getLocation() ), newLocation );
85 repoConfig.setLocation( newLocation.getAbsolutePath() );
87 String path = "/incorrect-checksums/1.0/incorrect-checksums-1.0.jar";
89 File sha1File = new File( repoConfig.getLocation(), path + ".sha1" );
90 File md5File = new File( repoConfig.getLocation(), path + ".md5" );
92 ChecksummedFile checksum = new ChecksummedFile( new File( repoConfig.getLocation(), path ) );
94 assertTrue( sha1File.exists() );
95 assertTrue( md5File.exists() );
96 assertFalse( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) );
98 consumer.beginScan( repoConfig, Calendar.getInstance().getTime() );
100 consumer.processFile( path );
102 assertTrue( sha1File.exists() );
103 assertTrue( md5File.exists() );
104 assertTrue( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) );