1 package org.apache.archiva.repository.maven2;
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.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;
40 import javax.inject.Inject;
41 import javax.inject.Named;
42 import java.time.Period;
44 import static org.junit.Assert.*;
47 * @author Martin Stockhammer <martin_s@apache.org>
49 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
50 @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
51 public class MavenRepositoryProviderTest
55 @Named( "archivaConfiguration#default" )
56 ArchivaConfiguration archivaConfiguration;
58 MavenRepositoryProvider provider;
65 provider = new MavenRepositoryProvider();
69 public void provides( ) throws Exception
71 assertEquals(1, provider.provides().size());
72 assertEquals( RepositoryType.MAVEN, provider.provides().iterator().next());
76 public void createManagedInstance( ) throws Exception
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());
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());
102 StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature( StagingRepositoryFeature.class ).get();
103 assertFalse(stagingRepositoryFeature.isStageRepoNeeded());
104 assertNull(stagingRepositoryFeature.getStagingRepository());
110 public void createRemoteInstance( ) throws Exception
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());
125 ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature( ArtifactCleanupFeature.class ).get( );
126 throw new Exception("artifactCleanupFeature should not be available");
127 } catch ( UnsupportedFeatureException e ) {
133 IndexCreationFeature indexCreationFeature = mr.getFeature( IndexCreationFeature.class ).get( );
134 throw new Exception("indexCreationFeature should not be available");
135 } catch (UnsupportedFeatureException e) {
140 StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature( StagingRepositoryFeature.class ).get( );
141 throw new Exception("stagingRepositoryFeature should not be available");
142 } catch (UnsupportedFeatureException e) {
145 RemoteIndexFeature remoteIndexFeature = mr.getFeature( RemoteIndexFeature.class ).get();
146 assertNull(remoteIndexFeature.getProxyId());