1 package org.apache.maven.shared.release.phase;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.project.MavenProject;
23 import org.apache.maven.shared.release.config.ReleaseDescriptor;
24 import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
25 import org.apache.maven.shared.release.util.ReleaseUtil;
26 import org.codehaus.plexus.util.FileUtils;
27
28 import java.io.File;
29 import java.util.Iterator;
30 import java.util.List;
31
32
33
34
35 public class RestoreBackupPomsPhaseTest
36 extends AbstractBackupPomsPhaseTest
37 {
38 private String expectedPomFilename = "expected-pom.xml";
39
40 ReleasePhase getReleasePhase()
41 throws Exception
42 {
43 return (ReleasePhase) lookup( ReleasePhase.ROLE, "restore-backup-poms" );
44 }
45
46 public void testBasicPom()
47 throws Exception
48 {
49 String projectPath = "/projects/restore-backup-poms/basic-pom";
50
51
52 File sourceDir = getTestFile( "src/test/resources" + projectPath );
53 File testDir = getTestFile( "target/test-classes" + projectPath );
54 FileUtils.copyDirectoryStructure( sourceDir, testDir );
55
56 String testPath = "target/test-classes" + projectPath;
57
58 runExecuteOnProjects( testPath );
59 }
60
61 public void testMultiModulePom()
62 throws Exception
63 {
64 String projectPath = "/projects/restore-backup-poms/pom-with-modules";
65
66
67 File sourceDir = getTestFile( "src/test/resources" + projectPath );
68 File testDir = getTestFile( "target/test-classes" + projectPath );
69 FileUtils.copyDirectoryStructure( sourceDir, testDir );
70
71 String testPath = "target/test-classes" + projectPath;
72
73 runExecuteOnProjects( testPath );
74 }
75
76 private void runExecuteOnProjects( String path )
77 throws Exception
78 {
79 List<MavenProject> projects = getReactorProjects( getTestPath( path ) );
80
81 ReleaseDescriptor desc = new ReleaseDescriptor();
82 desc.setScmSourceUrl( "scm:svn:http://myhost/myrepo" );
83 phase.execute( desc, new DefaultReleaseEnvironment(), projects );
84
85 testProjectIsRestored( projects );
86 }
87
88 private void testProjectIsRestored( List<MavenProject> reactorProjects )
89 throws Exception
90 {
91 for ( Iterator<MavenProject> projects = reactorProjects.iterator(); projects.hasNext(); )
92 {
93 MavenProject project = projects.next();
94
95 File pomFile = project.getFile();
96
97 File expectedFile = new File( pomFile.getParentFile(), expectedPomFilename );
98
99 assertTrue( "Check if expected file exists.", expectedFile.exists() );
100
101 String pomContents = ReleaseUtil.readXmlFile( pomFile );
102
103 String expectedContents = ReleaseUtil.readXmlFile( expectedFile );
104
105 assertTrue( "Check if pom and backup files are identical", pomContents.equals( expectedContents ) );
106 }
107 }
108 }