1 package org.apache.maven.archiva.proxy;
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.common.utils.PathUtil;
23 import org.apache.maven.archiva.model.ArtifactReference;
24 import org.apache.maven.archiva.policies.CachedFailuresPolicy;
25 import org.apache.maven.archiva.policies.ChecksumPolicy;
26 import org.apache.maven.archiva.policies.ReleasesPolicy;
27 import org.apache.maven.archiva.policies.SnapshotsPolicy;
28 import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
29 import org.apache.maven.wagon.ResourceDoesNotExistException;
34 * CacheFailuresTransferTest
36 * @author Brett Porter
37 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
40 public class CacheFailuresTransferTest
41 extends AbstractProxyTestCase
43 public void testGetWithCacheFailuresOn()
46 String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
47 File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path );
48 setupTestableManagedRepository( path );
50 assertNotExistsInManagedDefaultRepo( expectedFile );
52 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
54 // Configure Repository (usually done within archiva.xml configuration)
55 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
56 saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" );
58 // Configure Connector (usually done within archiva.xml configuration)
59 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
60 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES );
61 saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
62 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES );
64 wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
65 wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 );
67 wagonMockControl.replay();
69 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
71 wagonMockControl.verify();
73 assertNotDownloaded( downloadedFile );
74 assertNoTempFiles( expectedFile );
77 public void testGetWithCacheFailuresOff()
80 String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
81 File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path );
83 setupTestableManagedRepository( path );
85 assertNotExistsInManagedDefaultRepo( expectedFile );
87 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
89 // Configure Repository (usually done within archiva.xml configuration)
90 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
91 saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" );
93 // Configure Connector (usually done within archiva.xml configuration)
94 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
95 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
96 saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
97 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
99 wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
100 wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 );
102 wagonMockControl.replay();
104 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
106 assertNotDownloaded( downloadedFile );
108 wagonMockControl.verify();
109 assertNoTempFiles( expectedFile );
112 public void testGetWhenInBothProxiedButFirstCacheFailure()
115 String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
116 File expectedFile = new File( managedDefaultDir, path );
117 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
119 expectedFile.delete();
120 assertFalse( expectedFile.exists() );
122 String url = PathUtil.toUrl( REPOPATH_PROXIED1 + "/" + path );
124 // Intentionally set failure on url in proxied1 (for test)
125 UrlFailureCache failurlCache = lookupUrlFailureCache();
126 failurlCache.cacheFailure( url );
128 // Configure Connector (usually done within archiva.xml configuration)
129 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
130 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES );
131 saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
132 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES );
134 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
136 // Validate that file actually came from proxied2 (as intended).
137 File proxied2File = new File( REPOPATH_PROXIED2, path );
138 assertFileEquals( expectedFile, downloadedFile, proxied2File );
139 assertNoTempFiles( expectedFile );