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 import java.io.IOException;
24 import java.util.Collection;
25 import java.util.Iterator;
26
27 import org.apache.maven.artifact.Artifact;
28 import org.apache.maven.artifact.metadata.ArtifactMetadata;
29 import org.apache.maven.project.MavenProject;
30 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
31 import org.apache.maven.shared.test.plugin.ProjectTool.PomInfo;
32 import org.codehaus.plexus.ContainerConfiguration;
33 import org.codehaus.plexus.PlexusConstants;
34 import org.codehaus.plexus.PlexusTestCase;
35 import org.codehaus.plexus.util.FileUtils;
36 import org.codehaus.plexus.util.StringUtils;
37
38
39
40
41 public class ProjectToolTest
42 extends PlexusTestCase
43 {
44
45 private File getPom( String test )
46 throws IOException
47 {
48 File src = new File( "src/test/resources/projects/" + test );
49 File dst = new File( "target/unit/projects/" + test );
50
51 FileUtils.copyDirectoryStructureIfModified( src, dst );
52
53 return new File( dst, "pom.xml" );
54 }
55
56 public void testManglePomForTesting_ShouldPopulateOutDirAndFinalName()
57 throws Exception
58 {
59 ProjectTool tool = (ProjectTool) lookup( ProjectTool.ROLE, "default" );
60
61 File pomFile = getPom( "basic" );
62
63 PomInfo info = tool.manglePomForTesting( pomFile, "test", true );
64
65 assertEquals( "target"+File.separatorChar+"it-build-target", info.getBuildDirectory() );
66 assertEquals( "maven-it-plugin-test.jar", info.getFinalName() );
67 assertEquals( "target"+File.separatorChar+"it-build-target"+File.separatorChar+"classes",info.getBuildOutputDirectory() );
68 }
69
70 public void testPackageProjectArtifact_ShouldPopulateArtifactFileWithJarLocation()
71 throws Exception
72 {
73 ProjectTool tool = (ProjectTool) lookup( ProjectTool.ROLE, "default" );
74
75 File pomFile = getPom( "basic" );
76
77 MavenProject project = tool.packageProjectArtifact( pomFile, "test", true );
78
79 String expectedPath = "target/unit/projects/basic/target/it-build-target/maven-it-plugin-test.jar";
80
81
82 String actualPath = StringUtils.replace( project.getArtifact().getFile().getPath(), "\\", "/" );
83
84 assertEquals( expectedPath, actualPath );
85 }
86
87 public void testPackageProjectArtifact_ShouldPopulateWithCorrectArtifactAndMetadata()
88 throws Exception
89 {
90 ProjectTool tool = (ProjectTool) lookup( ProjectTool.ROLE, "default" );
91
92 File pomFile = getPom( "basic" );
93
94 MavenProject project = tool.packageProjectArtifact( pomFile, "test", true );
95
96 Artifact artifact = project.getArtifact();
97
98 assertEquals( "maven-plugin", artifact.getType() );
99 assertTrue( "Missing " + artifact.getFile(), artifact.getFile().exists() );
100
101 Collection<ArtifactMetadata> metadata = artifact.getMetadataList();
102
103 boolean foundPomMetadata = false;
104
105 for ( ArtifactMetadata metadataItem : metadata )
106 {
107 if ( metadataItem instanceof ProjectArtifactMetadata )
108 {
109 foundPomMetadata = true;
110 }
111 }
112
113 assertTrue( foundPomMetadata );
114 }
115
116 @Override
117 protected void customizeContainerConfiguration(ContainerConfiguration configuration)
118 {
119 configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
120 configuration.setAutoWiring( true );
121 }
122 }