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