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.repository.ManagedRepositoryContent;
37 import org.apache.maven.archiva.repository.RepositoryContentFactory;
38 import org.apache.maven.archiva.repository.RepositoryNotFoundException;
39 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
40 import org.apache.maven.archiva.repository.metadata.MetadataTools;
41 import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
42 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
43 import org.easymock.MockControl;
44 import org.easymock.classextension.MockClassControl;
46 import com.opensymphony.xwork2.Action;
51 public class UploadActionTest
52 extends PlexusInSpringTestCase
54 private ArchivaTaskScheduler scheduler;
56 private MockControl schedulerControl;
58 private UploadAction uploadAction;
60 private ArchivaConfiguration archivaConfig;
62 private MockControl archivaConfigControl;
64 private RepositoryContentFactory repoFactory;
66 private MockControl repoFactoryControl;
68 private ArchivaAuditLogsDao auditLogsDao;
70 private MockControl auditLogsDaoControl;
72 private static final String REPOSITORY_ID = "test-repo";
74 private Configuration config;
81 schedulerControl = MockControl.createControl( ArchivaTaskScheduler.class );
82 scheduler = (ArchivaTaskScheduler) schedulerControl.getMock();
84 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
85 archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
87 repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
88 repoFactory = (RepositoryContentFactory) repoFactoryControl.getMock();
90 auditLogsDaoControl = MockControl.createControl( ArchivaAuditLogsDao.class );
91 auditLogsDaoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
92 auditLogsDao = (ArchivaAuditLogsDao) auditLogsDaoControl.getMock();
94 uploadAction = new UploadAction();
95 uploadAction.setScheduler( scheduler );
96 uploadAction.setConfiguration( archivaConfig );
97 uploadAction.setRepositoryFactory( repoFactory );
98 uploadAction.setAuditLogsDao( auditLogsDao );
100 File testRepo = new File( getBasedir(), "target/test-classes/test-repo" );
103 assertTrue( testRepo.exists() );
105 config = new Configuration();
106 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
107 repoConfig.setId( REPOSITORY_ID );
108 repoConfig.setLayout( "default" );
109 repoConfig.setLocation( testRepo.getPath() );
110 repoConfig.setName( REPOSITORY_ID );
111 repoConfig.setBlockRedeployments( true );
112 config.addManagedRepository( repoConfig );
114 RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
115 repoScanning.setKnownContentConsumers( new ArrayList<String>() );
116 config.setRepositoryScanning( repoScanning );
119 public void tearDown()
122 File testRepo = new File( config.findManagedRepositoryById( REPOSITORY_ID ).getLocation() );
123 FileUtils.deleteDirectory( testRepo );
125 assertFalse( testRepo.exists() );
130 private void setUploadParameters( String version, String classifier, File artifact, File pomFile,
131 boolean generatePom )
133 uploadAction.setRepositoryId( REPOSITORY_ID );
134 uploadAction.setGroupId( "org.apache.archiva" );
135 uploadAction.setArtifactId( "artifact-upload" );
136 uploadAction.setVersion( version );
137 uploadAction.setPackaging( "jar" );
139 uploadAction.setClassifier( classifier );
140 uploadAction.setArtifact( artifact );
141 uploadAction.setPom( pomFile );
142 uploadAction.setGeneratePom( generatePom );
145 private void assertAllArtifactsIncludingSupportArtifactsArePresent( String repoLocation )
147 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
148 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ).exists() );
149 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ).exists() );
151 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
152 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
153 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
155 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
156 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
157 ".sha1" ).exists() );
158 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
162 private void verifyChecksums( String repoLocation )
165 // verify checksums of jar file
166 ChecksummedFile checksum =
167 new ChecksummedFile( new File( repoLocation,
168 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
169 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
170 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
173 FileUtils.readFileToString( new File( repoLocation,
174 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ) );
175 assertTrue( StringUtils.contains( contents, sha1 ) );
178 FileUtils.readFileToString( new File( repoLocation,
179 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ) );
180 assertTrue( StringUtils.contains( contents, md5 ) );
182 // verify checksums of pom file
184 new ChecksummedFile( new File( repoLocation,
185 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
186 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
187 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
190 FileUtils.readFileToString( new File( repoLocation,
191 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ) );
192 assertTrue( StringUtils.contains( contents, sha1 ) );
195 FileUtils.readFileToString( new File( repoLocation,
196 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ) );
197 assertTrue( StringUtils.contains( contents, md5 ) );
199 // verify checksums of metadata file
201 new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
202 MetadataTools.MAVEN_METADATA ) );
203 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
204 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
207 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
208 MetadataTools.MAVEN_METADATA + ".sha1" ) );
209 assertTrue( StringUtils.contains( contents, sha1 ) );
212 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
213 MetadataTools.MAVEN_METADATA + ".md5" ) );
214 assertTrue( StringUtils.contains( contents, md5 ) );
217 public void testArtifactUploadWithPomSuccessful()
220 setUploadParameters( "1.0", null,
221 new File( getBasedir(),
222 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
223 new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
225 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
226 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
228 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
229 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
230 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
232 archivaConfigControl.replay();
233 repoFactoryControl.replay();
234 auditLogsDaoControl.replay();
236 String returnString = uploadAction.doUpload();
237 assertEquals( Action.SUCCESS, returnString );
239 archivaConfigControl.verify();
240 repoFactoryControl.verify();
241 auditLogsDaoControl.verify();
243 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
244 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
246 verifyChecksums( repoLocation );
249 public void testArtifactUploadWithClassifier()
252 setUploadParameters( "1.0", "tests",
253 new File( getBasedir(),
254 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
257 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
258 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
260 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
261 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
262 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
264 archivaConfigControl.replay();
265 repoFactoryControl.replay();
266 auditLogsDaoControl.replay();
268 String returnString = uploadAction.doUpload();
269 assertEquals( Action.SUCCESS, returnString );
271 archivaConfigControl.verify();
272 repoFactoryControl.verify();
273 auditLogsDaoControl.verify();
275 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
276 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ).exists() );
277 assertTrue( new File( repoLocation,
278 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ).exists() );
279 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ).exists() );
281 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
282 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
283 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
285 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
286 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
287 ".sha1" ).exists() );
288 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
291 // verify checksums of jar file
292 ChecksummedFile checksum =
293 new ChecksummedFile( new File( repoLocation,
294 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ) );
295 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
296 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
299 FileUtils.readFileToString( new File( repoLocation,
300 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ) );
301 assertTrue( StringUtils.contains( contents, sha1 ) );
304 FileUtils.readFileToString( new File( repoLocation,
305 "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ) );
306 assertTrue( StringUtils.contains( contents, md5 ) );
308 // verify checksums of metadata file
310 new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
311 MetadataTools.MAVEN_METADATA ) );
312 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
313 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
316 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
317 MetadataTools.MAVEN_METADATA + ".sha1" ) );
318 assertTrue( StringUtils.contains( contents, sha1 ) );
321 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
322 MetadataTools.MAVEN_METADATA + ".md5" ) );
323 assertTrue( StringUtils.contains( contents, md5 ) );
326 public void testArtifactUploadGeneratePomSuccessful()
329 setUploadParameters( "1.0", null,
330 new File( getBasedir(),
331 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
334 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
335 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
337 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
338 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
339 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
341 archivaConfigControl.replay();
342 repoFactoryControl.replay();
343 auditLogsDaoControl.replay();
345 String returnString = uploadAction.doUpload();
346 assertEquals( Action.SUCCESS, returnString );
348 archivaConfigControl.verify();
349 repoFactoryControl.verify();
350 auditLogsDaoControl.verify();
352 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
353 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
355 verifyChecksums( repoLocation );
358 public void testArtifactUploadFailedRepositoryNotFound()
361 setUploadParameters( "1.0", null,
362 new File( getBasedir(),
363 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
366 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
367 repoFactoryControl.expectAndThrow( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ),
368 new RepositoryNotFoundException() );
370 archivaConfigControl.replay();
371 repoFactoryControl.replay();
373 String returnString = uploadAction.doUpload();
374 assertEquals( Action.ERROR, returnString );
376 archivaConfigControl.verify();
377 repoFactoryControl.verify();
379 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
380 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
382 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
384 assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
387 public void testArtifactUploadSnapshots()
390 setUploadParameters( "1.0-SNAPSHOT", null,
391 new File( getBasedir(),
392 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
395 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
396 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
398 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
399 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
400 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
402 archivaConfigControl.replay();
403 repoFactoryControl.replay();
404 auditLogsDaoControl.replay();
406 String returnString = uploadAction.doUpload();
407 assertEquals( Action.SUCCESS, returnString );
409 archivaConfigControl.verify();
410 repoFactoryControl.verify();
411 auditLogsDaoControl.verify();
413 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
414 String[] artifactsList = new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list();
416 assertEquals( 6, artifactsList.length );
418 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
419 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
420 ".sha1" ).exists() );
421 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
424 int startIndex = "artifact-upload-1.0-".length();
427 if ( artifactsList[0].contains( "jar" ) )
429 endIndex = artifactsList[0].indexOf( ".jar" );
433 endIndex = artifactsList[0].indexOf( ".pom" );
436 String timestamp = artifactsList[0].substring( startIndex, endIndex );
438 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".jar" ).exists() );
439 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".jar.md5" ).exists() );
440 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".jar.sha1" ).exists() );
441 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".pom" ).exists() );
442 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".pom.md5" ).exists() );
443 assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".pom.sha1" ).exists() );
445 // verify checksums of jar file
446 ChecksummedFile checksum =
447 new ChecksummedFile( new File( repoLocation,
448 "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".jar" ) );
449 String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
450 String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
453 FileUtils.readFileToString( new File( repoLocation,
454 "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".jar.sha1" ) );
455 assertTrue( StringUtils.contains( contents, sha1 ) );
458 FileUtils.readFileToString( new File( repoLocation,
459 "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".jar.md5" ) );
460 assertTrue( StringUtils.contains( contents, md5 ) );
462 // verify checksums of pom file
464 new ChecksummedFile( new File( repoLocation,
465 "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".pom" ) );
466 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
467 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
470 FileUtils.readFileToString( new File( repoLocation,
471 "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".pom.sha1" ) );
472 assertTrue( StringUtils.contains( contents, sha1 ) );
475 FileUtils.readFileToString( new File( repoLocation,
476 "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + ".pom.md5" ) );
477 assertTrue( StringUtils.contains( contents, md5 ) );
480 // verify checksums of metadata file
482 new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
483 MetadataTools.MAVEN_METADATA ) );
484 sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
485 md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
488 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
489 MetadataTools.MAVEN_METADATA + ".sha1" ) );
490 assertTrue( StringUtils.contains( contents, sha1 ) );
493 FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
494 MetadataTools.MAVEN_METADATA + ".md5" ) );
495 assertTrue( StringUtils.contains( contents, md5 ) );
498 public void testChecksumIsCorrectWhenArtifactIsReUploaded()
501 setUploadParameters( "1.0", null,
502 new File( getBasedir(),
503 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
506 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
507 ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
508 repoConfig.setBlockRedeployments( false );
509 content.setRepository( repoConfig );
511 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
512 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
513 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
515 archivaConfigControl.replay();
516 repoFactoryControl.replay();
517 auditLogsDaoControl.replay();
519 String returnString = uploadAction.doUpload();
520 assertEquals( Action.SUCCESS, returnString );
522 archivaConfigControl.verify();
523 repoFactoryControl.verify();
524 auditLogsDaoControl.verify();
526 archivaConfigControl.reset();
527 repoFactoryControl.reset();
528 auditLogsDaoControl.reset();
529 auditLogsDaoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
531 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
532 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
534 verifyChecksums( repoLocation );
536 // RE-upload artifact
537 setUploadParameters( "1.0", null,
538 new File( getBasedir(),
539 "target/test-classes/upload-artifact-test/artifact-to-be-reuploaded.jar" ),
542 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
543 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
544 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
546 archivaConfigControl.replay();
547 repoFactoryControl.replay();
548 auditLogsDaoControl.replay();
550 returnString = uploadAction.doUpload();
551 assertEquals( Action.SUCCESS, returnString );
553 archivaConfigControl.verify();
554 repoFactoryControl.verify();
555 auditLogsDaoControl.verify();
557 repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
558 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
560 verifyChecksums( repoLocation );
563 public void testUploadArtifactAlreadyExistingRedeploymentsBlocked()
566 setUploadParameters( "1.0", null,
567 new File( getBasedir(),
568 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
571 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
572 content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
574 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
575 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );
576 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
578 archivaConfigControl.replay();
579 repoFactoryControl.replay();
580 auditLogsDaoControl.replay();
582 String returnString = uploadAction.doUpload();
583 assertEquals( Action.SUCCESS, returnString );
585 setUploadParameters( "1.0", null,
586 new File( getBasedir(),
587 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
590 returnString = uploadAction.doUpload();
591 assertEquals( Action.ERROR, returnString );
593 archivaConfigControl.verify();
594 repoFactoryControl.verify();
595 auditLogsDaoControl.verify();
597 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
598 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
600 verifyChecksums( repoLocation );
603 public void testUploadArtifactAlreadyExistingRedeploymentsAllowed()
606 setUploadParameters( "1.0", null,
607 new File( getBasedir(),
608 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
611 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
612 ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
613 repoConfig.setBlockRedeployments( false );
614 content.setRepository( repoConfig );
616 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
617 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );
618 auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null, 2 );
620 archivaConfigControl.replay();
621 repoFactoryControl.replay();
622 auditLogsDaoControl.replay();
624 String returnString = uploadAction.doUpload();
625 assertEquals( Action.SUCCESS, returnString );
627 setUploadParameters( "1.0", null,
628 new File( getBasedir(),
629 "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
632 returnString = uploadAction.doUpload();
633 assertEquals( Action.SUCCESS, returnString );
635 archivaConfigControl.verify();
636 repoFactoryControl.verify();
637 auditLogsDaoControl.verify();
639 String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
640 assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
642 verifyChecksums( repoLocation );