]> source.dussan.org Git - archiva.git/blob
9f3f2f3f55c615c991adc8a886de5797aea1eef0
[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.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;
37
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;
44
45 // import static org.mockito.Mockito.*;
46
47 /**
48  * <code>SimpleArtifactConsumerTest</code>
49  */
50 @RunWith(SpringJUnit4ClassRunner.class)
51 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
52 public class SimpleArtifactConsumerTest
53 {
54     @Inject
55     private SimpleArtifactConsumer consumer;
56
57     @Inject
58     private ArchivaRepositoryRegistry repositoryRegistry;
59
60     @SuppressWarnings( "unused" )
61     @Inject
62     private ManagedRepositoryHandler managedRepositoryHandler;
63
64     @SuppressWarnings( "unused" )
65     @Inject
66     private org.apache.archiva.repository.base.group.RepositoryGroupHandler repositoryGroupHandler;
67
68     @Inject
69     private RepositorySessionFactory repositorySessionFactory;
70
71     private BasicManagedRepository testRepository;
72
73     private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
74
75     private MetadataRepository metadataRepository;
76
77     @Before
78     public void setUp()
79         throws Exception
80     {
81         setUpMockRepository();
82     }
83
84     @After
85     public void tearDown() {
86         try
87         {
88             repositoryRegistry.removeRepository( "test-consumer-repository" );
89         } catch (Throwable ex) {
90             log.error( "Could not remove repository: {}", ex.getMessage( ) );
91         }
92     }
93
94     private void setUpMockRepository()
95         throws IOException, RepositoryException
96     {
97         ((ArchivaRepositoryRegistry)repositoryRegistry).setIgnoreIndexing( true );
98         Path repoDir = Paths.get( "target/test-consumer-repo" );
99         Files.createDirectories( repoDir );
100         repoDir.toFile().deleteOnExit();
101
102         testRepository = BasicManagedRepository.newFilesystemInstance("test-consumer-repository","Test-Consumer-Repository", Paths.get("target/repositories") );
103         testRepository.setLocation( repoDir.toAbsolutePath().toUri() );
104
105         repositoryRegistry.putRepository(testRepository);
106
107         // when( repositoryRegistry.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository );
108     }
109
110     @Test
111     public void testBeginScan()
112         throws Exception
113     {
114         log.info( "Beginning scan of repository [test-consumer-repository]" );
115
116         consumer.beginScan( testRepository, new Date() );
117     }
118
119     @Test
120     public void testProcessFile()
121         throws Exception
122     {
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" );
126
127     }
128
129 }