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.TransferFailedException;
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 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
50 expectedFile.delete();
51 assertFalse( expectedFile.exists() );
53 // Configure Repository (usually done within archiva.xml configuration)
54 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
55 saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" );
57 // Configure Connector (usually done within archiva.xml configuration)
58 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
59 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
60 saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
61 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
63 wagonMock.getIfNewer( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ), 0 );
64 TransferFailedException failedException = new TransferFailedException( "transfer failed" );
65 wagonMockControl.setThrowable( failedException );
67 wagonMockControl.replay();
69 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
71 assertNotDownloaded( downloadedFile );
73 wagonMockControl.verify();
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 );
82 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
84 expectedFile.delete();
85 assertFalse( expectedFile.exists() );
87 // Configure Repository (usually done within archiva.xml configuration)
88 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
89 saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" );
91 // Configure Connector (usually done within archiva.xml configuration)
92 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
93 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
94 saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
95 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
97 wagonMock.getIfNewer( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ), 0 );
98 TransferFailedException failedException = new TransferFailedException( "transfer failed" );
99 wagonMockControl.setThrowable( failedException );
101 wagonMockControl.replay();
103 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
105 assertNotDownloaded( downloadedFile );
107 wagonMockControl.verify();
108 assertNoTempFiles( expectedFile );
111 public void testGetWhenInBothProxiedButFirstCacheFailure()
114 String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
115 File expectedFile = new File( managedDefaultDir, path );
116 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
118 expectedFile.delete();
119 assertFalse( expectedFile.exists() );
121 String url = PathUtil.toUrl( REPOPATH_PROXIED1 + "/" + path );
123 // Intentionally set failure on url in proxied1 (for test)
124 UrlFailureCache failurlCache = lookupUrlFailureCache();
125 failurlCache.cacheFailure( url );
127 // Configure Connector (usually done within archiva.xml configuration)
128 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
129 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
130 saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
131 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
133 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
135 // Validate that file actually came from proxied2 (as intended).
136 File proxied2File = new File( REPOPATH_PROXIED2, path );
137 assertFileEquals( expectedFile, downloadedFile, proxied2File );
138 assertNoTempFiles( expectedFile );