1 package org.apache.maven.shared.transfer.artifact.install.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Arrays;
24 import java.util.Collection;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.artifact.DefaultArtifact;
28 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
29 import org.apache.maven.project.DefaultProjectBuildingRequest;
30 import org.apache.maven.repository.internal.MavenRepositorySystemSession;
31 import org.apache.maven.shared.transfer.artifact.install.internal.Maven30ArtifactInstaller;
32 import org.codehaus.plexus.PlexusTestCase;
33 import org.sonatype.aether.RepositorySystem;
34 import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
35
36 public class Maven30ArtifactInstallerTest extends PlexusTestCase
37 {
38 private final File localRepo = new File( "target/tests/local-repo" );
39
40 private RepositorySystem repositorySystem;
41
42 @Override
43 public void setUp() throws Exception
44 {
45 super.setUp();
46 repositorySystem = lookup( RepositorySystem.class );
47 }
48
49 public void testInstall() throws Exception
50 {
51 DefaultProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
52 MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
53 repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
54 buildingRequest.setRepositorySession( repositorySession );
55
56 DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler();
57 artifactHandler.setExtension( "EXTENSION" );
58
59 File artifactsDirectory = new File( "target/tests/artifacts" );
60 artifactsDirectory.mkdirs();
61 File tmpFile = File.createTempFile( "test-install", ".jar", artifactsDirectory );
62
63 DefaultArtifact artifact = new DefaultArtifact( "GROUPID", "ARTIFACTID", "VERSION", "compile", "jar", null, artifactHandler );
64 artifact.setFile( tmpFile );
65 DefaultArtifact artifactWithClassifier = new DefaultArtifact( "GROUPID", "ARTIFACTID", "VERSION", "compile", "jar", "CLASSIFIER", artifactHandler );
66 artifactWithClassifier.setFile( tmpFile );
67
68 Collection<Artifact> mavenArtifacts = Arrays.<Artifact>asList( artifact, artifactWithClassifier );
69
70 MavenArtifactInstaller installer = new Maven30ArtifactInstaller( repositorySystem, repositorySession );
71 installer.install( mavenArtifacts );
72
73 assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION" ).exists() );
74 assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" ).exists() );
75 assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/maven-metadata-local.xml" ).exists() );
76 }
77 }