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.

ManagedDefaultTransferTest.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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.commons.io.FileUtils;
  21. import org.apache.commons.lang.StringUtils;
  22. import org.apache.archiva.model.ArtifactReference;
  23. import org.apache.archiva.policies.CachedFailuresPolicy;
  24. import org.apache.archiva.policies.ChecksumPolicy;
  25. import org.apache.archiva.policies.ReleasesPolicy;
  26. import org.apache.archiva.policies.SnapshotsPolicy;
  27. import org.apache.maven.wagon.ResourceDoesNotExistException;
  28. import org.junit.Test;
  29. import java.io.File;
  30. import static org.junit.Assert.*;
  31. /**
  32. * ManagedDefaultTransferTest
  33. *
  34. *
  35. */
  36. public class ManagedDefaultTransferTest
  37. extends AbstractProxyTestCase
  38. {
  39. @Test
  40. public void testGetDefaultLayoutNotPresentConnectorOffline()
  41. throws Exception
  42. {
  43. String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
  44. setupTestableManagedRepository( path );
  45. File expectedFile = new File( managedDefaultDir, path );
  46. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  47. // Ensure file isn't present first.
  48. assertNotExistsInManagedDefaultRepo( expectedFile );
  49. // Configure Connector (usually done within archiva.xml configuration)
  50. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
  51. CachedFailuresPolicy.NO, true );
  52. // Attempt the proxy fetch.
  53. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  54. assertNull("File should not have been downloaded", downloadedFile);
  55. }
  56. @Test
  57. public void testGetDefaultLayoutNotPresent()
  58. throws Exception
  59. {
  60. String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
  61. setupTestableManagedRepository( path );
  62. File expectedFile = new File( managedDefaultDir, path );
  63. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  64. // Ensure file isn't present first.
  65. assertNotExistsInManagedDefaultRepo( expectedFile );
  66. // Configure Connector (usually done within archiva.xml configuration)
  67. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
  68. CachedFailuresPolicy.NO, false );
  69. // Attempt the proxy fetch.
  70. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  71. File sourceFile = new File( REPOPATH_PROXIED1, path );
  72. assertFileEquals( expectedFile, downloadedFile, sourceFile );
  73. assertNoTempFiles( expectedFile );
  74. }
  75. @Test
  76. public void testGetDefaultLayoutNotPresentPassthrough()
  77. throws Exception
  78. {
  79. String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar.asc";
  80. setupTestableManagedRepository( path );
  81. File expectedFile = new File( managedDefaultDir, path );
  82. // Ensure file isn't present first.
  83. assertNotExistsInManagedDefaultRepo( expectedFile );
  84. // Configure Connector (usually done within archiva.xml configuration)
  85. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
  86. CachedFailuresPolicy.NO, false );
  87. // Attempt the proxy fetch.
  88. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
  89. File sourceFile = new File( REPOPATH_PROXIED1, path );
  90. assertFileEquals( expectedFile, downloadedFile, sourceFile );
  91. assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".sha1" ).exists() );
  92. assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".md5" ).exists() );
  93. assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".asc" ).exists() );
  94. assertNoTempFiles( expectedFile );
  95. }
  96. /**
  97. * The attempt here should result in no file being transferred.
  98. * <p/>
  99. * The file exists locally, and the policy is ONCE.
  100. *
  101. * @throws Exception
  102. */
  103. @Test
  104. public void testGetDefaultLayoutAlreadyPresentPolicyOnce()
  105. throws Exception
  106. {
  107. String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
  108. setupTestableManagedRepository( path );
  109. File expectedFile = new File( managedDefaultDir, path );
  110. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  111. assertTrue( expectedFile.exists() );
  112. // Configure Connector (usually done within archiva.xml configuration)
  113. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
  114. CachedFailuresPolicy.NO, false );
  115. // Attempt the proxy fetch.
  116. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  117. assertFileEquals( expectedFile, downloadedFile, expectedFile );
  118. assertNoTempFiles( expectedFile );
  119. }
  120. /**
  121. * The attempt here should result in no file being transferred.
  122. * <p/>
  123. * The file exists locally, and the policy is ONCE.
  124. *
  125. * @throws Exception
  126. */
  127. @Test
  128. public void testGetDefaultLayoutAlreadyPresentPassthrough()
  129. throws Exception
  130. {
  131. String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc";
  132. setupTestableManagedRepository( path );
  133. File expectedFile = new File( managedDefaultDir, path );
  134. File remoteFile = new File( REPOPATH_PROXIED1, path );
  135. assertTrue( expectedFile.exists() );
  136. // Set the managed File to be newer than local.
  137. setManagedOlderThanRemote( expectedFile, remoteFile );
  138. long originalModificationTime = expectedFile.lastModified();
  139. // Configure Connector (usually done within archiva.xml configuration)
  140. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
  141. CachedFailuresPolicy.NO, false );
  142. // Attempt the proxy fetch.
  143. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
  144. assertNotDownloaded( downloadedFile );
  145. assertNotModified( expectedFile, originalModificationTime );
  146. assertNoTempFiles( expectedFile );
  147. }
  148. /**
  149. * <p>
  150. * Request a file, that exists locally, and remotely.
  151. * </p>
  152. * <p>
  153. * All policies are set to IGNORE.
  154. * </p>
  155. * <p>
  156. * Managed file is newer than remote file.
  157. * </p>
  158. * <p>
  159. * Transfer should not have occured, as managed file is newer.
  160. * </p>
  161. *
  162. * @throws Exception
  163. */
  164. @Test
  165. public void testGetDefaultLayoutAlreadyPresentNewerThanRemotePolicyIgnored()
  166. throws Exception
  167. {
  168. String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
  169. setupTestableManagedRepository( path );
  170. File expectedFile = new File( managedDefaultDir, path );
  171. File remoteFile = new File( REPOPATH_PROXIED1, path );
  172. // Set the managed File to be newer than local.
  173. setManagedNewerThanRemote( expectedFile, remoteFile );
  174. long originalModificationTime = expectedFile.lastModified();
  175. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  176. assertTrue( expectedFile.exists() );
  177. // Configure Connector (usually done within archiva.xml configuration)
  178. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
  179. SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
  180. // Attempt the proxy fetch.
  181. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  182. assertNotDownloaded( downloadedFile );
  183. assertNotModified( expectedFile, originalModificationTime );
  184. assertNoTempFiles( expectedFile );
  185. }
  186. /**
  187. * <p>
  188. * Request a file, that exists locally, and remotely.
  189. * </p>
  190. * <p>
  191. * All policies are set to IGNORE.
  192. * </p>
  193. * <p>
  194. * Managed file is older than Remote file.
  195. * </p>
  196. * <p>
  197. * Transfer should have occured, as managed file is older than remote.
  198. * </p>
  199. *
  200. * @throws Exception
  201. */
  202. @Test
  203. public void testGetDefaultLayoutAlreadyPresentOlderThanRemotePolicyIgnored()
  204. throws Exception
  205. {
  206. String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
  207. setupTestableManagedRepository( path );
  208. File expectedFile = new File( managedDefaultDir, path );
  209. File remoteFile = new File( REPOPATH_PROXIED1, path );
  210. // Set the managed file to be newer than remote file.
  211. setManagedOlderThanRemote( expectedFile, remoteFile );
  212. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  213. assertTrue( expectedFile.exists() );
  214. // Configure Connector (usually done within archiva.xml configuration)
  215. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
  216. SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
  217. // Attempt the proxy fetch.
  218. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  219. File proxiedFile = new File( REPOPATH_PROXIED1, path );
  220. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  221. assertNoTempFiles( expectedFile );
  222. }
  223. /**
  224. * The attempt here should result in file being transferred.
  225. * <p/>
  226. * The file exists locally, is over 6 years old, and the policy is DAILY.
  227. *
  228. * @throws Exception
  229. */
  230. @Test
  231. public void testGetDefaultLayoutRemoteUpdate()
  232. throws Exception
  233. {
  234. String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.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, ChecksumPolicy.FIX, ReleasesPolicy.DAILY, SnapshotsPolicy.DAILY,
  242. CachedFailuresPolicy.NO, false );
  243. // Attempt the proxy fetch.
  244. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  245. File proxiedFile = new File( REPOPATH_PROXIED1, path );
  246. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  247. assertNoTempFiles( expectedFile );
  248. }
  249. @Test
  250. public void testGetWhenInBothProxiedRepos()
  251. throws Exception
  252. {
  253. String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
  254. setupTestableManagedRepository( path );
  255. File expectedFile = new File( managedDefaultDir, path );
  256. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  257. assertNotExistsInManagedDefaultRepo( expectedFile );
  258. // Configure Connector (usually done within archiva.xml configuration)
  259. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 , false );
  260. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 , false );
  261. // Attempt the proxy fetch.
  262. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  263. File proxied1File = new File( REPOPATH_PROXIED1, path );
  264. File proxied2File = new File( REPOPATH_PROXIED2, path );
  265. assertFileEquals( expectedFile, downloadedFile, proxied1File );
  266. assertNoTempFiles( expectedFile );
  267. // TODO: is this check even needed if it passes above?
  268. String actualContents = FileUtils.readFileToString( downloadedFile, null );
  269. String badContents = FileUtils.readFileToString( proxied2File, null );
  270. assertFalse( "Downloaded file contents should not be that of proxy 2",
  271. StringUtils.equals( actualContents, badContents ) );
  272. }
  273. @Test
  274. public void testGetInSecondProxiedRepo()
  275. throws Exception
  276. {
  277. String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
  278. setupTestableManagedRepository( path );
  279. File expectedFile = new File( managedDefaultDir, path );
  280. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  281. assertNotExistsInManagedDefaultRepo( expectedFile );
  282. // Configure Connector (usually done within archiva.xml configuration)
  283. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
  284. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
  285. // Attempt the proxy fetch.
  286. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  287. File proxied2File = new File( REPOPATH_PROXIED2, path );
  288. assertFileEquals( expectedFile, downloadedFile, proxied2File );
  289. assertNoTempFiles( expectedFile );
  290. }
  291. @Test
  292. public void testNotFoundInAnyProxies()
  293. throws Exception
  294. {
  295. String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar";
  296. setupTestableManagedRepository( path );
  297. File expectedFile = new File( managedDefaultDir, path );
  298. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  299. assertNotExistsInManagedDefaultRepo( expectedFile );
  300. // Configure Connector (usually done within archiva.xml configuration)
  301. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
  302. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
  303. saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false );
  304. // Attempt the proxy fetch.
  305. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  306. assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception",
  307. downloadedFile );
  308. assertNoTempFiles( expectedFile );
  309. }
  310. @Test
  311. public void testGetInSecondProxiedRepoFirstFails()
  312. throws Exception
  313. {
  314. String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
  315. setupTestableManagedRepository( path );
  316. File expectedFile = new File( managedDefaultDir, path );
  317. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  318. assertNotExistsInManagedDefaultRepo( expectedFile );
  319. // Configure Repository (usually done within archiva.xml configuration)
  320. saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" );
  321. wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) );
  322. wagonMockControl.setMatcher(customWagonGetMatcher);
  323. wagonMockControl.setThrowable( new ResourceDoesNotExistException( "transfer failed" ) );
  324. wagonMockControl.replay();
  325. // Configure Connector (usually done within archiva.xml configuration)
  326. saveConnector( ID_DEFAULT_MANAGED, "badproxied", false );
  327. saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
  328. // Attempt the proxy fetch.
  329. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  330. wagonMockControl.verify();
  331. File proxied2File = new File( REPOPATH_PROXIED2, path );
  332. assertFileEquals( expectedFile, downloadedFile, proxied2File );
  333. assertNoTempFiles( expectedFile );
  334. }
  335. @Test
  336. public void testGetAllRepositoriesFail()
  337. throws Exception
  338. {
  339. String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
  340. setupTestableManagedRepository( path );
  341. File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path );
  342. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  343. assertNotExistsInManagedDefaultRepo( expectedFile );
  344. // Configure Repository (usually done within archiva.xml configuration)
  345. saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
  346. saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://dead.machine.com/repo/", "default" );
  347. // Configure Connector (usually done within archiva.xml configuration)
  348. saveConnector( ID_DEFAULT_MANAGED, "badproxied1", false );
  349. saveConnector( ID_DEFAULT_MANAGED, "badproxied2", false );
  350. File tmpFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" );
  351. wagonMock.get( path, tmpFile );
  352. wagonMockControl.setMatcher(customWagonGetMatcher);
  353. wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) );
  354. wagonMock.get( path, tmpFile );
  355. wagonMockControl.setMatcher(customWagonGetMatcher);
  356. wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) );
  357. wagonMockControl.replay();
  358. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  359. assertNotDownloaded( downloadedFile );
  360. wagonMockControl.verify();
  361. assertNoTempFiles( expectedFile );
  362. // TODO: do not want failures to present as a not found [MRM-492]
  363. // TODO: How much information on each failure should we pass back to the user vs. logging in the proxy?
  364. }
  365. @Test
  366. public void testGetFromLegacyProxyAlreadyPresentInManaged_NewerThanRemote()
  367. throws Exception
  368. {
  369. String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
  370. String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
  371. setupTestableManagedRepository( path );
  372. File expectedFile = new File( managedDefaultDir, path );
  373. File remoteFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
  374. // Set the managed file to be newer than remote.
  375. setManagedNewerThanRemote( expectedFile, remoteFile );
  376. long expectedTimestamp = expectedFile.lastModified();
  377. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  378. assertTrue( expectedFile.exists() );
  379. // Configure Connector (usually done within archiva.xml configuration)
  380. saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false );
  381. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  382. assertNotDownloaded( downloadedFile );
  383. assertNotModified( expectedFile, expectedTimestamp );
  384. assertNoTempFiles( expectedFile );
  385. }
  386. @Test
  387. public void testGetFromLegacyProxyAlreadyPresentInManaged_OlderThanRemote()
  388. throws Exception
  389. {
  390. String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
  391. String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
  392. setupTestableManagedRepository( path );
  393. File expectedFile = new File( managedDefaultDir, path );
  394. File remoteFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
  395. // Set the managed file to be older than remote.
  396. setManagedOlderThanRemote( expectedFile, remoteFile );
  397. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  398. assertTrue( expectedFile.exists() );
  399. // Configure Connector (usually done within archiva.xml configuration)
  400. saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false );
  401. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  402. File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
  403. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  404. assertNoTempFiles( expectedFile );
  405. }
  406. @Test
  407. public void testGetFromLegacyProxyNotPresentInManaged()
  408. throws Exception
  409. {
  410. String legacyPath = "org.apache.maven.test/jars/example-lib-2.2.jar";
  411. String path = "org/apache/maven/test/example-lib/2.2/example-lib-2.2.jar";
  412. setupTestableManagedRepository( path );
  413. File expectedFile = new File( managedDefaultDir, path );
  414. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  415. assertNotExistsInManagedDefaultRepo( expectedFile );
  416. // Configure Connector (usually done within archiva.xml configuration)
  417. saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false);
  418. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  419. File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
  420. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  421. assertNoTempFiles( expectedFile );
  422. }
  423. @Test
  424. public void testGetFromLegacyProxyPluginNotPresentInManaged()
  425. throws Exception
  426. {
  427. String legacyPath = "org.apache.maven.test/maven-plugins/example-maven-plugin-0.42.jar";
  428. String path = "org/apache/maven/test/example-maven-plugin/0.42/example-maven-plugin-0.42.jar";
  429. setupTestableManagedRepository( path );
  430. File expectedFile = new File( managedDefaultDir, path );
  431. ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
  432. assertNotExistsInManagedDefaultRepo( expectedFile );
  433. // Configure Connector (usually done within archiva.xml configuration)
  434. saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false );
  435. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
  436. File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
  437. assertFileEquals( expectedFile, downloadedFile, proxiedFile );
  438. assertNoTempFiles( expectedFile );
  439. }
  440. }