]> source.dussan.org Git - archiva.git/blob
dcb92399bf597c322378199b017b35404a3d5c8f
[archiva.git] /
1 package $package;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import org.apache.archiva.metadata.repository.MetadataRepository;
23 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
24 import org.apache.archiva.repository.base.managed.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;
34
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;
41
42 // import static org.mockito.Mockito.*;
43
44 /**
45  * <code>SimpleArtifactConsumerTest</code>
46  */
47 @RunWith(SpringJUnit4ClassRunner.class)
48 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
49 public class SimpleArtifactConsumerTest
50 {
51     @Inject
52     private SimpleArtifactConsumer consumer;
53
54     @Inject
55     private RepositoryRegistry repositoryRegistry;
56
57     @Inject
58     private RepositorySessionFactory repositorySessionFactory;
59
60     private BasicManagedRepository testRepository;
61
62     private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
63
64     private MetadataRepository metadataRepository;
65
66     @Before
67     public void setUp()
68         throws Exception
69     {
70         setUpMockRepository();
71     }
72
73     private void setUpMockRepository()
74         throws IOException, RepositoryException
75     {
76         Path repoDir = Paths.get( "target/test-consumer-repo" );
77         Files.createDirectories( repoDir );
78         repoDir.toFile().deleteOnExit();
79
80         testRepository = BasicManagedRepository.newFilesystemInstance("test-consumer-repository","Test-Consumer-Repository", Paths.get("target/repositories") );
81         testRepository.setLocation( repoDir.toAbsolutePath().toUri() );
82
83         repositoryRegistry.putRepository(testRepository);
84
85         // when( repositoryRegistry.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository );
86     }
87
88     @Test
89     public void testBeginScan()
90         throws Exception
91     {
92         log.info( "Beginning scan of repository [test-consumer-repository]" );
93
94         consumer.beginScan( testRepository, new Date() );
95     }
96
97     @Test
98     public void testProcessFile()
99         throws Exception
100     {
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" );
104
105     }
106
107 }