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

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