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;
025import org.eclipse.aether.transfer.ChecksumFailureException;
026import org.eclipse.aether.transfer.TransferResource;
027import org.junit.Before;
028import org.junit.Test;
029
030public class WarnChecksumPolicyTest
031{
032
033    private WarnChecksumPolicy policy;
034
035    private ChecksumFailureException exception;
036
037    @Before
038    public void setup()
039    {
040        policy = new WarnChecksumPolicy( 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        assertTrue( policy.onTransferChecksumFailure( exception ) );
048    }
049
050    @Test
051    public void testOnChecksumMatch()
052    {
053        assertTrue( policy.onChecksumMatch( "SHA-1", 0 ) );
054        assertTrue( policy.onChecksumMatch( "SHA-1", ChecksumPolicy.KIND_UNOFFICIAL ) );
055    }
056
057    @Test
058    public void testOnChecksumMismatch()
059        throws Exception
060    {
061        try
062        {
063            policy.onChecksumMismatch( "SHA-1", 0, exception );
064            fail( "No exception" );
065        }
066        catch ( ChecksumFailureException e )
067        {
068            assertSame( exception, e );
069        }
070        policy.onChecksumMismatch( "SHA-1", ChecksumPolicy.KIND_UNOFFICIAL, exception );
071    }
072
073    @Test
074    public void testOnChecksumError()
075        throws Exception
076    {
077        policy.onChecksumError( "SHA-1", 0, exception );
078    }
079
080    @Test
081    public void testOnNoMoreChecksums()
082    {
083        try
084        {
085            policy.onNoMoreChecksums();
086            fail( "No exception" );
087        }
088        catch ( ChecksumFailureException e )
089        {
090            assertTrue( e.getMessage().contains( "no checksums available" ) );
091        }
092    }
093
094}