001package org.eclipse.aether.internal.impl; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.junit.Assert.*; 023 024import org.eclipse.aether.spi.connector.checksum.ChecksumPolicy.ChecksumKind; 025import org.eclipse.aether.transfer.ChecksumFailureException; 026import org.eclipse.aether.transfer.TransferResource; 027import org.junit.Before; 028import org.junit.Test; 029 030public class FailChecksumPolicyTest 031{ 032 033 private FailChecksumPolicy policy; 034 035 private ChecksumFailureException exception; 036 037 @Before 038 public void setup() 039 { 040 policy = new FailChecksumPolicy( new TransferResource( "null", "file:/dev/null", "file.txt", null, null ) ); 041 exception = new ChecksumFailureException( "test" ); 042 } 043 044 @Test 045 public void testOnTransferChecksumFailure() 046 { 047 assertFalse( policy.onTransferChecksumFailure( exception ) ); 048 } 049 050 @Test 051 public void testOnChecksumMatch() 052 { 053 assertTrue( policy.onChecksumMatch( "SHA-1", ChecksumKind.REMOTE_EXTERNAL ) ); 054 assertTrue( policy.onChecksumMatch( "SHA-1", ChecksumKind.REMOTE_INCLUDED ) ); 055 assertTrue( policy.onChecksumMatch( "SHA-1", ChecksumKind.PROVIDED ) ); 056 } 057 058 @Test 059 public void testOnChecksumMismatch() 060 throws Exception 061 { 062 try 063 { 064 policy.onChecksumMismatch( "SHA-1", ChecksumKind.REMOTE_EXTERNAL, exception ); 065 fail( "No exception" ); 066 } 067 catch ( ChecksumFailureException e ) 068 { 069 assertSame( exception, e ); 070 } 071 try 072 { 073 policy.onChecksumMismatch( "SHA-1", ChecksumKind.REMOTE_INCLUDED, exception ); 074 fail( "No exception" ); 075 } 076 catch ( ChecksumFailureException e ) 077 { 078 assertSame( exception, e ); 079 } 080 try 081 { 082 policy.onChecksumMismatch("SHA-1", ChecksumKind.PROVIDED, exception); 083 fail( "No exception" ); 084 } 085 catch ( ChecksumFailureException e) 086 { 087 assertSame( exception, e ); 088 } 089 } 090 091 @Test 092 public void testOnChecksumError() 093 throws Exception 094 { 095 policy.onChecksumError( "SHA-1", ChecksumKind.REMOTE_EXTERNAL, exception ); 096 } 097 098 @Test 099 public void testOnNoMoreChecksums() 100 { 101 try 102 { 103 policy.onNoMoreChecksums(); 104 fail( "No exception" ); 105 } 106 catch ( ChecksumFailureException e ) 107 { 108 assertTrue( e.getMessage().contains( "no checksums available" ) ); 109 } 110 } 111 112}