1 package org.apache.archiva.rest.api.v2.model.map;
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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.filelock.DefaultFileLockManager;
22 import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration;
23 import org.apache.archiva.repository.EditableManagedRepository;
24 import org.apache.archiva.repository.ReleaseScheme;
25 import org.apache.archiva.repository.RepositoryType;
26 import org.apache.archiva.repository.UnsupportedURIException;
27 import org.apache.archiva.repository.base.managed.BasicManagedRepository;
28 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
29 import org.apache.archiva.repository.features.IndexCreationFeature;
30 import org.apache.archiva.repository.features.StagingRepositoryFeature;
31 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
32 import org.apache.archiva.rest.api.v2.model.MavenManagedRepository;
33 import org.apache.archiva.rest.api.v2.model.Repository;
34 import org.junit.jupiter.api.Test;
36 import java.io.IOException;
38 import java.net.URISyntaxException;
39 import java.nio.file.Files;
40 import java.nio.file.Path;
41 import java.time.Period;
42 import java.util.Arrays;
43 import java.util.Locale;
45 import static org.junit.jupiter.api.Assertions.*;
48 * @author Martin Schreier <martin_s@apache.org>
50 class MavenRepositoryMapperTest
56 MavenRepositoryMapper mapper = new MavenRepositoryMapper( );
57 MavenManagedRepository repo = new MavenManagedRepository( );
58 repo.setId( "repo01" );
59 repo.setName( "Repo 01" );
60 repo.setDescription( "This is repo 01" );
61 repo.setLocation( "/data/repo01" );
62 repo.setHasStagingRepository( true );
63 repo.setSchedulingDefinition( "0,1,2 * * * *" );
64 repo.setPackedIndexPath( ".index" );
65 repo.setIndexPath( ".indexer" );
66 repo.setIndex( true );
67 repo.setDeleteSnapshotsOfRelease( false );
68 repo.setBlocksRedeployments( false );
69 repo.setReleaseSchemes( Arrays.asList( ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name() ) );
70 repo.setCharacteristic( Repository.CHARACTERISTIC_MANAGED );
71 repo.setScanned( true );
72 repo.setRetentionPeriod( Period.ofDays( 10 ) );
73 repo.setRetentionCount( 15 );
74 repo.setSkipPackedIndexCreation( false );
75 repo.setStagingRepository( "stage-repo01" );
76 ManagedRepositoryConfiguration result = mapper.map( repo );
78 assertNotNull( result );
79 assertEquals( "repo01", result.getId( ) );
80 assertEquals( "Repo 01", result.getName( ) );
81 assertEquals( "This is repo 01", result.getDescription( ) );
82 assertEquals( "/data/repo01", result.getLocation( ) );
83 assertTrue( result.isStageRepoNeeded( ) );
84 assertEquals( "0,1,2 * * * *", result.getRefreshCronExpression( ) );
85 assertEquals( ".indexer", result.getIndexDir( ) );
86 assertEquals( ".index", result.getPackedIndexDir( ) );
87 assertFalse( result.isDeleteReleasedSnapshots( ) );
88 assertFalse( result.isBlockRedeployments( ) );
89 assertTrue( result.isSnapshots( ) );
90 assertTrue( result.isReleases( ) );
91 assertTrue( result.isScanned( ) );
92 assertEquals( 10, result.getRetentionPeriod( ) );
93 assertEquals( 15, result.getRetentionCount( ) );
94 assertFalse( result.isSkipPackedIndexCreation( ) );
101 MavenRepositoryMapper mapper = new MavenRepositoryMapper( );
102 MavenManagedRepository repo = new MavenManagedRepository( );
103 ManagedRepositoryConfiguration result = new ManagedRepositoryConfiguration( );
104 repo.setId( "repo01" );
105 repo.setName( "Repo 01" );
106 repo.setDescription( "This is repo 01" );
107 repo.setLocation( "/data/repo01" );
108 repo.setHasStagingRepository( true );
109 repo.setSchedulingDefinition( "0,1,2 * * * *" );
110 repo.setPackedIndexPath( ".index" );
111 repo.setIndexPath( ".indexer" );
112 repo.setIndex( true );
113 repo.setDeleteSnapshotsOfRelease( false );
114 repo.setBlocksRedeployments( false );
115 repo.setReleaseSchemes( Arrays.asList( ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name() ) );
116 repo.setCharacteristic( Repository.CHARACTERISTIC_MANAGED );
117 repo.setScanned( true );
118 repo.setRetentionPeriod( Period.ofDays( 10 ) );
119 repo.setRetentionCount( 15 );
120 repo.setSkipPackedIndexCreation( false );
121 repo.setStagingRepository( "stage-repo01" );
122 mapper.update( repo, result );
124 assertNotNull( result );
125 assertEquals( "repo01", result.getId( ) );
126 assertEquals( "Repo 01", result.getName( ) );
127 assertEquals( "This is repo 01", result.getDescription( ) );
128 assertEquals( "/data/repo01", result.getLocation( ) );
129 assertTrue( result.isStageRepoNeeded( ) );
130 assertEquals( "0,1,2 * * * *", result.getRefreshCronExpression( ) );
131 assertEquals( ".indexer", result.getIndexDir( ) );
132 assertEquals( ".index", result.getPackedIndexDir( ) );
133 assertFalse( result.isDeleteReleasedSnapshots( ) );
134 assertFalse( result.isBlockRedeployments( ) );
135 assertTrue( result.isSnapshots( ) );
136 assertTrue( result.isReleases( ) );
137 assertTrue( result.isScanned( ) );
138 assertEquals( 10, result.getRetentionPeriod( ) );
139 assertEquals( 15, result.getRetentionCount( ) );
140 assertFalse( result.isSkipPackedIndexCreation( ) );
144 void reverseMap( ) throws IOException, URISyntaxException, UnsupportedURIException
146 MavenRepositoryMapper mapper = new MavenRepositoryMapper( );
148 Path tmpDir = Files.createTempDirectory( "mapper-test" );
149 FilesystemStorage fsStorage = new FilesystemStorage( tmpDir, new DefaultFileLockManager( ) );
150 EditableManagedRepository repository = new BasicManagedRepository( Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage );
151 repository.setDescription( Locale.getDefault(), "This is repo 02" );
152 repository.setBlocksRedeployment( false );
153 repository.setLocation( new URI("test-path") );
154 repository.setScanned( true );
155 repository.setLayout( "maven2" );
156 repository.setSchedulingDefinition( "* 3,5,10 * * *" );
157 IndexCreationFeature icf = repository.getFeature( IndexCreationFeature.class );
158 icf.setIndexPath( new URI( ".indexer" ) );
159 icf.setPackedIndexPath( new URI( ".index" ) );
160 icf.setSkipPackedIndexCreation( false );
161 ArtifactCleanupFeature acf = repository.getFeature( ArtifactCleanupFeature.class );
162 acf.setDeleteReleasedSnapshots( false );
163 acf.setRetentionPeriod( Period.ofDays( 5 ) );
164 acf.setRetentionCount( 17 );
165 StagingRepositoryFeature srf = repository.getFeature( StagingRepositoryFeature.class );
166 srf.setStageRepoNeeded( false );
168 MavenManagedRepository result = mapper.reverseMap( repository );
169 assertEquals( "repo02", result.getId( ) );
170 assertEquals( "Repo 02", result.getName( ) );
171 assertEquals( "This is repo 02", result.getDescription( ) );
172 assertFalse( result.isBlocksRedeployments( ) );
173 assertEquals( "test-path", result.getLocation( ) );
174 assertTrue( result.isScanned( ) );
175 assertEquals( "maven2", result.getLayout( ) );
176 assertEquals( "* 3,5,10 * * *", result.getSchedulingDefinition( ) );
177 assertEquals( ".indexer", result.getIndexPath( ) );
178 assertEquals( ".index", result.getPackedIndexPath( ) );
179 assertFalse( result.isSkipPackedIndexCreation( ) );
180 assertFalse( result.isDeleteSnapshotsOfRelease( ) );
181 assertEquals( Period.ofDays( 5 ), result.getRetentionPeriod( ) );
182 assertEquals( 17, result.getRetentionCount( ) );
183 assertFalse( result.hasStagingRepository( ) );
188 void reverseUpdate( ) throws IOException, URISyntaxException, UnsupportedURIException
190 MavenRepositoryMapper mapper = new MavenRepositoryMapper( );
191 MavenManagedRepository result = new MavenManagedRepository( );
192 Path tmpDir = Files.createTempDirectory( "mapper-test" );
193 FilesystemStorage fsStorage = new FilesystemStorage( tmpDir, new DefaultFileLockManager( ) );
194 EditableManagedRepository repository = new BasicManagedRepository( Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage );
195 repository.setDescription( Locale.getDefault(), "This is repo 02" );
196 repository.setBlocksRedeployment( false );
197 repository.setLocation( new URI("test-path") );
198 repository.setScanned( true );
199 repository.setLayout( "maven2" );
200 repository.setSchedulingDefinition( "* 3,5,10 * * *" );
201 IndexCreationFeature icf = repository.getFeature( IndexCreationFeature.class );
202 icf.setIndexPath( new URI( ".indexer" ) );
203 icf.setPackedIndexPath( new URI( ".index" ) );
204 icf.setSkipPackedIndexCreation( false );
205 ArtifactCleanupFeature acf = repository.getFeature( ArtifactCleanupFeature.class );
206 acf.setDeleteReleasedSnapshots( false );
207 acf.setRetentionPeriod( Period.ofDays( 5 ) );
208 acf.setRetentionCount( 17 );
209 StagingRepositoryFeature srf = repository.getFeature( StagingRepositoryFeature.class );
210 srf.setStageRepoNeeded( false );
212 mapper.reverseUpdate( repository, result );
214 assertEquals( "repo02", result.getId( ) );
215 assertEquals( "Repo 02", result.getName( ) );
216 assertEquals( "This is repo 02", result.getDescription( ) );
217 assertFalse( result.isBlocksRedeployments( ) );
218 assertEquals( "test-path", result.getLocation( ) );
219 assertTrue( result.isScanned( ) );
220 assertEquals( "maven2", result.getLayout( ) );
221 assertEquals( "* 3,5,10 * * *", result.getSchedulingDefinition( ) );
222 assertEquals( ".indexer", result.getIndexPath( ) );
223 assertEquals( ".index", result.getPackedIndexPath( ) );
224 assertFalse( result.isSkipPackedIndexCreation( ) );
225 assertFalse( result.isDeleteSnapshotsOfRelease( ) );
226 assertEquals( Period.ofDays( 5 ), result.getRetentionPeriod( ) );
227 assertEquals( 17, result.getRetentionCount( ) );
228 assertFalse( result.hasStagingRepository( ) );