]> source.dussan.org Git - archiva.git/blob
9a08f070b10fb977c24a2a023573eef841a33cd9
[archiva.git] /
1 package org.apache.archiva.repository.maven2;
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 org.apache.archiva.configuration.ArchivaConfiguration;
23 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
24 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
25 import org.apache.archiva.repository.ManagedRepository;
26 import org.apache.archiva.repository.ReleaseScheme;
27 import org.apache.archiva.repository.RemoteRepository;
28 import org.apache.archiva.repository.RepositoryType;
29 import org.apache.archiva.repository.UnsupportedFeatureException;
30 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
31 import org.apache.archiva.repository.features.IndexCreationFeature;
32 import org.apache.archiva.repository.features.RemoteIndexFeature;
33 import org.apache.archiva.repository.features.StagingRepositoryFeature;
34 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.springframework.test.context.ContextConfiguration;
39
40 import javax.inject.Inject;
41 import javax.inject.Named;
42 import java.time.Period;
43
44 import static org.junit.Assert.*;
45
46 /**
47  * @author Martin Stockhammer <martin_s@apache.org>
48  */
49 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
50 @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" }  )
51 public class MavenRepositoryProviderTest
52 {
53
54     @Inject
55     @Named( "archivaConfiguration#default" )
56     ArchivaConfiguration archivaConfiguration;
57
58     MavenRepositoryProvider provider;
59
60
61     @Before
62     public void setUp()
63         throws Exception
64     {
65         provider = new MavenRepositoryProvider();
66     }
67
68     @Test
69     public void provides( ) throws Exception
70     {
71         assertEquals(1, provider.provides().size());
72         assertEquals( RepositoryType.MAVEN, provider.provides().iterator().next());
73     }
74
75     @Test
76     public void createManagedInstance( ) throws Exception
77     {
78         assertNotNull(archivaConfiguration);
79         assertNotNull(archivaConfiguration.getConfiguration());
80         ManagedRepositoryConfiguration repo = archivaConfiguration.getConfiguration().getManagedRepositories().get(0);
81         ManagedRepository mr = provider.createManagedInstance( repo );
82         assertNotNull(mr.getLocation());
83         assertTrue(mr.getLocation().toString().endsWith( "/repositories/internal" ));
84         assertEquals("Archiva Managed Internal Repository", mr.getName());
85         assertEquals(1, mr.getActiveReleaseSchemes().size());
86         assertEquals( ReleaseScheme.RELEASE, mr.getActiveReleaseSchemes().iterator().next());
87         assertEquals("internal", mr.getId());
88         assertTrue(mr.blocksRedeployments());
89         assertEquals("0 0 * * * ?", mr.getSchedulingDefinition());
90         assertTrue(mr.isScanned());
91         ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature( ArtifactCleanupFeature.class ).get();
92         assertEquals( Period.ofDays( 30), artifactCleanupFeature.getRetentionTime());
93         assertFalse(artifactCleanupFeature.isDeleteReleasedSnapshots());
94         assertEquals(2, artifactCleanupFeature.getRetentionCount());
95
96         IndexCreationFeature indexCreationFeature = mr.getFeature( IndexCreationFeature.class ).get();
97         assertNotNull(indexCreationFeature.getIndexPath());
98         assertTrue(indexCreationFeature.getIndexPath().toString().endsWith("/repositories/internal/.indexer"));
99         assertTrue(indexCreationFeature.getIndexPath().isAbsolute());
100         assertFalse(indexCreationFeature.isSkipPackedIndexCreation());
101
102         StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature( StagingRepositoryFeature.class ).get();
103         assertFalse(stagingRepositoryFeature.isStageRepoNeeded());
104         assertNull(stagingRepositoryFeature.getStagingRepository());
105
106
107     }
108
109     @Test
110     public void createRemoteInstance( ) throws Exception
111     {
112         assertNotNull(archivaConfiguration);
113         assertNotNull(archivaConfiguration.getConfiguration());
114         RemoteRepositoryConfiguration repo = archivaConfiguration.getConfiguration().getRemoteRepositories().get(0);
115         RemoteRepository mr = provider.createRemoteInstance( repo );
116         assertNotNull(mr.getLocation());
117         assertEquals("https://repo.maven.apache.org/maven2", mr.getLocation().toString());
118         assertEquals("Central Repository", mr.getName());
119         assertEquals("central", mr.getId());
120         assertEquals("0 0 08 ? * SUN", mr.getSchedulingDefinition());
121         assertTrue(mr.isScanned());
122         assertNull(mr.getLoginCredentials());
123         try
124         {
125             ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature( ArtifactCleanupFeature.class ).get( );
126             throw new Exception("artifactCleanupFeature should not be available");
127         } catch ( UnsupportedFeatureException e ) {
128             // correct
129         }
130
131         try
132         {
133             IndexCreationFeature indexCreationFeature = mr.getFeature( IndexCreationFeature.class ).get( );
134             throw new Exception("indexCreationFeature should not be available");
135         } catch (UnsupportedFeatureException e) {
136             // correct
137         }
138         try
139         {
140             StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature( StagingRepositoryFeature.class ).get( );
141             throw new Exception("stagingRepositoryFeature should not be available");
142         } catch (UnsupportedFeatureException e) {
143             // correct
144         }
145         RemoteIndexFeature remoteIndexFeature = mr.getFeature( RemoteIndexFeature.class ).get();
146         assertNull(remoteIndexFeature.getProxyId());
147     }
148
149 }