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.

Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. package org.apache.archiva.repository.maven.metadata.storage;
  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. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import junit.framework.TestCase;
  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.ProxyConnectorConfiguration;
  24. import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
  25. import org.apache.archiva.configuration.RepositoryGroupConfiguration;
  26. import org.apache.archiva.filter.AllFilter;
  27. import org.apache.archiva.filter.Filter;
  28. import org.apache.archiva.metadata.model.ArtifactMetadata;
  29. import org.apache.archiva.metadata.model.Dependency;
  30. import org.apache.archiva.metadata.model.License;
  31. import org.apache.archiva.metadata.model.MailingList;
  32. import org.apache.archiva.metadata.model.ProjectVersionMetadata;
  33. import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
  34. import org.apache.archiva.proxy.maven.WagonFactory;
  35. import org.apache.archiva.proxy.maven.WagonFactoryRequest;
  36. import org.apache.archiva.repository.RepositoryRegistry;
  37. import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
  38. import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
  39. import org.apache.commons.io.FileUtils;
  40. import org.apache.maven.wagon.Wagon;
  41. import org.junit.Before;
  42. import org.junit.Test;
  43. import org.junit.runner.RunWith;
  44. import org.springframework.test.context.ContextConfiguration;
  45. import javax.inject.Inject;
  46. import javax.inject.Named;
  47. import java.io.IOException;
  48. import java.nio.file.Files;
  49. import java.nio.file.Path;
  50. import java.nio.file.Paths;
  51. import java.util.ArrayList;
  52. import java.util.Arrays;
  53. import java.util.List;
  54. import static org.mockito.Mockito.mock;
  55. import static org.mockito.Mockito.when;
  56. @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
  57. @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
  58. public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest
  59. extends TestCase
  60. {
  61. private static final Filter<String> ALL = new AllFilter<String>();
  62. @Inject
  63. @Named ( "repositoryStorage#maven2")
  64. private Maven2RepositoryStorage storage;
  65. private static final String TEST_REPO_ID = "test";
  66. private static final String TEST_SNAP_REPO_ID = "tests";
  67. private static final String TEST_REPO_GROUP_ID = "testrg";
  68. private static final String TEST_REMOTE_REPO_ID = "central";
  69. private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
  70. private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
  71. private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
  72. private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
  73. private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
  74. private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
  75. private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
  76. private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
  77. @Inject
  78. @Named ( "archivaConfiguration#default" )
  79. private ArchivaConfiguration configuration;
  80. @Inject
  81. RepositoryRegistry repositoryRegistry;
  82. @SuppressWarnings( "unused" )
  83. @Inject
  84. RepositoryHandlerDependencies repositoryHandlerDependencies;
  85. private WagonFactory wagonFactory;
  86. ManagedRepositoryConfiguration testRepo;
  87. ManagedRepositoryConfiguration testRepoS;
  88. Configuration c;
  89. @Before
  90. @Override
  91. public void setUp()
  92. throws Exception
  93. {
  94. super.setUp();
  95. c = new Configuration();
  96. testRepo = new ManagedRepositoryConfiguration();
  97. testRepo.setId( TEST_REPO_ID );
  98. testRepo.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toString() );
  99. testRepo.setReleases( true );
  100. testRepo.setSnapshots( false );
  101. c.addManagedRepository( testRepo );
  102. testRepoS = new ManagedRepositoryConfiguration();
  103. testRepoS.setId( TEST_SNAP_REPO_ID );
  104. testRepoS.setLocation( Paths.get( "target/test-repositorys" ).toAbsolutePath().toString() );
  105. testRepoS.setReleases( false );
  106. testRepoS.setSnapshots( true );
  107. c.addManagedRepository( testRepoS );
  108. RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
  109. testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
  110. testRemoteRepo.setLayout( "default" );
  111. testRemoteRepo.setName( "Central Repository" );
  112. testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
  113. testRemoteRepo.setTimeout( 10 );
  114. c.addRemoteRepository( testRemoteRepo );
  115. ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
  116. proxyConnector.setSourceRepoId( TEST_REPO_ID );
  117. proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
  118. proxyConnector.setDisabled( false );
  119. c.addProxyConnector( proxyConnector );
  120. ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
  121. proxyConnectors.setSourceRepoId( TEST_SNAP_REPO_ID );
  122. proxyConnectors.setTargetRepoId( TEST_REMOTE_REPO_ID );
  123. proxyConnectors.setDisabled( false );
  124. c.addProxyConnector( proxyConnectors );
  125. List<String> repos = new ArrayList<>();
  126. repos.add( TEST_REPO_ID );
  127. repos.add( TEST_SNAP_REPO_ID );
  128. RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
  129. repoGroup.setId( TEST_REPO_GROUP_ID );
  130. repoGroup.setRepositories( repos );
  131. c.addRepositoryGroup( repoGroup );
  132. configuration.save( c );
  133. repositoryRegistry.reload();
  134. assertFalse( c.getManagedRepositories().get( 0 ).isSnapshots() );
  135. assertTrue( c.getManagedRepositories().get( 0 ).isReleases() );
  136. assertTrue( c.getManagedRepositories().get( 1 ).isSnapshots() );
  137. assertFalse( c.getManagedRepositories().get( 1 ).isReleases() );
  138. wagonFactory = mock( WagonFactory.class );
  139. storage.setWagonFactory( wagonFactory );
  140. Wagon wagon = new MockWagon();
  141. when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
  142. }
  143. // Tests for MRM-1411 - START
  144. @Test
  145. public void testGetProjectVersionMetadataWithParentSuccessful()
  146. throws Exception
  147. {
  148. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-module-a",
  149. "target/test-repository/com/example/test/test-artifact-module-a" );
  150. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-root",
  151. "target/test-repository/com/example/test/test-artifact-root" );
  152. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
  153. "target/test-repository/com/example/test/test-artifact-parent" );
  154. ReadMetadataRequest readMetadataRequest =
  155. new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "com.example.test" ).projectId(
  156. "test-artifact-module-a" ).projectVersion( "1.0" );
  157. ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
  158. MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
  159. assertEquals( "jar", facet.getPackaging() );
  160. assertEquals( "http://maven.apache.org", metadata.getUrl() );
  161. assertEquals( "com.example.test", facet.getParent().getGroupId() );
  162. assertEquals( "test-artifact-root", facet.getParent().getArtifactId() );
  163. assertEquals( "1.0", facet.getParent().getVersion() );
  164. assertEquals( "test-artifact-module-a", facet.getArtifactId() );
  165. assertEquals( "com.example.test", facet.getGroupId() );
  166. assertNull( metadata.getCiManagement() );
  167. assertNotNull( metadata.getDescription() );
  168. checkApacheLicense( metadata );
  169. assertEquals( "1.0", metadata.getId() );
  170. assertEquals( "Test Artifact :: Module A", metadata.getName() );
  171. String path = "test-artifact/trunk/test-artifact-module-a";
  172. assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
  173. assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
  174. assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
  175. List<Dependency> dependencies = metadata.getDependencies();
  176. assertEquals( 2, dependencies.size() );
  177. assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
  178. assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
  179. List<String> paths = new ArrayList<>();
  180. paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
  181. paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
  182. paths.add( "target/test-repository/com/example/test/test-artifact-root" );
  183. deleteTestArtifactWithParent( paths );
  184. }
  185. @Test
  186. public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
  187. throws Exception
  188. {
  189. // remove configuration
  190. Configuration config = configuration.getConfiguration();
  191. RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById( TEST_REMOTE_REPO_ID );
  192. config.removeRemoteRepository( remoteRepo );
  193. configuration.save( config );
  194. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-module-a",
  195. "target/test-repository/com/example/test/test-artifact-module-a" );
  196. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-root",
  197. "target/test-repository/com/example/test/test-artifact-root" );
  198. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
  199. "target/test-repository/com/example/test/test-artifact-parent" );
  200. ReadMetadataRequest readMetadataRequest =
  201. new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "com.example.test" ).projectId(
  202. "test-artifact-module-a" ).projectVersion( "1.0" );
  203. ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
  204. assertEquals( "1.0", metadata.getId() );
  205. MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
  206. assertNotNull( facet );
  207. assertEquals( "com.example.test", facet.getGroupId() );
  208. assertEquals( "test-artifact-module-a", facet.getArtifactId() );
  209. assertEquals( "jar", facet.getPackaging() );
  210. List<String> paths = new ArrayList<>();
  211. paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
  212. paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
  213. paths.add( "target/test-repository/com/example/test/test-artifact-root" );
  214. deleteTestArtifactWithParent( paths );
  215. }
  216. @Test
  217. public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
  218. throws Exception
  219. {
  220. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-module-a",
  221. "target/test-repository/com/example/test/test-artifact-module-a" );
  222. ReadMetadataRequest readMetadataRequest =
  223. new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "com.example.test" ).projectId(
  224. "missing-parent" ).projectVersion( "1.1" );
  225. ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
  226. assertEquals( "1.1", metadata.getId() );
  227. MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
  228. assertNotNull( facet );
  229. assertEquals( "com.example.test", facet.getGroupId() );
  230. assertEquals( "missing-parent", facet.getArtifactId() );
  231. assertEquals( "jar", facet.getPackaging() );
  232. List<String> paths = new ArrayList<>();
  233. paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
  234. paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
  235. paths.add( "target/test-repository/com/example/test/test-artifact-root" );
  236. deleteTestArtifactWithParent( paths );
  237. }
  238. @Test
  239. public void testGetProjectVersionMetadataWithParentSnapshotVersion()
  240. throws Exception
  241. {
  242. copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
  243. "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
  244. copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-root",
  245. "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
  246. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
  247. "target/test-repositorys/com/example/test/test-artifact-parent" );
  248. ReadMetadataRequest readMetadataRequest =
  249. new ReadMetadataRequest( TEST_SNAP_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
  250. "1.1-SNAPSHOT" );
  251. ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
  252. MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
  253. assertEquals( "jar", facet.getPackaging() );
  254. assertEquals( "com.example.test", facet.getParent().getGroupId() );
  255. assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
  256. assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
  257. assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
  258. assertEquals( "com.example.test", facet.getGroupId() );
  259. assertNull( metadata.getCiManagement() );
  260. assertNotNull( metadata.getDescription() );
  261. checkApacheLicense( metadata );
  262. assertEquals( "1.1-SNAPSHOT", metadata.getId() );
  263. assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
  264. String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
  265. assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
  266. assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
  267. assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
  268. List<Dependency> dependencies = metadata.getDependencies();
  269. assertEquals( 2, dependencies.size() );
  270. assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
  271. assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
  272. List<String> paths = new ArrayList<>();
  273. paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
  274. paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
  275. deleteTestArtifactWithParent( paths );
  276. }
  277. @Test
  278. public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed()
  279. throws Exception
  280. {
  281. copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
  282. "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
  283. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
  284. "target/test-repositorys/com/example/test/test-artifact-parent" );
  285. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-snapshot-artifact-root",
  286. "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
  287. ReadMetadataRequest readMetadataRequest =
  288. new ReadMetadataRequest().repositoryId( TEST_SNAP_REPO_ID ).namespace( "com.example.test" ).projectId(
  289. "test-snapshot-artifact-module-a" ).projectVersion( "1.1-SNAPSHOT" );
  290. ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
  291. MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
  292. assertEquals( "jar", facet.getPackaging() );
  293. assertEquals( "com.example.test", facet.getParent().getGroupId() );
  294. assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
  295. assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
  296. assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
  297. assertEquals( "com.example.test", facet.getGroupId() );
  298. assertNull( metadata.getCiManagement() );
  299. assertNotNull( metadata.getDescription() );
  300. checkApacheLicense( metadata );
  301. assertEquals( "1.1-SNAPSHOT", metadata.getId() );
  302. assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
  303. String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
  304. assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
  305. assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
  306. assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
  307. List<Dependency> dependencies = metadata.getDependencies();
  308. assertEquals( 2, dependencies.size() );
  309. assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
  310. assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
  311. List<String> paths = new ArrayList<>();
  312. paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
  313. paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
  314. deleteTestArtifactWithParent( paths );
  315. }
  316. @Test
  317. public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed2()
  318. throws Exception
  319. {
  320. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-module-b",
  321. "target/test-repository/com/example/test/test-artifact-module-b" );
  322. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
  323. "target/test-repository/com/example/test/test-artifact-parent" );
  324. copyTestArtifactWithParent( "src/test/resources/com/example/test/test-snapshot-artifact-root",
  325. "target/test-repository/com/example/test/test-snapshot-artifact-root" );
  326. ReadMetadataRequest readMetadataRequest =
  327. new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "com.example.test" ).projectId(
  328. "test-artifact-module-b" ).projectVersion( "1.0" );
  329. ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
  330. MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
  331. assertEquals( "jar", facet.getPackaging() );
  332. assertEquals( "com.example.test", facet.getParent().getGroupId() );
  333. assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
  334. assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
  335. assertEquals( "test-artifact-module-b", facet.getArtifactId() );
  336. assertEquals( "com.example.test", facet.getGroupId() );
  337. assertNull( metadata.getCiManagement() );
  338. assertNotNull( metadata.getDescription() );
  339. checkApacheLicense( metadata );
  340. assertEquals( "1.0", metadata.getId() );
  341. assertEquals( "Test Artifact :: Module B", metadata.getName() );
  342. String path = "test-snapshot-artifact/trunk/test-artifact-module-b";
  343. assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
  344. assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
  345. assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
  346. List<Dependency> dependencies = metadata.getDependencies();
  347. assertEquals( 2, dependencies.size() );
  348. assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
  349. assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
  350. List<String> paths = new ArrayList<>();
  351. paths.add( "target/test-repository/com/example/test/test-artifact-module-b" );
  352. paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
  353. deleteTestArtifactWithParent( paths );
  354. }
  355. // Tests for MRM-1411 - END
  356. private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
  357. {
  358. assertDependency( dependency, groupId, artifactId, version, "compile" );
  359. }
  360. private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
  361. String scope )
  362. {
  363. assertEquals( artifactId, dependency.getArtifactId() );
  364. assertEquals( "jar", dependency.getType() );
  365. assertEquals( version, dependency.getVersion() );
  366. assertEquals( groupId, dependency.getNamespace() );
  367. assertEquals( scope, dependency.getScope() );
  368. assertNull( dependency.getClassifier() );
  369. assertNull( dependency.getSystemPath() );
  370. }
  371. private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
  372. {
  373. assertEquals( id, artifact.getId() );
  374. assertEquals( md5, artifact.getMd5() );
  375. assertEquals( sha1, artifact.getSha1() );
  376. assertEquals( size, artifact.getSize() );
  377. assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
  378. assertEquals( "plexus-spring", artifact.getProject() );
  379. assertEquals( "1.2", artifact.getVersion() );
  380. assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
  381. }
  382. private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
  383. String unsubscribe, List<String> otherArchives, boolean allowPost )
  384. {
  385. assertEquals( archive, mailingList.getMainArchiveUrl() );
  386. if ( allowPost )
  387. {
  388. assertEquals( post, mailingList.getPostAddress() );
  389. }
  390. else
  391. {
  392. assertNull( mailingList.getPostAddress() );
  393. }
  394. assertEquals( subscribe, mailingList.getSubscribeAddress() );
  395. assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
  396. assertEquals( name, mailingList.getName() );
  397. assertEquals( otherArchives, mailingList.getOtherArchives() );
  398. }
  399. private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
  400. String nabbleUrl )
  401. {
  402. List<String> otherArchives = new ArrayList<>();
  403. otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
  404. if ( nabbleUrl != null )
  405. {
  406. otherArchives.add( nabbleUrl );
  407. }
  408. otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
  409. assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
  410. prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
  411. prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
  412. }
  413. private void checkApacheLicense( ProjectVersionMetadata metadata )
  414. {
  415. assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
  416. "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
  417. metadata.getLicenses() );
  418. }
  419. private void checkOrganizationApache( ProjectVersionMetadata metadata )
  420. {
  421. assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
  422. assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
  423. }
  424. private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
  425. throws IOException
  426. {
  427. for ( String path : pathsToBeDeleted )
  428. {
  429. Path dir = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path );
  430. org.apache.archiva.common.utils.FileUtils.deleteDirectory( dir );
  431. assertFalse( Files.exists(dir) );
  432. }
  433. Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
  434. Path parentPom = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
  435. Path rootPom = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
  436. org.apache.archiva.common.utils.FileUtils.deleteDirectory( dest );
  437. org.apache.archiva.common.utils.FileUtils.deleteDirectory( parentPom );
  438. org.apache.archiva.common.utils.FileUtils.deleteDirectory( rootPom );
  439. assertFalse( Files.exists(dest) );
  440. assertFalse( Files.exists(parentPom) );
  441. assertFalse( Files.exists(rootPom) );
  442. }
  443. private Path copyTestArtifactWithParent( String srcPath, String destPath )
  444. throws IOException
  445. {
  446. Path src = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), srcPath );
  447. Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), destPath );
  448. FileUtils.copyDirectory( src.toFile(), dest.toFile() );
  449. assertTrue( Files.exists(dest) );
  450. return dest;
  451. }
  452. }