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.stats.RepositoryStatisticsManager;
27 import org.apache.archiva.mock.MockRepositorySessionFactory;
28 import org.apache.archiva.redback.components.taskqueue.execution.TaskExecutor;
29 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
30 import org.apache.commons.lang.StringUtils;
31 import org.codehaus.plexus.util.FileUtils;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.runner.RunWith;
36 import org.springframework.test.annotation.DirtiesContext;
37 import org.springframework.test.context.ContextConfiguration;
39 import javax.inject.Inject;
40 import javax.inject.Named;
42 import java.util.Calendar;
43 import java.util.List;
45 import static org.mockito.Mockito.mock;
48 * ArchivaRepositoryScanningTaskExecutorPhase1Test
50 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
51 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
52 @DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
53 public abstract class AbstractArchivaRepositoryScanningTaskExecutorTest
57 @Named( value = "taskExecutor#test-repository-scanning" )
58 protected TaskExecutor taskExecutor;
61 @Named( value = "archivaConfiguration#test-repository-scanning" )
62 protected ArchivaConfiguration archivaConfig;
65 @Named( value = "repositoryStatisticsManager#test" )
66 protected RepositoryStatisticsManager repositoryStatisticsManager;
69 @Named( value = "knownRepositoryContentConsumer#test-consumer" )
70 protected TestConsumer testConsumer;
73 @Named( value = "repositorySessionFactory#mock" )
74 private MockRepositorySessionFactory factory;
76 protected File repoDir;
78 protected static final String TEST_REPO_ID = "testRepo";
80 protected MetadataRepository metadataRepository;
89 File sourceRepoDir = new File( "./src/test/repositories/default-repository" );
90 repoDir = new File( "./target/default-repository" );
92 FileUtils.deleteDirectory( repoDir );
93 assertFalse( "Default Test Repository should not exist.", repoDir.exists() );
97 FileUtils.copyDirectoryStructure( sourceRepoDir, repoDir );
98 // set the timestamps to a time well in the past
99 Calendar cal = Calendar.getInstance();
100 cal.add( Calendar.YEAR, -1 );
101 FileUtils.getFiles( repoDir, "**", null ) //
102 .stream().forEach( file -> file.setLastModified( cal.getTimeInMillis() ) );
104 // TODO: test they are excluded instead
105 for ( String dir : FileUtils.getDirectoryNames( repoDir, "**/.svn", null, false ) )
107 FileUtils.deleteDirectory( new File( repoDir, dir ) );
110 assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
112 assertNotNull( archivaConfig );
115 ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
116 repositoryConfiguration.setId( TEST_REPO_ID );
117 repositoryConfiguration.setName( "Test Repository" );
118 repositoryConfiguration.setLocation( repoDir.getAbsolutePath() );
119 archivaConfig.getConfiguration().getManagedRepositories().clear();
120 archivaConfig.getConfiguration().addManagedRepository( repositoryConfiguration );
122 metadataRepository = mock( MetadataRepository.class );
124 factory.setRepository( metadataRepository );
129 public void tearDown()
132 FileUtils.deleteDirectory( repoDir );
134 assertFalse( repoDir.exists() );