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

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