You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SnapshotTransferTest.java 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. package org.apache.archiva.proxy;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.model.ArtifactReference;
  21. import org.apache.archiva.policies.CachedFailuresPolicy;
  22. import org.apache.archiva.policies.ChecksumPolicy;
  23. import org.apache.archiva.policies.ReleasesPolicy;
  24. import org.apache.archiva.policies.SnapshotsPolicy;
  25. import org.junit.Test;
  26. import java.io.File;
  27. import static org.junit.Assert.assertFalse;
  28. import static org.junit.Assert.assertTrue;
  29. /**
  30. * SnapshotTransferTest
  31. *
  32. *
  33. */
  34. public class SnapshotTransferTest
  35. extends AbstractProxyTestCase
  36. {
  37. @Test
  38. public void testSnapshotNonExistant()
  39. throws Exception
  40. {
  41. String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
  42. setupTestableManagedRepository( path );
  43. File expectedFile = new File( managedDefaultDir, path );
  44. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  45. expectedFile.delete();
  46. assertFalse( expectedFile.exists() );
  47. // Configure Connector (usually done within archiva.xml configuration)
  48. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
  49. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  50. assertNotDownloaded( downloadedFile );
  51. assertNoTempFiles( expectedFile );
  52. }
  53. @Test
  54. public void testTimestampDrivenSnapshotNotPresentAlready()
  55. throws Exception
  56. {
  57. String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
  58. setupTestableManagedRepository( path );
  59. File expectedFile = new File( managedDefaultDir, path );
  60. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  61. expectedFile.delete();
  62. assertFalse( expectedFile.exists() );
  63. // Configure Connector (usually done within archiva.xml configuration)
  64. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
  65. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  66. File proxiedFile = new File( REPOPATH_PROXIED1, path );
  67. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  68. assertNoTempFiles( expectedFile );
  69. }
  70. @Test
  71. public void testNewerTimestampDrivenSnapshotOnFirstRepo()
  72. throws Exception
  73. {
  74. String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
  75. setupTestableManagedRepository( path );
  76. File expectedFile = new File( managedDefaultDir, path );
  77. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  78. assertTrue( expectedFile.exists() );
  79. expectedFile.setLastModified( getPastDate().getTime() );
  80. // Configure Connector (usually done within archiva.xml configuration)
  81. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
  82. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  83. File proxiedFile = new File( REPOPATH_PROXIED1, path );
  84. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  85. assertNoTempFiles( expectedFile );
  86. }
  87. @Test
  88. public void testOlderTimestampDrivenSnapshotOnFirstRepo()
  89. throws Exception
  90. {
  91. String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
  92. setupTestableManagedRepository( path );
  93. File expectedFile = new File( managedDefaultDir, path );
  94. File remoteFile = new File( REPOPATH_PROXIED1, path );
  95. setManagedNewerThanRemote( expectedFile, remoteFile );
  96. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  97. // Configure Connector (usually done within archiva.xml configuration)
  98. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
  99. // Attempt to download.
  100. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  101. // Should not have downloaded as managed is newer than remote.
  102. assertNotDownloaded( downloadedFile );
  103. assertNoTempFiles( expectedFile );
  104. }
  105. /**
  106. * TODO: Has problems with wagon implementation not preserving timestamp.
  107. */
  108. /*
  109. public void testNewerTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
  110. throws Exception
  111. {
  112. String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
  113. setupTestableManagedRepository( path );
  114. File expectedFile = new File( managedDefaultDir, path );
  115. ArtifactReference artifact = createArtifactReference( "default", path );
  116. expectedFile.delete();
  117. assertFalse( expectedFile.exists() );
  118. // Create customized proxy / target repository
  119. File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED1_TARGET, REPOPATH_PROXIED1,
  120. REPOPATH_PROXIED1_TARGET, "default" );
  121. new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
  122. // Configure Connector (usually done within archiva.xml configuration)
  123. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
  124. SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
  125. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
  126. SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
  127. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  128. // Should have downloaded the content from proxy2, as proxy1 has an old (by file.lastModified check) version.
  129. File proxiedFile = new File( REPOPATH_PROXIED2, path );
  130. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  131. assertNoTempFiles( expectedFile );
  132. }
  133. public void testOlderTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
  134. throws Exception
  135. {
  136. String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
  137. setupTestableManagedRepository( path );
  138. File expectedFile = new File( managedDefaultDir, path );
  139. ArtifactReference artifact = createArtifactReference( "default", path );
  140. expectedFile.delete();
  141. assertFalse( expectedFile.exists() );
  142. // Create customized proxy / target repository
  143. File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED2_TARGET, REPOPATH_PROXIED2,
  144. REPOPATH_PROXIED2_TARGET, "default" );
  145. new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
  146. // Configure Connector (usually done within archiva.xml configuration)
  147. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
  148. SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
  149. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
  150. SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
  151. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  152. File proxiedFile = new File( REPOPATH_PROXIED1_TARGET, path );
  153. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  154. assertNoTempFiles( expectedFile );
  155. } */
  156. @Test
  157. public void testTimestampDrivenSnapshotNotExpired()
  158. throws Exception
  159. {
  160. String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
  161. setupTestableManagedRepository( path );
  162. File expectedFile = new File( managedDefaultDir, path );
  163. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  164. assertTrue( expectedFile.exists() );
  165. File proxiedFile = new File( REPOPATH_PROXIED1, path );
  166. proxiedFile.setLastModified( getFutureDate().getTime() );
  167. // Configure Connector (usually done within archiva.xml configuration)
  168. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
  169. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  170. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  171. assertNoTempFiles( expectedFile );
  172. }
  173. @Test
  174. public void testTimestampDrivenSnapshotNotUpdated()
  175. throws Exception
  176. {
  177. String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
  178. setupTestableManagedRepository( path );
  179. File expectedFile = new File( managedDefaultDir, path );
  180. File remoteFile = new File( REPOPATH_PROXIED1, path );
  181. setManagedNewerThanRemote( expectedFile, remoteFile, 12000000 );
  182. long expectedTimestamp = expectedFile.lastModified();
  183. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  184. // Configure Connector (usually done within archiva.xml configuration)
  185. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
  186. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  187. assertNotDownloaded( downloadedFile );
  188. assertNotModified( expectedFile, expectedTimestamp );
  189. assertNoTempFiles( expectedFile );
  190. }
  191. @Test
  192. public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure()
  193. throws Exception
  194. {
  195. String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
  196. setupTestableManagedRepository( path );
  197. File expectedFile = new File( managedDefaultDir, path );
  198. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  199. expectedFile.delete();
  200. assertFalse( expectedFile.exists() );
  201. // Configure Connector (usually done within archiva.xml configuration)
  202. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
  203. SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
  204. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
  205. SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
  206. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  207. File proxiedFile = new File( REPOPATH_PROXIED1, path );
  208. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  209. assertNoTempFiles( expectedFile );
  210. }
  211. @Test
  212. public void testMetadataDrivenSnapshotNotPresentAlready()
  213. throws Exception
  214. {
  215. String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
  216. setupTestableManagedRepository( path );
  217. File expectedFile = new File( managedDefaultDir, path );
  218. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  219. expectedFile.delete();
  220. assertFalse( expectedFile.exists() );
  221. // Configure Connector (usually done within archiva.xml configuration)
  222. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
  223. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  224. File proxiedFile = new File( REPOPATH_PROXIED1, path );
  225. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  226. assertNoTempFiles( expectedFile );
  227. }
  228. @Test
  229. public void testGetMetadataDrivenSnapshotRemoteUpdate()
  230. throws Exception
  231. {
  232. // Metadata driven snapshots (using a full timestamp) are treated like a release. It is the timing of the
  233. // updates to the metadata files that triggers which will be downloaded
  234. String path = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar";
  235. setupTestableManagedRepository( path );
  236. File expectedFile = new File( managedDefaultDir, path );
  237. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  238. assertTrue( expectedFile.exists() );
  239. expectedFile.setLastModified( getPastDate().getTime() );
  240. // Configure Connector (usually done within archiva.xml configuration)
  241. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
  242. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  243. File proxiedFile = new File( REPOPATH_PROXIED1, path );
  244. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  245. assertNoTempFiles( expectedFile );
  246. }
  247. }