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.BasicManagedRepository;
25 import org.apache.archiva.repository.RepositoryException;
26 import org.apache.archiva.repository.RepositoryRegistry;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
35 import javax.inject.Inject;
36 import java.io.IOException;
37 import java.nio.file.Files;
38 import java.nio.file.Path;
39 import java.nio.file.Paths;
40 import java.util.Date;
42 // import static org.mockito.Mockito.*;
45 * <code>SimpleArtifactConsumerTest</code>
47 @RunWith(SpringJUnit4ClassRunner.class)
48 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
49 public class SimpleArtifactConsumerTest
52 private SimpleArtifactConsumer consumer;
55 private RepositoryRegistry repositoryRegistry;
58 private RepositorySessionFactory repositorySessionFactory;
60 private BasicManagedRepository testRepository;
62 private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
64 private MetadataRepository metadataRepository;
70 setUpMockRepository();
73 private void setUpMockRepository()
74 throws IOException, RepositoryException
76 Path repoDir = Paths.get( "target/test-consumer-repo" );
77 Files.createDirectories( repoDir );
78 repoDir.toFile().deleteOnExit();
80 testRepository = BasicManagedRepository.newFilesystemInstance("test-consumer-repository","Test-Consumer-Repository", Paths.get("target/repositories") );
81 testRepository.setLocation( repoDir.toAbsolutePath().toUri() );
83 repositoryRegistry.putRepository(testRepository);
85 // when( repositoryRegistry.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository );
89 public void testBeginScan()
92 log.info( "Beginning scan of repository [test-consumer-repository]" );
94 consumer.beginScan( testRepository, new Date() );
98 public void testProcessFile()
101 consumer.beginScan( testRepository, new Date() );
102 consumer.processFile( "org/simple/test/testartifact/testartifact/1.0/testartifact-1.0.pom" );
103 consumer.processFile( "org/simple/test/testartifact/testartifact/1.1/testartifact-1.1.pom" );