1 package org.apache.maven.archiva.web.action;
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
23 import java.io.IOException;
24 import java.text.SimpleDateFormat;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.Date;
29 import java.util.List;
30 import java.util.TimeZone;
32 import com.opensymphony.xwork2.Action;
33 import org.apache.archiva.checksum.ChecksumAlgorithm;
34 import org.apache.archiva.checksum.ChecksummedFile;
35 import org.apache.archiva.scheduler.ArchivaTaskScheduler;
36 import org.apache.commons.io.FileUtils;
37 import org.apache.commons.lang.StringUtils;
38 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
39 import org.apache.maven.archiva.configuration.Configuration;
40 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
41 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
42 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
43 import org.apache.maven.archiva.repository.RepositoryContentFactory;
44 import org.apache.maven.archiva.repository.RepositoryNotFoundException;
45 import org.apache.maven.archiva.repository.audit.AuditEvent;
46 import org.apache.maven.archiva.repository.audit.AuditListener;
47 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
48 import org.apache.maven.archiva.repository.metadata.MetadataTools;
49 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
50 import org.easymock.MockControl;
51 import org.easymock.classextension.MockClassControl;
56 public class UploadActionTest
57 extends PlexusInSpringTestCase
59 private UploadAction uploadAction;
61 private ArchivaConfiguration archivaConfig;
63 private MockControl archivaConfigControl;
65 private RepositoryContentFactory repoFactory;
67 private MockControl repoFactoryControl;
69 private static final String REPOSITORY_ID = "test-repo";
71 private Configuration config;
78 MockControl schedulerControl = MockControl.createControl( ArchivaTaskScheduler.class );
79 ArchivaTaskScheduler scheduler = (ArchivaTaskScheduler) schedulerControl.getMock();
81 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
82 archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
84 repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
85 repoFactory = (RepositoryContentFactory) repoFactoryControl.getMock();
87 uploadAction = new UploadAction();
88 uploadAction.setScheduler( scheduler );
89 uploadAction.setConfiguration( archivaConfig );
90 uploadAction.setRepositoryFactory( repoFactory );
92 File testRepo = new File( getBasedir(), "target/test-classes/test-repo" );
95 assertTrue( testRepo.exists() );
97 config = new Configuration();
98 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
99 repoConfig.setId( REPOSITORY_ID );
100 repoConfig.setLayout( "default" );
101 repoConfig.setLocation( testRepo.getPath() );
102 repoConfig.setName( REPOSITORY_ID );
103 repoConfig.setBlockRedeployments( true );
104 config.addManagedRepository( repoConfig );
106 RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
107 repoScanning.setKnownContentConsumers( new ArrayList<String>() );
108 config.setRepositoryScanning( repoScanning );
111 public void tearDown()
114 File testRepo = new File( config.findManagedRepositoryById( REPOSITORY_ID ).getLocation() );
115 FileUtils.deleteDirectory( testRepo );
117 assertFalse( testRepo.exists() );
122 private void setUploadParameters( String version, String classifier, File artifact, File pomFile,
123 boolean generatePom )
125 uploadAction.setRepositoryId( REPOSITORY_ID );
126 uploadAction.setGroupId( "org.apache.archiva" );
127 uploadAction.setArtifactId( "artifact-upload" );
128 uploadAction.setVersion( version );
129 uploadAction.setPackaging( "jar" );
131 uploadAction.setClassifier( classifier );
132 uploadAction.setArtifact( artifact );
133 uploadAction.setPom( pomFile );
134 uploadAction.setGeneratePom( generatePom );
137 private void assertAllArtifactsIncludingSupportArtifactsArePresent( String repoLocation )
140 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
142 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ).exists() );
144 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ).exists() );
147 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
149 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
151 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
154 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
155 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
156 ".sha1" ).exists() );
157 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
161 private void verifyChecksums( String repoLocation )
164 // verify checksums of jar file
165 ChecksummedFile checksum = new ChecksummedFile(
166 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
167 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
168 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
170 String contents = FileUtils.readFileToString(
171 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ) );
172 assertTrue( StringUtils.contains( contents, sha1 ) );
174 contents = FileUtils.readFileToString(
175 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ) );
176 assertTrue( StringUtils.contains( contents, md5 ) );
178 // verify checksums of pom file
179 checksum = new ChecksummedFile(
180 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
181 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
182 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
184 contents = FileUtils.readFileToString(
185 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ) );
186 assertTrue( StringUtils.contains( contents, sha1 ) );
188 contents = FileUtils.readFileToString(
189 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ) );
190 assertTrue( StringUtils.contains( contents, md5 ) );
192 // verify checksums of metadata file
193 checksum = new ChecksummedFile(
194 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ) );
195 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
196 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
198 contents = FileUtils.readFileToString(
199 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".sha1" ) );
200 assertTrue( StringUtils.contains( contents, sha1 ) );
202 contents = FileUtils.readFileToString(
203 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ) );
204 assertTrue( StringUtils.contains( contents, md5 ) );
207 public void testArtifactUploadWithPomSuccessful()
210 setUploadParameters( "1.0", null, new File( getBasedir(),
211 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
212 new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
214 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
215 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
217 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
218 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
220 archivaConfigControl.replay();
221 repoFactoryControl.replay();
223 MockControl control = mockAuditLogs(
224 Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
225 "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
227 String returnString = uploadAction.doUpload();
228 assertEquals( Action.SUCCESS, returnString );
230 archivaConfigControl.verify();
231 repoFactoryControl.verify();
234 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
235 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
237 verifyChecksums( repoLocation );
240 private MockControl mockAuditLogs( List<String> resources )
242 return mockAuditLogs( AuditEvent.UPLOAD_FILE, resources );
245 private MockControl mockAuditLogs( String action, List<String> resources )
247 MockControl control = MockControl.createControl( AuditListener.class );
248 AuditListener listener = (AuditListener) control.getMock();
249 boolean matcherSet = false;
250 for ( String resource : resources )
252 listener.auditEvent( new AuditEvent( REPOSITORY_ID, "guest", resource, action ) );
255 control.setMatcher( new AuditEventArgumentsMatcher() );
261 uploadAction.setAuditListeners( Collections.singletonList( listener ) );
265 public void testArtifactUploadWithClassifier()
268 setUploadParameters( "1.0", "tests", new File( getBasedir(),
269 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
270 new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
272 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
273 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
275 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
276 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
278 archivaConfigControl.replay();
279 repoFactoryControl.replay();
281 MockControl control = mockAuditLogs(
282 Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar",
283 "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
285 String returnString = uploadAction.doUpload();
286 assertEquals( Action.SUCCESS, returnString );
288 archivaConfigControl.verify();
289 repoFactoryControl.verify();
292 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
293 assertTrue( new File( repoLocation,
294 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ).exists() );
295 assertTrue( new File( repoLocation,
296 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ).exists() );
297 assertTrue( new File( repoLocation,
298 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ).exists() );
301 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
303 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
305 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
308 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
309 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
310 ".sha1" ).exists() );
311 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
314 // verify checksums of jar file
315 ChecksummedFile checksum = new ChecksummedFile(
316 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ) );
317 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
318 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
320 String contents = FileUtils.readFileToString(
321 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ) );
322 assertTrue( StringUtils.contains( contents, sha1 ) );
324 contents = FileUtils.readFileToString(
325 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ) );
326 assertTrue( StringUtils.contains( contents, md5 ) );
328 // verify checksums of jar file
329 checksum = new ChecksummedFile(
330 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
331 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
332 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
334 contents = FileUtils.readFileToString(
335 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ) );
336 assertTrue( StringUtils.contains( contents, sha1 ) );
338 contents = FileUtils.readFileToString(
339 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ) );
340 assertTrue( StringUtils.contains( contents, md5 ) );
342 // verify checksums of metadata file
343 checksum = new ChecksummedFile(
344 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ) );
345 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
346 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
348 contents = FileUtils.readFileToString(
349 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".sha1" ) );
350 assertTrue( StringUtils.contains( contents, sha1 ) );
352 contents = FileUtils.readFileToString(
353 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ) );
354 assertTrue( StringUtils.contains( contents, md5 ) );
357 public void testArtifactUploadGeneratePomSuccessful()
360 setUploadParameters( "1.0", null, new File( getBasedir(),
361 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
364 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
365 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
367 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
368 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
370 archivaConfigControl.replay();
371 repoFactoryControl.replay();
373 MockControl control = mockAuditLogs(
374 Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
375 "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
377 String returnString = uploadAction.doUpload();
378 assertEquals( Action.SUCCESS, returnString );
380 archivaConfigControl.verify();
381 repoFactoryControl.verify();
384 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
385 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
387 verifyChecksums( repoLocation );
390 public void testArtifactUploadNoPomSuccessful()
393 setUploadParameters( "1.0", null, new File( getBasedir(),
394 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
397 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
398 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
400 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
401 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
403 archivaConfigControl.replay();
404 repoFactoryControl.replay();
406 MockControl control =
407 mockAuditLogs( Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
409 String returnString = uploadAction.doUpload();
410 assertEquals( Action.SUCCESS, returnString );
412 archivaConfigControl.verify();
413 repoFactoryControl.verify();
416 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
418 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
420 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ).exists() );
422 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ).exists() );
425 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
427 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
429 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
432 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
433 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
434 ".sha1" ).exists() );
435 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
438 // verify checksums of jar file
439 ChecksummedFile checksum = new ChecksummedFile(
440 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
441 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
442 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
444 String contents = FileUtils.readFileToString(
445 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ) );
446 assertTrue( StringUtils.contains( contents, sha1 ) );
448 contents = FileUtils.readFileToString(
449 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ) );
450 assertTrue( StringUtils.contains( contents, md5 ) );
452 // verify checksums of metadata file
453 checksum = new ChecksummedFile(
454 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ) );
455 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
456 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
458 contents = FileUtils.readFileToString(
459 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".sha1" ) );
460 assertTrue( StringUtils.contains( contents, sha1 ) );
462 contents = FileUtils.readFileToString(
463 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ) );
464 assertTrue( StringUtils.contains( contents, md5 ) );
467 public void testArtifactUploadFailedRepositoryNotFound()
470 setUploadParameters( "1.0", null, new File( getBasedir(),
471 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
474 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
475 repoFactoryControl.expectAndThrow( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ),
476 new RepositoryNotFoundException() );
478 archivaConfigControl.replay();
479 repoFactoryControl.replay();
481 String returnString = uploadAction.doUpload();
482 assertEquals( Action.ERROR, returnString );
484 archivaConfigControl.verify();
485 repoFactoryControl.verify();
487 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
489 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
492 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
495 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
498 public void testArtifactUploadSnapshots()
501 setUploadParameters( "1.0-SNAPSHOT", null, new File( getBasedir(),
502 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
505 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
506 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
508 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
509 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
511 archivaConfigControl.replay();
512 repoFactoryControl.replay();
514 SimpleDateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
515 fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
516 String timestamp = fmt.format( new Date() );
517 MockControl control = mockAuditLogs( Arrays.asList(
518 "org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + "-1.jar",
519 "org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + "-1.pom" ) );
521 String returnString = uploadAction.doUpload();
522 assertEquals( Action.SUCCESS, returnString );
524 archivaConfigControl.verify();
525 repoFactoryControl.verify();
528 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
529 assertEquals( 6, new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list().length );
532 new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
533 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
534 ".sha1" ).exists() );
535 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
539 public void testChecksumIsCorrectWhenArtifactIsReUploaded()
542 setUploadParameters( "1.0", null, new File( getBasedir(),
543 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
546 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
547 ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
548 repoConfig.setBlockRedeployments( false );
549 content.setRepository( repoConfig );
551 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
552 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
554 archivaConfigControl.replay();
555 repoFactoryControl.replay();
557 String returnString = uploadAction.doUpload();
558 assertEquals( Action.SUCCESS, returnString );
560 archivaConfigControl.verify();
561 repoFactoryControl.verify();
563 archivaConfigControl.reset();
564 repoFactoryControl.reset();
566 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
567 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
569 verifyChecksums( repoLocation );
571 // RE-upload artifact
572 setUploadParameters( "1.0", null, new File( getBasedir(),
573 "target/test-classes/upload-artifact-test/artifact-to-be-reuploaded.jar" ),
576 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
577 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
579 archivaConfigControl.replay();
580 repoFactoryControl.replay();
582 // TODO: track modifications?
583 // MockControl control = mockAuditLogs( AuditEvent.MODIFY_FILE, Arrays.asList(
584 MockControl control = mockAuditLogs(
585 Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
586 "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
588 returnString = uploadAction.doUpload();
589 assertEquals( Action.SUCCESS, returnString );
591 archivaConfigControl.verify();
592 repoFactoryControl.verify();
595 repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
596 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
598 verifyChecksums( repoLocation );
601 public void testUploadArtifactAlreadyExistingRedeploymentsBlocked()
604 setUploadParameters( "1.0", null, new File( getBasedir(),
605 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
608 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
609 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
611 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
612 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );
614 archivaConfigControl.replay();
615 repoFactoryControl.replay();
617 String returnString = uploadAction.doUpload();
618 assertEquals( Action.SUCCESS, returnString );
620 setUploadParameters( "1.0", null, new File( getBasedir(),
621 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
624 MockControl control = mockAuditLogs( Collections.<String>emptyList() );
626 returnString = uploadAction.doUpload();
627 assertEquals( Action.ERROR, returnString );
629 archivaConfigControl.verify();
630 repoFactoryControl.verify();
633 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
634 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
636 verifyChecksums( repoLocation );
639 public void testUploadArtifactAlreadyExistingRedeploymentsAllowed()
642 setUploadParameters( "1.0", null, new File( getBasedir(),
643 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
646 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
647 ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
648 repoConfig.setBlockRedeployments( false );
649 content.setRepository( repoConfig );
651 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
652 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );
654 archivaConfigControl.replay();
655 repoFactoryControl.replay();
657 String returnString = uploadAction.doUpload();
658 assertEquals( Action.SUCCESS, returnString );
660 setUploadParameters( "1.0", null, new File( getBasedir(),
661 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
664 // TODO: track modifications?
665 // MockControl control = mockAuditLogs( AuditEvent.MODIFY_FILE, Arrays.asList(
666 MockControl control = mockAuditLogs(
667 Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
668 "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
670 returnString = uploadAction.doUpload();
671 assertEquals( Action.SUCCESS, returnString );
673 archivaConfigControl.verify();
674 repoFactoryControl.verify();
677 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
678 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
680 verifyChecksums( repoLocation );