4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.metadata.repository.MetadataRepository;
23 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
24 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
25 import org.apache.archiva.repository.base.managed.BasicManagedRepository;
26 import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
27 import org.apache.archiva.repository.RepositoryException;
28 import org.apache.archiva.repository.RepositoryRegistry;
29 import org.junit.Before;
30 import org.junit.After;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.test.context.ContextConfiguration;
36 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38 import javax.inject.Inject;
39 import java.io.IOException;
40 import java.nio.file.Files;
41 import java.nio.file.Path;
42 import java.nio.file.Paths;
43 import java.util.Date;
45 // import static org.mockito.Mockito.*;
48 * <code>SimpleArtifactConsumerTest</code>
50 @RunWith(SpringJUnit4ClassRunner.class)
51 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
52 public class SimpleArtifactConsumerTest
55 private SimpleArtifactConsumer consumer;
58 private ArchivaRepositoryRegistry repositoryRegistry;
60 @SuppressWarnings( "unused" )
62 private ManagedRepositoryHandler managedRepositoryHandler;
64 @SuppressWarnings( "unused" )
66 private org.apache.archiva.repository.base.group.RepositoryGroupHandler repositoryGroupHandler;
69 private RepositorySessionFactory repositorySessionFactory;
71 private BasicManagedRepository testRepository;
73 private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
75 private MetadataRepository metadataRepository;
81 setUpMockRepository();
85 public void tearDown() {
88 repositoryRegistry.removeRepository( "test-consumer-repository" );
89 } catch (Throwable ex) {
90 log.error( "Could not remove repository: {}", ex.getMessage( ) );
94 private void setUpMockRepository()
95 throws IOException, RepositoryException
97 ((ArchivaRepositoryRegistry)repositoryRegistry).setIgnoreIndexing( true );
98 Path repoDir = Paths.get( "target/test-consumer-repo" );
99 Files.createDirectories( repoDir );
100 repoDir.toFile().deleteOnExit();
102 testRepository = BasicManagedRepository.newFilesystemInstance("test-consumer-repository","Test-Consumer-Repository", Paths.get("target/repositories") );
103 testRepository.setLocation( repoDir.toAbsolutePath().toUri() );
105 repositoryRegistry.putRepository(testRepository);
107 // when( repositoryRegistry.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository );
111 public void testBeginScan()
114 log.info( "Beginning scan of repository [test-consumer-repository]" );
116 consumer.beginScan( testRepository, new Date() );
120 public void testProcessFile()
123 consumer.beginScan( testRepository, new Date() );
124 consumer.processFile( "org/simple/test/testartifact/testartifact/1.0/testartifact-1.0.pom" );
125 consumer.processFile( "org/simple/test/testartifact/testartifact/1.1/testartifact-1.1.pom" );