View Javadoc

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.model.ArtifactReference;
23  import org.apache.maven.archiva.policies.CachedFailuresPolicy;
24  import org.apache.maven.archiva.policies.ChecksumPolicy;
25  import org.apache.maven.archiva.policies.ReleasesPolicy;
26  import org.apache.maven.archiva.policies.SnapshotsPolicy;
27  
28  import java.io.File;
29  
30  /**
31   * ManagedLegacyTransferTest 
32   *
33   * @version $Id: ManagedLegacyTransferTest.java 718864 2008-11-19 06:33:35Z brett $
34   */
35  public class ManagedLegacyTransferTest
36      extends AbstractProxyTestCase
37  {
38      /**
39       * Incoming request on a Managed Legacy repository, for content that does not
40       * exist in the managed legacy repository, but does exist on a remote default layout repository.
41       */
42      public void testManagedLegacyNotPresentRemoteDefaultPresent()
43          throws Exception
44      {
45          String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar";
46          File expectedFile = new File( managedLegacyDir, path );
47          ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
48  
49          assertNotExistsInManagedLegacyRepo( expectedFile );
50  
51          // Configure Connector (usually done within archiva.xml configuration)
52          saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, false );
53  
54          File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
55  
56          File proxied2File = new File( REPOPATH_PROXIED1,
57                                        "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar" );
58          assertFileEquals( expectedFile, downloadedFile, proxied2File );
59          assertNoTempFiles( expectedFile );
60      }
61  
62      /**
63       * Incoming request on a Managed Legacy repository, for content that already
64       * exist in the managed legacy repository, and also exist on a remote default layout repository.
65       */
66      public void testManagedLegacyPresentRemoteDefaultPresent()
67          throws Exception
68      {
69          String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
70          String remotePath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
71          
72          File expectedFile = new File( managedLegacyDir, path );
73          File remoteFile = new File( REPOPATH_PROXIED1, remotePath );
74  
75          setManagedOlderThanRemote( expectedFile, remoteFile );
76          
77          ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
78  
79          // Configure Connector (usually done within archiva.xml configuration)
80          saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
81                         SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
82  
83          File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
84  
85          assertFileEquals( expectedFile, downloadedFile, remoteFile );
86          assertNoTempFiles( expectedFile );
87      }
88  
89      /**
90       * Incoming request on a Managed Legacy repository, for content that does not
91       * exist in the managed legacy repository, and does not exist on a remote legacy layout repository.
92       */
93      public void testManagedLegacyNotPresentRemoteLegacyPresent()
94          throws Exception
95      {
96          String path = "org.apache.maven.test/plugins/get-legacy-plugin-1.0.jar";
97          File expectedFile = new File( managedLegacyDir, path );
98          ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
99  
100         assertNotExistsInManagedLegacyRepo( expectedFile );
101 
102         // Configure Connector (usually done within archiva.xml configuration)
103         saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, false );
104 
105         File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
106 
107         File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, path );
108         assertFileEquals( expectedFile, downloadedFile, proxiedFile );
109         assertNoTempFiles( expectedFile );
110     }
111 
112     /**
113      * Incoming request on a Managed Legacy repository, for content that does exist in the 
114      * managed legacy repository, and also exists on a remote legacy layout repository. 
115      */
116     public void testManagedLegacyPresentRemoteLegacyPresent()
117         throws Exception
118     {
119         String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
120         File expectedFile = new File( managedLegacyDir, path );
121         File remoteFile = new File( REPOPATH_PROXIED_LEGACY, path );
122 
123         setManagedOlderThanRemote( expectedFile, remoteFile );
124         
125         ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
126 
127         // Configure Connector (usually done within archiva.xml configuration)
128         saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, false );
129 
130         File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
131 
132         assertFileEquals( expectedFile, downloadedFile, remoteFile );
133         assertNoTempFiles( expectedFile );
134     }
135 
136     /**
137      * Incoming request on a Managed Legacy repository, for content that does exist in the 
138      * managed legacy repository, and does not exist on a remote legacy layout repository. 
139      */
140     public void testManagedLegacyPresentRemoteLegacyNotPresent()
141         throws Exception
142     {
143         String path = "org.apache.maven.test/jars/managed-only-lib-2.1.jar";
144         File expectedFile = new File( managedLegacyDir, path );
145         ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
146 
147         assertTrue( expectedFile.exists() );
148 
149         // Configure Connector (usually done within archiva.xml configuration)
150         saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, false );
151 
152         File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
153 
154         assertNotDownloaded( downloadedFile );
155         assertNoTempFiles( expectedFile );
156     }
157 
158     /**
159      * Incoming request on a Managed Legacy repository, for content that does exist in the 
160      * managed legacy repository, and does not exists on a remote default layout repository. 
161      */
162     public void testManagedLegacyPresentRemoteDefaultNotPresent()
163         throws Exception
164     {
165         String path = "org.apache.maven.test/jars/managed-only-lib-2.1.jar";
166         File expectedFile = new File( managedLegacyDir, path );
167         ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
168 
169         assertTrue( expectedFile.exists() );
170 
171         // Configure Connector (usually done within archiva.xml configuration)
172         saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, false );
173 
174         File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
175 
176         assertNotDownloaded( downloadedFile );
177         assertNoTempFiles( expectedFile );
178     }
179 
180     /**
181      * Incoming request on a Managed Legacy repository, for content that does not exist in the 
182      * managed legacy repository, and does not exists on a remote legacy layout repository. 
183      */
184     public void testManagedLegacyNotPresentRemoteLegacyNotPresent()
185         throws Exception
186     {
187         String path = "org.apache.archiva.test/jars/mystery-lib-1.0.jar";
188         File expectedFile = new File( managedLegacyDir, path );
189         ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
190 
191         assertNotExistsInManagedLegacyRepo( expectedFile );
192 
193         // Configure Connector (usually done within archiva.xml configuration)
194         saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, false );
195 
196         File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
197 
198         assertNotDownloaded( downloadedFile );
199         assertNoTempFiles( expectedFile );
200     }
201 
202     /**
203      * Incoming request on a Managed Legacy repository, for content that does not exist in the 
204      * managed legacy repository, and does not exists on a remote default layout repository. 
205      */
206     public void testManagedLegacyNotPresentRemoteDefaultNotPresent()
207         throws Exception
208     {
209         String path = "org.apache.archiva.test/jars/mystery-lib-2.1.jar";
210         File expectedFile = new File( managedLegacyDir, path );
211         ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
212 
213         assertNotExistsInManagedLegacyRepo( expectedFile );
214 
215         // Configure Connector (usually done within archiva.xml configuration)
216         saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, false );
217 
218         File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
219 
220         assertNotDownloaded( downloadedFile );
221         assertNoTempFiles( expectedFile );
222     }
223 }