1 package org.apache.maven.archiva.policies;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
23 import org.codehaus.plexus.PlexusTestCase;
26 import java.util.Properties;
29 * CachedFailuresPolicyTest
31 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
34 public class CachedFailuresPolicyTest
35 extends PlexusTestCase
37 private DownloadPolicy lookupPolicy()
40 return (DownloadPolicy) lookup( PreDownloadPolicy.class.getName(), "cache-failures" );
43 private UrlFailureCache lookupUrlFailureCache()
46 return (UrlFailureCache) lookup( UrlFailureCache.class.getName(), "default" );
49 private File getFile()
51 return new File( "target/cache-failures/" + getName() + ".txt" );
54 private Properties createRequest()
56 Properties request = new Properties();
61 public void testIgnored()
64 DownloadPolicy policy = lookupPolicy();
65 File localFile = getFile();
66 Properties request = createRequest();
68 request.setProperty( "url", "http://a.bad.hostname.maven.org/path/to/resource.txt" );
70 policy.applyPolicy( CachedFailuresPolicy.IGNORED, request, localFile );
73 public void testCachedNotInCache()
76 DownloadPolicy policy = lookupPolicy();
77 File localFile = getFile();
78 Properties request = createRequest();
80 request.setProperty( "url", "http://a.bad.hostname.maven.org/path/to/resource.txt" );
82 policy.applyPolicy( CachedFailuresPolicy.CACHED, request, localFile );
85 public void testCachedInCache()
88 UrlFailureCache urlFailureCache = lookupUrlFailureCache();
90 DownloadPolicy policy = lookupPolicy();
91 File localFile = getFile();
92 Properties request = createRequest();
94 String url = "http://a.bad.hostname.maven.org/path/to/resource.txt";
96 urlFailureCache.cacheFailure( url );
98 request.setProperty( "url", url );
102 policy.applyPolicy( CachedFailuresPolicy.CACHED, request, localFile );
103 fail( "Expected a PolicyViolationException." );
105 catch ( PolicyViolationException e )