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.util.ArrayList;
26 import org.apache.archiva.checksum.ChecksumAlgorithm;
27 import org.apache.archiva.checksum.ChecksummedFile;
28 import org.apache.commons.io.FileUtils;
29 import org.apache.commons.lang.StringUtils;
30 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
31 import org.apache.maven.archiva.configuration.Configuration;
32 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
33 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
34 import org.apache.maven.archiva.database.ArchivaAuditLogsDao;
35 import org.apache.maven.archiva.model.ArchivaAuditLogs;
36 import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
37 import org.apache.maven.archiva.model.SnapshotVersion;
38 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
39 import org.apache.maven.archiva.repository.RepositoryContentFactory;
40 import org.apache.maven.archiva.repository.RepositoryNotFoundException;
41 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
42 import org.apache.maven.archiva.repository.metadata.MetadataTools;
43 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
44 import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
45 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
46 import org.easymock.MockControl;
47 import org.easymock.classextension.MockClassControl;
49 import com.opensymphony.xwork2.Action;
54 public class UploadActionTest
55 extends PlexusInSpringTestCase
57 private ArchivaTaskScheduler scheduler;
59 private MockControl schedulerControl;
61 private UploadAction uploadAction;
63 private ArchivaConfiguration archivaConfig;
65 private MockControl archivaConfigControl;
67 private RepositoryContentFactory repoFactory;
69 private MockControl repoFactoryControl;
71 private ArchivaAuditLogsDao auditLogsDao;
73 private MockControl auditLogsDaoControl;
75 private static final String REPOSITORY_ID = "test-repo";
77 private Configuration config;
84 schedulerControl = MockControl.createControl( ArchivaTaskScheduler.class );
85 scheduler = (ArchivaTaskScheduler) schedulerControl.getMock();
87 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
88 archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
90 repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
91 repoFactory = (RepositoryContentFactory) repoFactoryControl.getMock();
93 auditLogsDaoControl = MockControl.createControl( ArchivaAuditLogsDao.class );
94 auditLogsDaoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
95 auditLogsDao = (ArchivaAuditLogsDao) auditLogsDaoControl.getMock();
97 uploadAction = new UploadAction();
98 uploadAction.setScheduler( scheduler );
99 uploadAction.setConfiguration( archivaConfig );
100 uploadAction.setRepositoryFactory( repoFactory );
101 uploadAction.setAuditLogsDao( auditLogsDao );
103 File testRepo = new File( getBasedir(), "target/test-classes/test-repo" );
106 assertTrue( testRepo.exists() );
108 config = new Configuration();
109 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
110 repoConfig.setId( REPOSITORY_ID );
111 repoConfig.setLayout( "default" );
112 repoConfig.setLocation( testRepo.getPath() );
113 repoConfig.setName( REPOSITORY_ID );
114 repoConfig.setBlockRedeployments( true );
115 config.addManagedRepository( repoConfig );
117 RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
118 repoScanning.setKnownContentConsumers( new ArrayList<String>() );
119 config.setRepositoryScanning( repoScanning );
122 public void tearDown()
125 File testRepo = new File( config.findManagedRepositoryById( REPOSITORY_ID ).getLocation() );
126 FileUtils.deleteDirectory( testRepo );
128 assertFalse( testRepo.exists() );
133 private void setUploadParameters( String version, String classifier, File artifact, File pomFile,
134 boolean generatePom )
136 uploadAction.setRepositoryId( REPOSITORY_ID );
137 uploadAction.setGroupId( "org.apache.archiva" );
138 uploadAction.setArtifactId( "artifact-upload" );
139 uploadAction.setVersion( version );
140 uploadAction.setPackaging( "jar" );
142 uploadAction.setClassifier( classifier );
143 uploadAction.setArtifact( artifact );
144 uploadAction.setPom( pomFile );
145 uploadAction.setGeneratePom( generatePom );
148 private void assertAllArtifactsIncludingSupportArtifactsArePresent( String repoLocation, String artifact,
151 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact + ".jar" ).exists() );
152 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact
153 + ".jar.sha1" ).exists() );
154 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact
155 + ".jar.md5" ).exists() );
157 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact + ".pom" ).exists() );
158 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact
159 + ".pom.sha1" ).exists() );
160 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact
161 + ".pom.md5" ).exists() );
163 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
164 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA
165 + ".sha1" ).exists() );
166 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA
167 + ".md5" ).exists() );
170 private void verifyVersionMetadataChecksums( String repoLocation, String version )
173 ChecksummedFile checksum =
174 new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
175 + MetadataTools.MAVEN_METADATA ) );
176 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
177 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
180 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
181 + MetadataTools.MAVEN_METADATA + ".sha1" ) );
182 assertTrue( StringUtils.contains( contents, sha1 ) );
185 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
186 + MetadataTools.MAVEN_METADATA + ".md5" ) );
187 assertTrue( StringUtils.contains( contents, md5 ) );
190 private void verifyProjectMetadataChecksums( String repoLocation )
193 ChecksummedFile checksum =
194 new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/"
195 + MetadataTools.MAVEN_METADATA ) );
196 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
197 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
200 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/"
201 + MetadataTools.MAVEN_METADATA + ".sha1" ) );
202 assertTrue( StringUtils.contains( contents, sha1 ) );
205 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/"
206 + MetadataTools.MAVEN_METADATA + ".md5" ) );
207 assertTrue( StringUtils.contains( contents, md5 ) );
210 private void verifyPomChecksums( String repoLocation, String artifact, String version )
213 ChecksummedFile checksum;
218 new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
219 + artifact + ".pom" ) );
220 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
221 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
224 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
225 + artifact + ".pom.sha1" ) );
226 assertTrue( StringUtils.contains( contents, sha1 ) );
229 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
230 + artifact + ".pom.md5" ) );
231 assertTrue( StringUtils.contains( contents, md5 ) );
234 private void verifyArtifactChecksums( String repoLocation, String artifact, String version )
237 ChecksummedFile checksum =
238 new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
239 + artifact + ".jar" ) );
240 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
241 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
244 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
245 + artifact + ".jar.sha1" ) );
246 assertTrue( StringUtils.contains( contents, sha1 ) );
249 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
250 + artifact + ".jar.md5" ) );
251 assertTrue( StringUtils.contains( contents, md5 ) );
254 private String getTimestamp( String[] artifactsList, int startIndex, int index )
259 if ( artifactsList[index].contains( "jar" ) )
261 endIndex = artifactsList[index].indexOf( ".jar" );
265 endIndex = artifactsList[index].indexOf( ".pom" );
268 timestamp = artifactsList[index].substring( startIndex, endIndex );
273 public void testArtifactUploadWithPomSuccessful()
276 setUploadParameters( "1.0", null,
277 new File( getBasedir(),
278 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
279 new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
281 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
282 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
284 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
285 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
286 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
288 archivaConfigControl.replay();
289 repoFactoryControl.replay();
290 auditLogsDaoControl.replay();
292 String returnString = uploadAction.doUpload();
293 assertEquals( Action.SUCCESS, returnString );
295 archivaConfigControl.verify();
296 repoFactoryControl.verify();
297 auditLogsDaoControl.verify();
299 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
300 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
302 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
303 verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
304 verifyProjectMetadataChecksums( repoLocation );
307 public void testArtifactUploadWithClassifier()
310 setUploadParameters( "1.0", "tests",
311 new File( getBasedir(),
312 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
315 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
316 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
318 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
319 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
320 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
322 archivaConfigControl.replay();
323 repoFactoryControl.replay();
324 auditLogsDaoControl.replay();
326 String returnString = uploadAction.doUpload();
327 assertEquals( Action.SUCCESS, returnString );
329 archivaConfigControl.verify();
330 repoFactoryControl.verify();
331 auditLogsDaoControl.verify();
333 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
334 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ).exists() );
335 assertTrue( new File( repoLocation,
336 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ).exists() );
337 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ).exists() );
339 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
340 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
341 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
343 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
344 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA
345 + ".sha1" ).exists() );
346 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA
347 + ".md5" ).exists() );
349 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0-tests", "1.0" );
350 verifyProjectMetadataChecksums( repoLocation );
353 public void testArtifactUploadGeneratePomSuccessful()
356 setUploadParameters( "1.0", null,
357 new File( getBasedir(),
358 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
361 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
362 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
364 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
365 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
366 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
368 archivaConfigControl.replay();
369 repoFactoryControl.replay();
370 auditLogsDaoControl.replay();
372 String returnString = uploadAction.doUpload();
373 assertEquals( Action.SUCCESS, returnString );
375 archivaConfigControl.verify();
376 repoFactoryControl.verify();
377 auditLogsDaoControl.verify();
379 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
380 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
382 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
383 verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
384 verifyProjectMetadataChecksums( repoLocation );
387 public void testArtifactUploadFailedRepositoryNotFound()
390 setUploadParameters( "1.0", null,
391 new File( getBasedir(),
392 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
395 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
396 repoFactoryControl.expectAndThrow( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ),
397 new RepositoryNotFoundException() );
399 archivaConfigControl.replay();
400 repoFactoryControl.replay();
402 String returnString = uploadAction.doUpload();
403 assertEquals( Action.ERROR, returnString );
405 archivaConfigControl.verify();
406 repoFactoryControl.verify();
408 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
409 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
411 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
413 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
416 public void testArtifactUploadSnapshots()
419 setUploadParameters( "1.0-SNAPSHOT", null,
420 new File( getBasedir(),
421 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
424 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
425 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
427 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
428 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
429 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
431 archivaConfigControl.replay();
432 repoFactoryControl.replay();
433 auditLogsDaoControl.replay();
435 String returnString = uploadAction.doUpload();
436 assertEquals( Action.SUCCESS, returnString );
438 archivaConfigControl.verify();
439 repoFactoryControl.verify();
440 auditLogsDaoControl.verify();
442 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
443 String[] artifactsList = new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list();
445 assertEquals( 9, artifactsList.length );
446 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
447 + MetadataTools.MAVEN_METADATA ).exists() );
448 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
449 + MetadataTools.MAVEN_METADATA + ".sha1" ).exists() );
450 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
451 + MetadataTools.MAVEN_METADATA + ".md5" ).exists() );
453 int startIndex = "artifact-upload-1.0-".length();
454 String timestamp = getTimestamp( artifactsList, startIndex, 0 );
456 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0-" + timestamp,
458 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0-" + timestamp, "1.0-SNAPSHOT" );
459 verifyPomChecksums( repoLocation, "artifact-upload-1.0-" + timestamp, "1.0-SNAPSHOT" );
460 verifyProjectMetadataChecksums( repoLocation );
461 verifyVersionMetadataChecksums( repoLocation, "1.0-SNAPSHOT" );
463 // verify build number
465 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" + MetadataTools.MAVEN_METADATA );
466 ArchivaRepositoryMetadata artifactMetadata = RepositoryMetadataReader.read( metadataFile );
468 SnapshotVersion snapshotVersion = artifactMetadata.getSnapshotVersion();
469 assertEquals( "Incorrect build number set in artifact metadata.", 1, snapshotVersion.getBuildNumber() );
471 String timestampPart = StringUtils.substringBeforeLast( timestamp, "-" );
472 assertEquals( "Incorrect timestamp set in artifact metadata.", timestampPart, snapshotVersion.getTimestamp() );
474 String buildnumber = StringUtils.substringAfterLast( timestamp, "-" );
475 assertEquals( "Incorrect build number in filename.", "1", buildnumber );
477 archivaConfigControl.reset();
478 repoFactoryControl.reset();
479 auditLogsDaoControl.reset();
481 auditLogsDaoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
484 // upload snapshot artifact again and check if build number was incremented
485 setUploadParameters( "1.0-SNAPSHOT", null,
486 new File( getBasedir(),
487 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
490 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
491 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
492 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
494 archivaConfigControl.replay();
495 repoFactoryControl.replay();
496 auditLogsDaoControl.replay();
498 returnString = uploadAction.doUpload();
499 assertEquals( Action.SUCCESS, returnString );
501 archivaConfigControl.verify();
502 repoFactoryControl.verify();
503 auditLogsDaoControl.verify();
505 artifactsList = new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list();
507 assertEquals( 15, artifactsList.length );
509 timestamp = getTimestamp( artifactsList, startIndex, 6 );
511 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0-" + timestamp,
513 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0-" + timestamp, "1.0-SNAPSHOT" );
514 verifyPomChecksums( repoLocation, "artifact-upload-1.0-" + timestamp, "1.0-SNAPSHOT" );
515 verifyProjectMetadataChecksums( repoLocation );
516 verifyVersionMetadataChecksums( repoLocation, "1.0-SNAPSHOT" );
518 // verify build number set in metadata and in filename
520 new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" + MetadataTools.MAVEN_METADATA );
521 artifactMetadata = RepositoryMetadataReader.read( metadataFile );
523 snapshotVersion = artifactMetadata.getSnapshotVersion();
524 assertEquals( "Incorrect build number set in artifact metadata.", 2, snapshotVersion.getBuildNumber() );
526 timestampPart = StringUtils.substringBeforeLast( timestamp, "-" );
527 assertEquals( "Incorrect timestamp set in artifact metadata.", timestampPart, snapshotVersion.getTimestamp() );
529 buildnumber = StringUtils.substringAfterLast( timestamp, "-" );
530 assertEquals( "Incorrect build number in filename.", "2", buildnumber );
533 public void testChecksumIsCorrectWhenArtifactIsReUploaded()
536 setUploadParameters( "1.0", null,
537 new File( getBasedir(),
538 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
541 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
542 ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
543 repoConfig.setBlockRedeployments( false );
544 content.setRepository( repoConfig );
546 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
547 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
548 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
550 archivaConfigControl.replay();
551 repoFactoryControl.replay();
552 auditLogsDaoControl.replay();
554 String returnString = uploadAction.doUpload();
555 assertEquals( Action.SUCCESS, returnString );
557 archivaConfigControl.verify();
558 repoFactoryControl.verify();
559 auditLogsDaoControl.verify();
561 archivaConfigControl.reset();
562 repoFactoryControl.reset();
563 auditLogsDaoControl.reset();
564 auditLogsDaoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
566 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
567 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
569 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
570 verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
571 verifyProjectMetadataChecksums( repoLocation );
573 // RE-upload artifact
574 setUploadParameters( "1.0", null,
575 new File( getBasedir(),
576 "target/test-classes/upload-artifact-test/artifact-to-be-reuploaded.jar" ),
579 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
580 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
581 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
583 archivaConfigControl.replay();
584 repoFactoryControl.replay();
585 auditLogsDaoControl.replay();
587 returnString = uploadAction.doUpload();
588 assertEquals( Action.SUCCESS, returnString );
590 archivaConfigControl.verify();
591 repoFactoryControl.verify();
592 auditLogsDaoControl.verify();
594 repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
595 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
597 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
598 verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
599 verifyProjectMetadataChecksums( repoLocation );
602 public void testUploadArtifactAlreadyExistingRedeploymentsBlocked()
605 setUploadParameters( "1.0", null,
606 new File( getBasedir(),
607 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
610 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
611 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
613 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
614 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );
615 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
617 archivaConfigControl.replay();
618 repoFactoryControl.replay();
619 auditLogsDaoControl.replay();
621 String returnString = uploadAction.doUpload();
622 assertEquals( Action.SUCCESS, returnString );
624 setUploadParameters( "1.0", null,
625 new File( getBasedir(),
626 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
629 returnString = uploadAction.doUpload();
630 assertEquals( Action.ERROR, returnString );
632 archivaConfigControl.verify();
633 repoFactoryControl.verify();
634 auditLogsDaoControl.verify();
636 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
637 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
639 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
640 verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
641 verifyProjectMetadataChecksums( repoLocation );
644 public void testUploadArtifactAlreadyExistingRedeploymentsAllowed()
647 setUploadParameters( "1.0", null,
648 new File( getBasedir(),
649 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
652 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
653 ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
654 repoConfig.setBlockRedeployments( false );
655 content.setRepository( repoConfig );
657 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
658 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );
659 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null, 2 );
661 archivaConfigControl.replay();
662 repoFactoryControl.replay();
663 auditLogsDaoControl.replay();
665 String returnString = uploadAction.doUpload();
666 assertEquals( Action.SUCCESS, returnString );
668 setUploadParameters( "1.0", null,
669 new File( getBasedir(),
670 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
673 returnString = uploadAction.doUpload();
674 assertEquals( Action.SUCCESS, returnString );
676 archivaConfigControl.verify();
677 repoFactoryControl.verify();
678 auditLogsDaoControl.verify();
680 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
681 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
683 verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
684 verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
685 verifyProjectMetadataChecksums( repoLocation );