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.

SimpleArtifactConsumerTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package $package;
  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.admin.model.RepositoryAdminException;
  21. import org.apache.archiva.repository.ManagedRepository;
  22. import org.apache.archiva.repository.BasicManagedRepository;
  23. import org.apache.archiva.repository.RepositoryRegistry;
  24. import org.apache.archiva.repository.RepositoryException;
  25. import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
  26. import org.apache.archiva.metadata.repository.MetadataRepository;
  27. import org.apache.archiva.metadata.repository.RepositorySession;
  28. import org.apache.archiva.metadata.repository.RepositorySessionFactory;
  29. import org.junit.Before;
  30. import org.junit.Test;
  31. import org.junit.runner.RunWith;
  32. import org.slf4j.Logger;
  33. import org.slf4j.LoggerFactory;
  34. import org.springframework.test.context.ContextConfiguration;
  35. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  36. import javax.inject.Inject;
  37. import java.io.IOException;
  38. import java.nio.file.Files;
  39. import java.nio.file.Path;
  40. import java.nio.file.Paths;
  41. import java.util.Date;
  42. import static org.mockito.Mockito.*;
  43. /**
  44. * <code>SimpleArtifactConsumerTest</code>
  45. */
  46. @RunWith(SpringJUnit4ClassRunner.class)
  47. @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
  48. public class SimpleArtifactConsumerTest
  49. {
  50. @Inject
  51. private SimpleArtifactConsumer consumer;
  52. @Inject
  53. private ManagedRepositoryAdmin managedRepositoryAdmin;
  54. @Inject
  55. private RepositoryRegistry repositoryRegistry;
  56. @Inject
  57. private RepositorySessionFactory repositorySessionFactory;
  58. private BasicManagedRepository testRepository;
  59. private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
  60. private MetadataRepository metadataRepository;
  61. @Before
  62. public void setUp()
  63. throws Exception
  64. {
  65. setUpMockRepository();
  66. }
  67. private void setUpMockRepository()
  68. throws RepositoryAdminException, IOException, RepositoryException
  69. {
  70. Path repoDir = Paths.get( "target/test-consumer-repo" );
  71. Files.createDirectories( repoDir );
  72. repoDir.toFile().deleteOnExit();
  73. testRepository = new BasicManagedRepository("test-consumer-repository","Test-Consumer-Repository" );
  74. testRepository.setLocation( repoDir.toAbsolutePath().toUri() );
  75. repositoryRegistry.putRepository(testRepository);
  76. // when( repositoryRegistry.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository );
  77. }
  78. @Test
  79. public void testBeginScan()
  80. throws Exception
  81. {
  82. log.info( "Beginning scan of repository [test-consumer-repository]" );
  83. consumer.beginScan( testRepository, new Date() );
  84. }
  85. @Test
  86. public void testProcessFile()
  87. throws Exception
  88. {
  89. consumer.beginScan( testRepository, new Date() );
  90. consumer.processFile( "org/simple/test/testartifact/testartifact/1.0/testartifact-1.0.pom" );
  91. consumer.processFile( "org/simple/test/testartifact/testartifact/1.1/testartifact-1.1.pom" );
  92. }
  93. }