1 package org.apache.maven.shared.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.artifact.install.ArtifactInstaller;
32 import org.codehaus.plexus.PlexusTestCase;
33 import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
34
35 public class Maven30ArtifactInstallerTest extends PlexusTestCase
36 {
37 private final File localRepo = new File( "target/tests/local-repo" );
38
39 private Maven30ArtifactInstaller installer;
40
41 @Override
42 public void setUp() throws Exception
43 {
44 super.setUp();
45 installer = (Maven30ArtifactInstaller) super.lookup( ArtifactInstaller.class, "maven3" );
46 }
47
48 public void testInstall() throws Exception
49 {
50 DefaultProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
51 MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
52 repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
53 buildingRequest.setRepositorySession( repositorySession );
54
55 DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler();
56 artifactHandler.setExtension( "EXTENSION" );
57
58 File artifactsDirectory = new File( "target/tests/artifacts" );
59 artifactsDirectory.mkdirs();
60 File tmpFile = File.createTempFile( "test-install", ".jar", artifactsDirectory );
61
62 DefaultArtifact artifact = new DefaultArtifact( "GROUPID", "ARTIFACTID", "VERSION", "compile", "jar", null, artifactHandler );
63 artifact.setFile( tmpFile );
64 DefaultArtifact artifactWithClassifier = new DefaultArtifact( "GROUPID", "ARTIFACTID", "VERSION", "compile", "jar", "CLASSIFIER", artifactHandler );
65 artifactWithClassifier.setFile( tmpFile );
66
67 Collection<Artifact> mavenArtifacts = Arrays.<Artifact>asList( artifact, artifactWithClassifier );
68
69 installer.install( buildingRequest, mavenArtifacts );
70
71 assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION" ).exists() );
72 assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" ).exists() );
73 assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/maven-metadata-local.xml" ).exists() );
74 }
75 }