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.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ManagedRepository;
24 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
25 import org.apache.archiva.metadata.repository.MetadataRepository;
26 import org.apache.archiva.metadata.repository.RepositorySession;
27 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.test.context.ContextConfiguration;
34 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36 import javax.inject.Inject;
38 import java.util.Date;
40 import static org.mockito.Mockito.*;
43 * <code>SimpleArtifactConsumerTest</code>
45 @RunWith(SpringJUnit4ClassRunner.class)
46 @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
47 public class SimpleArtifactConsumerTest
50 private SimpleArtifactConsumer consumer;
53 private ManagedRepositoryAdmin managedRepositoryAdmin;
56 private RepositorySessionFactory repositorySessionFactory;
58 private ManagedRepository testRepository;
60 private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
62 private MetadataRepository metadataRepository;
68 setUpMockRepository();
70 RepositorySession repositorySession = mock( RepositorySession.class );
71 when( repositorySessionFactory.createSession() ).thenReturn( repositorySession );
73 metadataRepository = mock( MetadataRepository.class );
74 when( repositorySession.getRepository() ).thenReturn( metadataRepository );
77 private void setUpMockRepository()
78 throws RepositoryAdminException
80 File repoDir = new File( "target/test-consumer-repo" );
82 repoDir.deleteOnExit();
84 testRepository = new ManagedRepository();
85 testRepository.setName( "Test-Consumer-Repository" );
86 testRepository.setId( "test-consumer-repository" );
87 testRepository.setLocation( repoDir.getAbsolutePath() );
89 when( managedRepositoryAdmin.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository );
93 public void testBeginScan()
96 log.info( "Beginning scan of repository [test-consumer-repository]" );
98 consumer.beginScan( testRepository, new Date() );
102 public void testProcessFile()
105 consumer.beginScan( testRepository, new Date() );
106 consumer.processFile( "org/simple/test/testartifact/testartifact/1.0/testartifact-1.0.pom" );
107 consumer.processFile( "org/simple/test/testartifact/testartifact/1.1/testartifact-1.1.pom" );
109 verify( metadataRepository ).getArtifacts( testRepository.getId(), "org.simple.test.testartifact",
110 "testartifact", "1.0" );
111 verify( metadataRepository ).getArtifacts( testRepository.getId(), "org.simple.test.testartifact",
112 "testartifact", "1.1" );