1 package org.apache.maven.scm.plugin;
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.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
24 import org.apache.maven.scm.ScmTestCase;
25 import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
26 import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
27 import org.codehaus.plexus.util.FileUtils;
28 import org.codehaus.plexus.util.StringUtils;
29
30 import java.io.File;
31
32
33
34
35
36 public class CheckoutMojoTest
37 extends AbstractMojoTestCase
38 {
39 File checkoutDir;
40
41 File repository;
42
43 protected void setUp()
44 throws Exception
45 {
46 super.setUp();
47
48 checkoutDir = getTestFile( "target/checkout" );
49
50 repository = getTestFile( "target/repository" );
51
52 FileUtils.forceDelete( checkoutDir );
53 }
54
55 public void testSkipCheckoutWhenCheckoutDirectoryExistsAndSkip()
56 throws Exception
57 {
58 FileUtils.forceDelete( checkoutDir );
59 checkoutDir.mkdirs();
60
61 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
62 "src/test/resources/mojos/checkout/checkoutWhenCheckoutDirectoryExistsAndSkip.xml" ) );
63
64 mojo.setCheckoutDirectory( checkoutDir );
65
66 mojo.execute();
67
68 assertEquals( 0, checkoutDir.listFiles().length );
69 }
70
71 public void testSkipCheckoutWithConnectionUrl()
72 throws Exception
73 {
74 if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
75 {
76 System.err.println( "'" + SvnScmTestUtils.SVNADMIN_COMMAND_LINE
77 + "' is not a system command. Ignored " + getName() + "." );
78 return;
79 }
80
81 FileUtils.forceDelete( checkoutDir );
82
83 SvnScmTestUtils.initializeRepository( repository );
84
85 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
86 "src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
87 mojo.setWorkingDirectory( new File( getBasedir() ) );
88
89 String connectionUrl = mojo.getConnectionUrl();
90 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
91 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
92 mojo.setConnectionUrl( connectionUrl );
93
94 mojo.setCheckoutDirectory( checkoutDir );
95
96 mojo.execute();
97 }
98
99 public void testSkipCheckoutWithoutConnectionUrl()
100 throws Exception
101 {
102 FileUtils.forceDelete( checkoutDir );
103
104 checkoutDir.mkdirs();
105 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
106 "src/test/resources/mojos/checkout/checkoutWithoutConnectionUrl.xml" ) );
107
108 try
109 {
110 mojo.execute();
111
112 fail( "mojo execution must fail." );
113 }
114 catch ( MojoExecutionException e )
115 {
116 assertTrue( true );
117 }
118 }
119
120 public void testUseExport()
121 throws Exception
122 {
123 FileUtils.forceDelete( checkoutDir );
124
125 checkoutDir.mkdirs();
126
127 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
128 "src/test/resources/mojos/checkout/checkoutUsingExport.xml" ) );
129
130 mojo.setCheckoutDirectory( checkoutDir );
131
132 mojo.execute();
133
134 assertTrue( checkoutDir.listFiles().length > 0 );
135 assertFalse( new File( checkoutDir, ".svn" ).exists() );
136 }
137
138 public void testExcludeInclude()
139 throws Exception
140 {
141 FileUtils.forceDelete( checkoutDir );
142
143 checkoutDir.mkdirs();
144
145 SvnScmTestUtils.initializeRepository( repository );
146
147 CheckoutMojo mojo = (CheckoutMojo) lookupMojo(
148 "checkout",
149 getTestFile( "src/test/resources/mojos/checkout/checkoutWithExcludesIncludes.xml" ) );
150
151 mojo.setCheckoutDirectory( checkoutDir );
152
153 mojo.execute();
154
155 assertTrue( checkoutDir.listFiles().length > 0 );
156 assertTrue( new File( checkoutDir, ".svn").exists() );
157 assertTrue( new File( checkoutDir, "pom.xml" ).exists() );
158 assertFalse( new File( checkoutDir, "readme.txt" ).exists() );
159 assertFalse( new File( checkoutDir, "src/test" ).exists() );
160 assertTrue( new File( checkoutDir, "src/main/java" ).exists() );
161
162
163
164 }
165
166 public void testEncryptedPasswordFromSettings()
167 throws Exception
168 {
169 File pom = getTestFile( "src/test/resources/mojos/checkout/checkoutEncryptedPasswordFromSettings.xml" );
170 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", pom );
171 ScmProviderRepositoryWithHost repo =
172 (ScmProviderRepositoryWithHost) mojo.getScmRepository().getProviderRepository();
173
174 assertEquals( "testuser", repo.getUser() );
175 assertEquals( "testpass", repo.getPassword() );
176 assertEquals( "testphrase", repo.getPassphrase() );
177 }
178
179 }