Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AbstractRepositoryLayerTestCase.java 3.6KB

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