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.

AbstractRepositoryLayerTestCase.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package org.apache.archiva.maven.repository;
  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 org.apache.archiva.repository.ManagedRepositoryContent;
  20. import org.apache.archiva.repository.RemoteRepositoryContent;
  21. import org.apache.archiva.repository.RepositoryContentProvider;
  22. import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
  23. import org.junit.Rule;
  24. import org.junit.rules.TestName;
  25. import org.junit.runner.RunWith;
  26. import org.springframework.context.ApplicationContext;
  27. import org.springframework.test.context.ContextConfiguration;
  28. import javax.inject.Inject;
  29. import java.io.IOException;
  30. import java.net.URI;
  31. import java.net.URISyntaxException;
  32. import java.nio.file.Path;
  33. import java.nio.file.Paths;
  34. /**
  35. * AbstractRepositoryLayerTestCase
  36. *
  37. *
  38. */
  39. @RunWith( ArchivaSpringJUnit4ClassRunner.class )
  40. @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-repository-conf.xml" } )
  41. public abstract class AbstractRepositoryLayerTestCase
  42. {
  43. @Rule
  44. public TestName name = new TestName();
  45. @Inject
  46. protected ApplicationContext applicationContext;
  47. protected MavenManagedRepository createRepository( String id, String name, Path location ) throws IOException {
  48. MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, location.getParent().toAbsolutePath());
  49. repo.setLocation( location.toAbsolutePath().toUri() );
  50. return repo;
  51. }
  52. protected MavenRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException, IOException {
  53. MavenRemoteRepository repo = MavenRemoteRepository.newLocalInstance(id, name, Paths.get("target/remotes"));
  54. repo.setLocation( new URI( url ) );
  55. return repo;
  56. }
  57. protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, Path location,
  58. String layout )
  59. throws Exception
  60. {
  61. MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, location.getParent() );
  62. repo.setLocation( location.toAbsolutePath().toUri() );
  63. repo.setLayout( layout );
  64. RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
  65. ManagedRepositoryContent repoContent =
  66. provider.createManagedContent( repo );
  67. return repoContent;
  68. }
  69. protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
  70. throws Exception
  71. {
  72. MavenRemoteRepository repo = MavenRemoteRepository.newLocalInstance(id, name, Paths.get("target/remotes"));
  73. repo.setLocation( new URI( url ) );
  74. repo.setLayout( layout );
  75. RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
  76. RemoteRepositoryContent repoContent =
  77. provider.createRemoteContent( repo );
  78. return repoContent;
  79. }
  80. }