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.5KB

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