1 package org.apache.maven.shared.test.plugin;
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
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.factory.ArtifactFactory;
26 import org.apache.maven.project.MavenProject;
27 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
28 import org.apache.maven.shared.tools.easymock.TestFileManager;
29 import org.codehaus.plexus.ContainerConfiguration;
30 import org.codehaus.plexus.PlexusConstants;
31 import org.codehaus.plexus.PlexusTestCase;
32
33
34
35
36 public class RepositoryToolTest
37 extends PlexusTestCase
38 {
39 private TestFileManager fileManager;
40
41 public void setUp()
42 throws Exception
43 {
44 super.setUp();
45
46 fileManager = new TestFileManager( "RepositoryToolTest.", "" );
47 }
48
49 public void tearDown()
50 throws Exception
51 {
52 super.tearDown();
53
54 fileManager.cleanUp();
55 }
56
57 public void testCreateLocalRepositoryFromPlugin_ShouldWriteJarAndPom()
58 throws Exception
59 {
60 RepositoryTool repoTool = (RepositoryTool) lookup( RepositoryTool.ROLE, "default" );
61
62 File tempDir = fileManager.createTempDir();
63
64 String pomContent = "<project><modelVersion>4.0.0</modelVersion></project>";
65 String jarContent = "This is a test";
66
67 File pom = fileManager.createFile( tempDir, "pom.xml", pomContent );
68 File jar = fileManager.createFile( tempDir, "artifact-test.jar", jarContent );
69
70 MavenProject pluginProject = new MavenProject();
71
72 ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
73
74 Artifact pluginArtifact = artifactFactory.createArtifact( "group", "artifact", "test", null, "jar" );
75 pluginArtifact.setFile( jar );
76 pluginArtifact.addMetadata( new ProjectArtifactMetadata( pluginArtifact, pom ) );
77
78 pluginProject.setArtifact( pluginArtifact );
79 pluginProject.setFile( pom );
80
81 File targetLocalRepoBasedir = fileManager.createTempDir();
82
83 repoTool.createLocalRepositoryFromComponentProject( pluginProject, pom, targetLocalRepoBasedir );
84
85 fileManager.assertFileExistence( targetLocalRepoBasedir, "group/artifact/test/artifact-test.pom", true );
86 fileManager.assertFileContents( targetLocalRepoBasedir, "group/artifact/test/artifact-test.jar", jarContent );
87
88 }
89
90 @Override
91 protected void customizeContainerConfiguration(ContainerConfiguration configuration)
92 {
93 configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
94 configuration.setAutoWiring( true );
95 }
96 }