]> source.dussan.org Git - archiva.git/blob
270c59f93e61c119021dd139d1d2900d4ea141cb
[archiva.git] /
1 package org.apache.maven.archiva.proxy;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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;
30
31 import java.io.File;
32
33 /**
34  * CacheFailuresTransferTest
35  *
36  * @author Brett Porter
37  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
38  * @version $Id$
39  */
40 public class CacheFailuresTransferTest
41     extends AbstractProxyTestCase
42 {
43     public void testGetWithCacheFailuresOn()
44         throws Exception
45     {
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 );
49         
50         assertNotExistsInManagedDefaultRepo( expectedFile );
51         
52         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
53
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" );
57
58         // Configure Connector (usually done within archiva.xml configuration)
59         saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
60                        SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
61         saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
62                        SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
63
64         wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
65         wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 );
66
67         wagonMockControl.replay();
68
69         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
70
71         wagonMockControl.verify();
72         
73         assertNotDownloaded( downloadedFile );
74         assertNoTempFiles( expectedFile );
75     }
76
77     public void testGetWithCacheFailuresOff()
78         throws Exception
79     {
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         
83         setupTestableManagedRepository( path );
84
85         assertNotExistsInManagedDefaultRepo( expectedFile );
86         
87         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
88
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" );
92
93         // Configure Connector (usually done within archiva.xml configuration)
94         saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
95                        SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
96         saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
97                        SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
98
99         wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
100         wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 );
101
102         wagonMockControl.replay();
103
104         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
105
106         assertNotDownloaded( downloadedFile );
107
108         wagonMockControl.verify();
109         assertNoTempFiles( expectedFile );
110     }
111
112     public void testGetWhenInBothProxiedButFirstCacheFailure()
113         throws Exception
114     {
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 );
118
119         expectedFile.delete();
120         assertFalse( expectedFile.exists() );
121
122         String url = PathUtil.toUrl( REPOPATH_PROXIED1 + "/" + path );
123
124         // Intentionally set failure on url in proxied1 (for test)
125         UrlFailureCache failurlCache = lookupUrlFailureCache();
126         failurlCache.cacheFailure( url );
127
128         // Configure Connector (usually done within archiva.xml configuration)
129         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
130                        SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
131         saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
132                        SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
133
134         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
135
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 );
140     }
141 }