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.archiva.consumers.KnownRepositoryContentConsumer;
7 import org.apache.commons.io.FileUtils;
8 import org.assertj.core.api.Assertions;
9 import org.junit.Before;
10 import org.junit.Test;
13 import java.nio.file.Files;
14 import java.nio.file.Path;
15 import java.nio.file.Paths;
16 import java.util.Calendar;
19 * Licensed to the Apache Software Foundation (ASF) under one
20 * or more contributor license agreements. See the NOTICE file
21 * distributed with this work for additional information
22 * regarding copyright ownership. The ASF licenses this file
23 * to you under the Apache License, Version 2.0 (the
24 * "License"); you may not use this file except in compliance
25 * with the License. You may obtain a copy of the License at
27 * http://www.apache.org/licenses/LICENSE-2.0
29 * Unless required by applicable law or agreed to in writing,
30 * software distributed under the License is distributed on an
31 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
32 * KIND, either express or implied. See the License for the
33 * specific language governing permissions and limitations
37 public class ArtifactMissingChecksumsConsumerTest
38 extends AbstractArtifactConsumerTest
40 private ManagedRepository repoConfig;
49 repoConfig = new ManagedRepository();
50 repoConfig.setId( "test-repo" );
51 repoConfig.setName( "Test Repository" );
52 repoConfig.setLayout( "default" );
53 repoConfig.setLocation( new File( "target/test-classes/test-repo/" ).getPath() );
55 consumer = applicationContext.getBean( "knownRepositoryContentConsumer#create-missing-checksums",
56 KnownRepositoryContentConsumer.class );
60 public void testNoExistingChecksums()
63 String path = "/no-checksums-artifact/1.0/no-checksums-artifact-1.0.jar";
65 Path sha1Path = Paths.get( repoConfig.getLocation(),
66 path + ".sha1" );// new File( repoConfig.getLocation(), path + ".sha1" );
68 Paths.get( repoConfig.getLocation(), path + ".md5" );// new File( repoConfig.getLocation(), path + ".md5" );
70 Files.deleteIfExists( sha1Path );
71 Files.deleteIfExists( md5FilePath );
76 Assertions.assertThat( sha1Path.toFile() ).doesNotExist();// assertFalse( sha1File.exists() );
77 Assertions.assertThat( md5FilePath.toFile() ).doesNotExist();// assertFalse( md5File.exists() );
79 consumer.beginScan( repoConfig, Calendar.getInstance().getTime() );
81 consumer.processFile( path );
83 Assertions.assertThat( sha1Path.toFile() ).exists();// assertTrue( sha1File.exists() );
84 Assertions.assertThat( md5FilePath.toFile() ).exists();//assertTrue( md5File.exists() );
88 public void testExistingIncorrectChecksums()
91 File newLocation = new File( "target/test-repo" );
92 FileUtils.deleteDirectory( newLocation );
93 FileUtils.copyDirectory( new File( repoConfig.getLocation() ), newLocation );
94 repoConfig.setLocation( newLocation.getAbsolutePath() );
96 String path = "/incorrect-checksums/1.0/incorrect-checksums-1.0.jar";
98 // new File( repoConfig.getLocation(), path + ".sha1" );
99 Path sha1Path = Paths.get( repoConfig.getLocation(), path + ".sha1" );
101 //new File( repoConfig.getLocation(), path + ".md5" );
102 Path md5Path = Paths.get( repoConfig.getLocation(), path + ".md5" );
104 ChecksummedFile checksum = new ChecksummedFile( new File( repoConfig.getLocation(), path ) );
106 Assertions.assertThat( sha1Path.toFile() ).exists();
107 Assertions.assertThat( md5Path.toFile() ).exists();
108 Assertions.assertThat(
109 checksum.isValidChecksums( new ChecksumAlgorithm[]{ ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ) //
112 consumer.beginScan( repoConfig, Calendar.getInstance().getTime() );
114 consumer.processFile( path );
116 Assertions.assertThat( sha1Path.toFile() ).exists();
117 Assertions.assertThat( md5Path.toFile() ).exists();
118 Assertions.assertThat(
119 checksum.isValidChecksums( new ChecksumAlgorithm[]{ ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ) //