Debian Codegraph @

maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/CheckoutMojoTest.java

raw
1 package org.apache.maven.scm.plugin;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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 * @author <a href="mailto:[email protected]">Emmanuel Venisse</a>
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 ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName() );
77 return;
78 }
79
80 FileUtils.forceDelete( checkoutDir );
81
82 SvnScmTestUtils.initializeRepository( repository );
83
84 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
85 "src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
86 mojo.setWorkingDirectory( new File( getBasedir() ) );
87
88 String connectionUrl = mojo.getConnectionUrl();
89 connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() );
90 connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" );
91 mojo.setConnectionUrl( connectionUrl );
92
93 mojo.setCheckoutDirectory( checkoutDir );
94
95 mojo.execute();
96 }
97
98 public void testSkipCheckoutWithoutConnectionUrl()
99 throws Exception
100 {
101 FileUtils.forceDelete( checkoutDir );
102
103 checkoutDir.mkdirs();
104 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
105 "src/test/resources/mojos/checkout/checkoutWithoutConnectionUrl.xml" ) );
106
107 try
108 {
109 mojo.execute();
110
111 fail( "mojo execution must fail." );
112 }
113 catch ( MojoExecutionException e )
114 {
115 assertTrue( true );
116 }
117 }
118
119 public void testUseExport()
120 throws Exception
121 {
122 FileUtils.forceDelete( checkoutDir );
123
124 checkoutDir.mkdirs();
125
126 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
127 "src/test/resources/mojos/checkout/checkoutUsingExport.xml" ) );
128
129 mojo.setCheckoutDirectory( checkoutDir );
130
131 mojo.execute();
132
133 assertTrue( checkoutDir.listFiles().length > 0 );
134 assertFalse( new File( checkoutDir, ".svn" ).exists() );
135 }
136
137 public void testExcludeInclude()
138 throws Exception
139 {
140 FileUtils.forceDelete( checkoutDir );
141
142 checkoutDir.mkdirs();
143
144 SvnScmTestUtils.initializeRepository( repository );
145
146 CheckoutMojo mojo = (CheckoutMojo) lookupMojo(
147 "checkout",
148 getTestFile( "src/test/resources/mojos/checkout/checkoutWithExcludesIncludes.xml" ) );
149
150 mojo.setCheckoutDirectory( checkoutDir );
151
152 mojo.execute();
153
154 assertTrue( checkoutDir.listFiles().length > 0 );
155 assertTrue( new File( checkoutDir, ".svn").exists() );
156 assertTrue( new File( checkoutDir, "pom.xml" ).exists() );
157 assertFalse( new File( checkoutDir, "readme.txt" ).exists() );
158 assertFalse( new File( checkoutDir, "src/test" ).exists() );
159 assertTrue( new File( checkoutDir, "src/main/java" ).exists() );
160 // olamy those files not exists anymore with svn 1.7
161 //assertTrue( new File( checkoutDir, "src/main/java/.svn" ).exists() );
162 //assertTrue( new File( checkoutDir, "src/main/.svn" ).exists() );
163 }
164
165 public void testEncryptedPasswordFromSettings()
166 throws Exception
167 {
168 File pom = getTestFile( "src/test/resources/mojos/checkout/checkoutEncryptedPasswordFromSettings.xml" );
169 CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", pom );
170 ScmProviderRepositoryWithHost repo =
171 (ScmProviderRepositoryWithHost) mojo.getScmRepository().getProviderRepository();
172
173 assertEquals( "testuser", repo.getUser() );
174 assertEquals( "testpass", repo.getPassword() );
175 assertEquals( "testphrase", repo.getPassphrase() );
176 }
177
178 }