]> source.dussan.org Git - archiva.git/blob
de7bd459d521c654f37eec32b0a0f676939175b1
[archiva.git] /
1 package org.apache.archiva.scheduler.repository;
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 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.model.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.codehaus.plexus.util.FileUtils;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.runner.RunWith;
34 import org.springframework.test.annotation.DirtiesContext;
35 import org.springframework.test.context.ContextConfiguration;
36
37 import javax.inject.Inject;
38 import javax.inject.Named;
39 import java.io.File;
40 import java.util.Calendar;
41
42 import static org.mockito.Mockito.mock;
43
44 /**
45  * ArchivaRepositoryScanningTaskExecutorPhase1Test
46  */
47 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
48 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
49 @DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
50 public abstract class AbstractArchivaRepositoryScanningTaskExecutorTest
51     extends TestCase
52 {
53     @Inject
54     @Named( value = "taskExecutor#test-repository-scanning" )
55     protected TaskExecutor taskExecutor;
56
57     @Inject
58     @Named( value = "archivaConfiguration#test-repository-scanning" )
59     protected ArchivaConfiguration archivaConfig;
60
61     @Inject
62     @Named( value = "repositoryStatisticsManager#test" )
63     protected RepositoryStatisticsManager repositoryStatisticsManager;
64
65     @Inject
66     @Named( value = "knownRepositoryContentConsumer#test-consumer" )
67     protected TestConsumer testConsumer;
68
69     @Inject
70     @Named( value = "repositorySessionFactory#mock" )
71     private MockRepositorySessionFactory factory;
72
73     protected File repoDir;
74
75     protected static final String TEST_REPO_ID = "testRepo";
76
77     protected MetadataRepository metadataRepository;
78
79     @Before
80     @Override
81     public void setUp()
82         throws Exception
83     {
84         super.setUp();
85
86         File sourceRepoDir = new File( "./src/test/repositories/default-repository" );
87         repoDir = new File( "./target/default-repository" );
88
89         FileUtils.deleteDirectory( repoDir );
90         assertFalse( "Default Test Repository should not exist.", repoDir.exists() );
91
92         repoDir.mkdir();
93
94         FileUtils.copyDirectoryStructure( sourceRepoDir, repoDir );
95         // set the timestamps to a time well in the past
96         Calendar cal = Calendar.getInstance();
97         cal.add( Calendar.YEAR, -1 );
98         FileUtils.getFiles( repoDir, "**", null ) //
99             .stream().forEach( file -> file.setLastModified( cal.getTimeInMillis() ) );
100
101         // TODO: test they are excluded instead
102         for ( String dir : FileUtils.getDirectoryNames( repoDir, "**/.svn", null, false ) )
103         {
104             FileUtils.deleteDirectory( new File( repoDir, dir ) );
105         }
106
107         assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
108
109         assertNotNull( archivaConfig );
110
111         // Create it
112         ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
113         repositoryConfiguration.setId( TEST_REPO_ID );
114         repositoryConfiguration.setName( "Test Repository" );
115         repositoryConfiguration.setLocation( repoDir.getAbsolutePath() );
116         archivaConfig.getConfiguration().getManagedRepositories().clear();
117         archivaConfig.getConfiguration().addManagedRepository( repositoryConfiguration );
118
119         metadataRepository = mock( MetadataRepository.class );
120
121         factory.setRepository( metadataRepository );
122     }
123
124     @After
125     @Override
126     public void tearDown()
127         throws Exception
128     {
129         FileUtils.deleteDirectory( repoDir );
130
131         assertFalse( repoDir.exists() );
132
133         super.tearDown();
134     }
135
136 }