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.

ManagedLegacyTransferTest.java 9.4KB

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