1 package org.apache.archiva.scheduler.repository;
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 junit.framework.TestCase;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.archiva.metadata.repository.MetadataRepository;
26 import org.apache.archiva.metadata.repository.TestRepositorySessionFactory;
27 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
28 import org.apache.archiva.redback.components.taskqueue.execution.TaskExecutor;
29 import org.codehaus.plexus.util.FileUtils;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.runner.RunWith;
33 import org.springframework.test.context.ContextConfiguration;
35 import javax.inject.Inject;
36 import javax.inject.Named;
38 import java.util.Calendar;
39 import java.util.List;
40 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
42 import static org.mockito.Mockito.mock;
45 * ArchivaRepositoryScanningTaskExecutorPhase1Test
49 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
50 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
51 public abstract class ArchivaRepositoryScanningTaskExecutorAbstractTest
55 @Named( value = "taskExecutor#test-repository-scanning" )
56 protected TaskExecutor taskExecutor;
59 @Named( value = "archivaConfiguration#test-repository-scanning" )
60 protected ArchivaConfiguration archivaConfig;
63 @Named( value = "repositoryStatisticsManager#test" )
64 protected RepositoryStatisticsManager repositoryStatisticsManager;
67 @Named( value = "knownRepositoryContentConsumer#test-consumer" )
68 protected TestConsumer testConsumer;
71 @Named( value = "repositorySessionFactory#test" )
72 private TestRepositorySessionFactory factory;
74 protected File repoDir;
76 protected static final String TEST_REPO_ID = "testRepo";
78 protected MetadataRepository metadataRepository;
87 File sourceRepoDir = new File( "./src/test/repositories/default-repository" );
88 repoDir = new File( "./target/default-repository" );
90 FileUtils.deleteDirectory( repoDir );
91 assertFalse( "Default Test Repository should not exist.", repoDir.exists() );
95 FileUtils.copyDirectoryStructure( sourceRepoDir, repoDir );
96 // set the timestamps to a time well in the past
97 Calendar cal = Calendar.getInstance();
98 cal.add( Calendar.YEAR, -1 );
99 for ( File f : (List<File>) FileUtils.getFiles( repoDir, "**", null ) )
101 f.setLastModified( cal.getTimeInMillis() );
103 // TODO: test they are excluded instead
104 for ( String dir : (List<String>) FileUtils.getDirectoryNames( repoDir, "**/.svn", null, false ) )
106 FileUtils.deleteDirectory( new File( repoDir, dir ) );
109 assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
111 assertNotNull( archivaConfig );
114 ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
115 repositoryConfiguration.setId( TEST_REPO_ID );
116 repositoryConfiguration.setName( "Test Repository" );
117 repositoryConfiguration.setLocation( repoDir.getAbsolutePath() );
118 archivaConfig.getConfiguration().getManagedRepositories().clear();
119 archivaConfig.getConfiguration().addManagedRepository( repositoryConfiguration );
121 metadataRepository = mock( MetadataRepository.class );
123 factory.setRepository( metadataRepository );
128 public void tearDown()
131 FileUtils.deleteDirectory( repoDir );
133 assertFalse( repoDir.exists() );