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();
71 private void setUpMockRepository()
72 throws RepositoryAdminException
74 File repoDir = new File( "target/test-consumer-repo" );
76 repoDir.deleteOnExit();
78 testRepository = new ManagedRepository();
79 testRepository.setName( "Test-Consumer-Repository" );
80 testRepository.setId( "test-consumer-repository" );
81 testRepository.setLocation( repoDir.getAbsolutePath() );
83 when( managedRepositoryAdmin.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository );
87 public void testBeginScan()
90 log.info( "Beginning scan of repository [test-consumer-repository]" );
92 consumer.beginScan( testRepository, new Date() );
96 public void testProcessFile()
99 consumer.beginScan( testRepository, new Date() );
100 consumer.processFile( "org/simple/test/testartifact/testartifact/1.0/testartifact-1.0.pom" );
101 consumer.processFile( "org/simple/test/testartifact/testartifact/1.1/testartifact-1.1.pom" );