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.

ArchivaRepositoryRegistryTest.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. package org.apache.archiva.repository.base;
  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.configuration.ArchivaConfiguration;
  21. import org.apache.archiva.configuration.Configuration;
  22. import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
  23. import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
  24. import org.apache.archiva.repository.ManagedRepository;
  25. import org.apache.archiva.repository.ReleaseScheme;
  26. import org.apache.archiva.repository.RemoteRepository;
  27. import org.apache.archiva.repository.Repository;
  28. import org.apache.archiva.repository.RepositoryException;
  29. import org.apache.archiva.repository.RepositoryRegistry;
  30. import org.apache.archiva.repository.RepositoryType;
  31. import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
  32. import org.apache.archiva.repository.base.managed.BasicManagedRepository;
  33. import org.apache.archiva.repository.base.remote.BasicRemoteRepository;
  34. import org.junit.jupiter.api.AfterAll;
  35. import org.junit.jupiter.api.AfterEach;
  36. import org.junit.jupiter.api.BeforeAll;
  37. import org.junit.jupiter.api.BeforeEach;
  38. import org.junit.jupiter.api.Test;
  39. import org.junit.jupiter.api.extension.ExtendWith;
  40. import org.springframework.test.context.ContextConfiguration;
  41. import org.springframework.test.context.junit.jupiter.SpringExtension;
  42. import javax.inject.Inject;
  43. import java.io.IOException;
  44. import java.net.URISyntaxException;
  45. import java.net.URL;
  46. import java.nio.file.Files;
  47. import java.nio.file.Path;
  48. import java.nio.file.Paths;
  49. import java.nio.file.StandardCopyOption;
  50. import java.util.Collection;
  51. import static org.junit.jupiter.api.Assertions.*;
  52. /**
  53. * Test for RepositoryRegistry
  54. */
  55. @ExtendWith( SpringExtension.class)
  56. @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
  57. public class ArchivaRepositoryRegistryTest
  58. {
  59. @Inject
  60. RepositoryRegistry repositoryRegistry;
  61. @Inject
  62. ArchivaConfiguration archivaConfiguration;
  63. @SuppressWarnings( "unused" )
  64. @Inject
  65. RepositoryGroupHandler repositoryGroupHandler;
  66. private static final Path userCfg = Paths.get(System.getProperty( "user.home" ), ".m2/archiva.xml");
  67. private static Path cfgCopy;
  68. private static Path archivaCfg;
  69. @BeforeAll
  70. public static void classSetup() throws IOException, URISyntaxException
  71. {
  72. URL archivaCfgUri = Thread.currentThread().getContextClassLoader().getResource( "archiva.xml" );
  73. if (archivaCfgUri!=null) {
  74. archivaCfg = Paths.get(archivaCfgUri.toURI());
  75. cfgCopy = Files.createTempFile( "archiva-backup", ".xml" );
  76. Files.copy( archivaCfg, cfgCopy, StandardCopyOption.REPLACE_EXISTING);
  77. }
  78. }
  79. @AfterAll
  80. public static void classTearDown() throws IOException
  81. {
  82. if (cfgCopy!=null) {
  83. Files.deleteIfExists( cfgCopy );
  84. }
  85. }
  86. @BeforeEach
  87. public void setUp( ) throws Exception
  88. {
  89. assertNotNull( repositoryRegistry );
  90. Files.deleteIfExists( userCfg );
  91. URL archivaCfgUri = Thread.currentThread().getContextClassLoader().getResource( "archiva.xml" );
  92. if (archivaCfgUri!=null) {
  93. archivaCfg = Paths.get(archivaCfgUri.toURI());
  94. if (Files.exists(cfgCopy))
  95. {
  96. Files.copy( cfgCopy, archivaCfg , StandardCopyOption.REPLACE_EXISTING);
  97. }
  98. }
  99. archivaConfiguration.reload();
  100. repositoryRegistry.reload();
  101. }
  102. @AfterEach
  103. public void tearDown( ) throws Exception
  104. {
  105. Files.deleteIfExists( userCfg );
  106. if (cfgCopy!=null && Files.exists(cfgCopy)) {
  107. Files.copy(cfgCopy, archivaCfg, StandardCopyOption.REPLACE_EXISTING);
  108. }
  109. }
  110. @Test
  111. public void getRepositories( ) throws Exception
  112. {
  113. Collection<Repository> repos = repositoryRegistry.getRepositories( );
  114. assertEquals( 5, repos.size( ) );
  115. assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals("internal") ));
  116. assertTrue( repos.stream( ).anyMatch( rep -> rep.getId( ).equals( "snapshots") ) );
  117. assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals( "central") ));
  118. }
  119. @Test
  120. public void getManagedRepositories( ) throws Exception
  121. {
  122. Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
  123. assertEquals( 4, repos.size( ) );
  124. assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals("internal") ));
  125. assertTrue( repos.stream( ).anyMatch( rep -> rep.getId( ).equals( "snapshots") ) );
  126. }
  127. @Test
  128. public void getRemoteRepositories( ) throws Exception
  129. {
  130. Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories( );
  131. assertEquals( 1, repos.size( ) );
  132. assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals( "central") ));
  133. }
  134. @Test
  135. public void getRepository( ) throws Exception
  136. {
  137. Repository repo = repositoryRegistry.getRepository( "internal" );
  138. assertNotNull(repo);
  139. assertEquals("internal", repo.getId());
  140. assertEquals("Archiva Managed Internal Repository", repo.getName());
  141. assertEquals("This is internal repository.", repo.getDescription());
  142. assertEquals( "default", repo.getLayout( ) );
  143. assertEquals("0 0 * * * ?", repo.getSchedulingDefinition());
  144. assertTrue(repo instanceof ManagedRepository);
  145. assertTrue( repo.hasIndex( ) );
  146. assertTrue(repo.isScanned());
  147. assertEquals( RepositoryType.MAVEN, repo.getType());
  148. }
  149. @Test
  150. public void getManagedRepository( ) throws Exception
  151. {
  152. ManagedRepository repo = repositoryRegistry.getManagedRepository( "internal" );
  153. assertNotNull(repo);
  154. assertEquals("internal", repo.getId());
  155. assertEquals("Archiva Managed Internal Repository", repo.getName());
  156. assertEquals("This is internal repository.", repo.getDescription());
  157. assertEquals( "default", repo.getLayout( ) );
  158. assertEquals("0 0 * * * ?", repo.getSchedulingDefinition());
  159. assertTrue( repo.hasIndex( ) );
  160. assertTrue(repo.isScanned());
  161. assertEquals(RepositoryType.MAVEN, repo.getType());
  162. assertTrue(repo.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE));
  163. assertFalse( repo.getActiveReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT ) );
  164. assertNotNull(repo.getContent());
  165. assertNull(repositoryRegistry.getManagedRepository( "xyu" ));
  166. }
  167. @Test
  168. public void getRemoteRepository( ) throws Exception
  169. {
  170. RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" );
  171. assertNotNull(repo);
  172. assertEquals("central", repo.getId());
  173. assertEquals("Central Repository", repo.getName());
  174. assertEquals("", repo.getDescription());
  175. assertEquals( "default", repo.getLayout( ) );
  176. assertEquals("0 0 08 ? * SUN", repo.getSchedulingDefinition());
  177. assertTrue( repo.hasIndex( ) );
  178. assertTrue(repo.isScanned());
  179. assertEquals(RepositoryType.MAVEN, repo.getType());
  180. assertEquals(35, repo.getTimeout().getSeconds());
  181. }
  182. @Test
  183. public void putManagedRepository( ) throws Exception
  184. {
  185. BasicManagedRepository managedRepository = BasicManagedRepository.newFilesystemInstance("test001", "Test repo", archivaConfiguration.getRepositoryBaseDir().resolve("test001"));
  186. managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
  187. repositoryRegistry.putRepository(managedRepository);
  188. assertNotNull(managedRepository.getContent());
  189. assertEquals(6, repositoryRegistry.getRepositories().size());
  190. managedRepository = BasicManagedRepository.newFilesystemInstance("central", "Test repo", archivaConfiguration.getRepositoryBaseDir().resolve("central"));
  191. managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
  192. ManagedRepository updatedRepo;
  193. try {
  194. repositoryRegistry.putRepository( managedRepository );
  195. throw new RuntimeException("Repository exception should be thrown, if there exists a remote repository already with that id");
  196. } catch ( RepositoryException e) {
  197. // OK
  198. }
  199. managedRepository = BasicManagedRepository.newFilesystemInstance("internal", "Test repo", archivaConfiguration.getRepositoryBaseDir().resolve("internal"));
  200. managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" );
  201. updatedRepo = repositoryRegistry.putRepository( managedRepository );
  202. assertSame( updatedRepo, managedRepository );
  203. assertNotNull(managedRepository.getContent());
  204. assertEquals(6, repositoryRegistry.getRepositories().size());
  205. ManagedRepository managedRepository1 = repositoryRegistry.getManagedRepository( "internal" );
  206. assertEquals("Test repo", managedRepository1.getName());
  207. assertSame( managedRepository1, managedRepository );
  208. }
  209. @Test
  210. public void putManagedRepositoryFromConfig( ) throws Exception
  211. {
  212. ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
  213. cfg.setId("test002");
  214. cfg.setName("This is test 002");
  215. ManagedRepository repo = repositoryRegistry.putRepository( cfg );
  216. assertNotNull(repo);
  217. assertEquals("test002", repo.getId());
  218. assertEquals("This is test 002", repo.getName());
  219. assertNotNull(repo.getContent());
  220. archivaConfiguration.reload();
  221. Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
  222. assertEquals(5, repos.size());
  223. ManagedRepository internalRepo = repositoryRegistry.getManagedRepository( "internal" );
  224. cfg = new ManagedRepositoryConfiguration();
  225. cfg.setId("internal");
  226. cfg.setName("This is internal test 002");
  227. repo = repositoryRegistry.putRepository( cfg );
  228. assertSame( internalRepo, repo );
  229. assertEquals("This is internal test 002",repo.getName());
  230. assertEquals(5, repositoryRegistry.getManagedRepositories().size());
  231. repositoryRegistry.reload();
  232. assertEquals(5, repositoryRegistry.getManagedRepositories().size());
  233. }
  234. @Test
  235. public void putManagedRepositoryFromConfigWithoutSave( ) throws Exception
  236. {
  237. Configuration configuration = archivaConfiguration.getConfiguration();
  238. ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
  239. cfg.setId("test002");
  240. cfg.setName("This is test 002");
  241. ManagedRepository repo = repositoryRegistry.putRepository( cfg, configuration );
  242. assertNotNull(repo);
  243. assertEquals("test002", repo.getId());
  244. assertEquals("This is test 002", repo.getName());
  245. assertNotNull(repo.getContent());
  246. archivaConfiguration.reload();
  247. assertEquals(3, archivaConfiguration.getConfiguration().getManagedRepositories().size());
  248. Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
  249. assertEquals(5, repos.size());
  250. ManagedRepository internalRepo = repositoryRegistry.getManagedRepository( "internal" );
  251. cfg = new ManagedRepositoryConfiguration();
  252. cfg.setId("internal");
  253. cfg.setName("This is internal test 002");
  254. repo = repositoryRegistry.putRepository( cfg, configuration );
  255. assertSame( internalRepo, repo );
  256. assertEquals("This is internal test 002",repo.getName());
  257. assertEquals(5, repositoryRegistry.getManagedRepositories().size());
  258. repositoryRegistry.reload();
  259. assertEquals(4, repositoryRegistry.getManagedRepositories().size());
  260. }
  261. @Test
  262. public void putRemoteRepository( ) throws Exception
  263. {
  264. BasicRemoteRepository remoteRepository = BasicRemoteRepository.newFilesystemInstance( "test001", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() );
  265. remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
  266. RemoteRepository newRepo = repositoryRegistry.putRepository(remoteRepository);
  267. assertSame( remoteRepository, newRepo );
  268. assertNotNull(remoteRepository.getContent());
  269. assertEquals(6, repositoryRegistry.getRepositories().size());
  270. remoteRepository = BasicRemoteRepository.newFilesystemInstance( "internal", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() );
  271. remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
  272. RemoteRepository updatedRepo;
  273. try
  274. {
  275. updatedRepo = repositoryRegistry.putRepository( remoteRepository );
  276. assertSame( remoteRepository, updatedRepo );
  277. throw new RuntimeException("Should throw repository exception, if repository exists already and is not the same type.");
  278. } catch (RepositoryException e) {
  279. // OK
  280. }
  281. remoteRepository = BasicRemoteRepository.newFilesystemInstance( "central", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() );
  282. remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" );
  283. updatedRepo = repositoryRegistry.putRepository( remoteRepository );
  284. assertSame( updatedRepo, remoteRepository );
  285. assertNotNull(remoteRepository.getContent());
  286. assertEquals(6, repositoryRegistry.getRepositories().size());
  287. RemoteRepository remoteRepository1 = repositoryRegistry.getRemoteRepository( "central" );
  288. assertEquals("Test repo", remoteRepository1.getName());
  289. assertSame( remoteRepository1, remoteRepository );
  290. }
  291. @Test
  292. public void putRemoteRepositoryFromConfig( ) throws Exception
  293. {
  294. RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
  295. cfg.setId("test002");
  296. cfg.setName("This is test 002");
  297. RemoteRepository repo = repositoryRegistry.putRepository( cfg );
  298. assertNotNull(repo);
  299. assertEquals("test002", repo.getId());
  300. assertEquals("This is test 002", repo.getName());
  301. assertNotNull(repo.getContent());
  302. archivaConfiguration.reload();
  303. Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories();
  304. assertEquals(2, repos.size());
  305. RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" );
  306. cfg = new RemoteRepositoryConfiguration();
  307. cfg.setId("central");
  308. cfg.setName("This is central test 002");
  309. repo = repositoryRegistry.putRepository( cfg );
  310. assertSame( internalRepo, repo );
  311. assertEquals("This is central test 002",repo.getName());
  312. assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
  313. repositoryRegistry.reload();
  314. assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
  315. }
  316. @Test
  317. public void putRemoteRepositoryFromConfigWithoutSave( ) throws Exception
  318. {
  319. Configuration configuration = archivaConfiguration.getConfiguration();
  320. RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
  321. cfg.setId("test002");
  322. cfg.setName("This is test 002");
  323. RemoteRepository repo = repositoryRegistry.putRepository( cfg, configuration );
  324. assertNotNull(repo);
  325. assertEquals("test002", repo.getId());
  326. assertEquals("This is test 002", repo.getName());
  327. assertNotNull(repo.getContent());
  328. archivaConfiguration.reload();
  329. assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size());
  330. Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories();
  331. assertEquals(2, repos.size());
  332. RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" );
  333. cfg = new RemoteRepositoryConfiguration();
  334. cfg.setId("central");
  335. cfg.setName("This is central test 002");
  336. repo = repositoryRegistry.putRepository( cfg, configuration );
  337. assertSame( internalRepo, repo );
  338. assertEquals("This is central test 002",repo.getName());
  339. assertEquals(2, repositoryRegistry.getRemoteRepositories().size());
  340. repositoryRegistry.reload();
  341. assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
  342. }
  343. @Test
  344. public void removeRepository( ) throws Exception
  345. {
  346. assertEquals(5, repositoryRegistry.getRepositories().size());
  347. Repository repo = repositoryRegistry.getRepository( "snapshots" );
  348. repositoryRegistry.removeRepository( repo );
  349. assertEquals(4, repositoryRegistry.getRepositories().size());
  350. assertTrue( repositoryRegistry.getRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) );
  351. archivaConfiguration.reload();
  352. repositoryRegistry.reload();
  353. assertEquals(4, repositoryRegistry.getRepositories().size());
  354. }
  355. @Test
  356. public void removeManagedRepository( ) throws Exception
  357. {
  358. assertEquals(4, repositoryRegistry.getManagedRepositories().size());
  359. ManagedRepository repo = repositoryRegistry.getManagedRepository( "snapshots" );
  360. repositoryRegistry.removeRepository( repo );
  361. assertEquals(3, repositoryRegistry.getManagedRepositories().size());
  362. assertTrue( repositoryRegistry.getManagedRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) );
  363. archivaConfiguration.reload();
  364. repositoryRegistry.reload();
  365. assertEquals(3, repositoryRegistry.getManagedRepositories().size());
  366. }
  367. @Test
  368. public void removeManagedRepositoryWithoutSave( ) throws Exception
  369. {
  370. Configuration configuration = archivaConfiguration.getConfiguration();
  371. assertEquals(4, repositoryRegistry.getManagedRepositories().size());
  372. ManagedRepository repo = repositoryRegistry.getManagedRepository( "snapshots" );
  373. repositoryRegistry.removeRepository( repo, configuration );
  374. assertEquals(3, repositoryRegistry.getManagedRepositories().size());
  375. assertTrue( repositoryRegistry.getManagedRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) );
  376. archivaConfiguration.reload();
  377. repositoryRegistry.reload();
  378. assertEquals(4, repositoryRegistry.getManagedRepositories().size());
  379. }
  380. @Test
  381. public void removeRemoteRepository( ) throws Exception
  382. {
  383. assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
  384. RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" );
  385. repositoryRegistry.removeRepository( repo );
  386. assertEquals(0, repositoryRegistry.getRemoteRepositories().size());
  387. assertTrue( repositoryRegistry.getRemoteRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "central" ) ) );
  388. archivaConfiguration.reload();
  389. repositoryRegistry.reload();
  390. assertEquals(0, repositoryRegistry.getRemoteRepositories().size());
  391. }
  392. @Test
  393. public void removeRemoteRepositoryWithoutSave( ) throws Exception
  394. {
  395. Configuration configuration = archivaConfiguration.getConfiguration();
  396. assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
  397. RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" );
  398. repositoryRegistry.removeRepository( repo, configuration );
  399. assertEquals(0, repositoryRegistry.getRemoteRepositories().size());
  400. assertTrue( repositoryRegistry.getRemoteRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "central" ) ) );
  401. archivaConfiguration.reload();
  402. repositoryRegistry.reload();
  403. assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
  404. }
  405. @Test
  406. public void cloneManagedRepo( ) throws Exception
  407. {
  408. ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( "internal" );
  409. try
  410. {
  411. repositoryRegistry.clone(managedRepository, "snapshots");
  412. throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already.");
  413. }
  414. catch ( RepositoryException e )
  415. {
  416. // OK
  417. }
  418. try
  419. {
  420. repositoryRegistry.clone(managedRepository, "central");
  421. throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already.");
  422. }
  423. catch ( RepositoryException e )
  424. {
  425. // OK
  426. }
  427. ManagedRepository clone = repositoryRegistry.clone( managedRepository, "newinternal" );
  428. assertNotNull(clone);
  429. assertNull(clone.getContent());
  430. assertEquals("Archiva Managed Internal Repository", clone.getName());
  431. assertNotSame( managedRepository, clone );
  432. }
  433. @Test
  434. public void cloneRemoteRepo( ) throws Exception
  435. {
  436. RemoteRepository remoteRepository = repositoryRegistry.getRemoteRepository( "central" );
  437. try
  438. {
  439. repositoryRegistry.clone(remoteRepository, "snapshots");
  440. throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already.");
  441. }
  442. catch ( RepositoryException e )
  443. {
  444. // OK
  445. }
  446. try
  447. {
  448. repositoryRegistry.clone(remoteRepository, "central");
  449. throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already.");
  450. }
  451. catch ( RepositoryException e )
  452. {
  453. // OK
  454. }
  455. RemoteRepository clone = repositoryRegistry.clone( remoteRepository, "newCentral" );
  456. assertNotNull(clone);
  457. assertNull(clone.getContent());
  458. assertEquals("Central Repository", clone.getName());
  459. assertNotSame( remoteRepository, clone );
  460. }
  461. @Test
  462. void validateRepository() {
  463. Repository repo = repositoryRegistry.getRepository( "internal" );
  464. assertNotNull( repo );
  465. assertTrue( repositoryRegistry.validateRepository( repo ).isValid() );
  466. }
  467. }