| 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.codehaus.plexus.util.StringUtils; |
| 26 |
|
| 27 |
import java.io.File; |
| 28 |
|
| 29 |
/** |
| 30 |
* @author <a href="[email protected]">Paul Mackinlay</a> |
| 31 |
*/ |
| 32 |
public abstract class RemoveMojoTest //see https://jira.codehaus.org/browse/SCM-760 |
| 33 |
extends AbstractMojoTestCase |
| 34 |
{ |
| 35 |
|
| 36 |
public void testShouldInvokeP4Delete() |
| 37 |
throws Exception |
| 38 |
{ |
| 39 |
|
| 40 |
if ( !ScmTestCase.isSystemCmd( "p4" ) ) |
| 41 |
{ |
| 42 |
ScmTestCase.printSystemCmdUnavail( "p4", getName() ); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
String testConfig = "src/test/resources/mojos/remove/removeWithPerforce.xml"; |
| 47 |
try |
| 48 |
{ |
| 49 |
RemoveMojo removeMojo = (RemoveMojo) lookupMojo( "remove", getTestFile( testConfig ) ); |
| 50 |
String connectionUrl = removeMojo.getConnectionUrl(); |
| 51 |
connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); |
| 52 |
connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); |
| 53 |
removeMojo.setWorkingDirectory( new File( getBasedir() ) ); |
| 54 |
removeMojo.setConnectionUrl( connectionUrl ); |
| 55 |
|
| 56 |
removeMojo.execute(); |
| 57 |
} |
| 58 |
finally |
| 59 |
{ |
| 60 |
// Just to be sure unedit anything that has been marked for delete |
| 61 |
UnEditMojo unEditMojo = (UnEditMojo) lookupMojo( "unedit", getTestFile( testConfig ) ); |
| 62 |
String connectionUrl = unEditMojo.getConnectionUrl(); |
| 63 |
connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); |
| 64 |
connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); |
| 65 |
unEditMojo.setWorkingDirectory( new File( getBasedir() ) ); |
| 66 |
unEditMojo.setConnectionUrl( connectionUrl ); |
| 67 |
unEditMojo.execute(); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
public void testShouldFailToInvokeP4Delete() |
| 72 |
throws Exception |
| 73 |
{ |
| 74 |
if ( !ScmTestCase.isSystemCmd( "p4" ) ) |
| 75 |
{ |
| 76 |
ScmTestCase.printSystemCmdUnavail( "p4", getName() ); |
| 77 |
return; |
| 78 |
} |
| 79 |
String testConfig = "src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml"; |
| 80 |
try |
| 81 |
{ |
| 82 |
RemoveMojo removeMojo = (RemoveMojo) lookupMojo( "remove", getTestFile( testConfig ) ); |
| 83 |
String connectionUrl = removeMojo.getConnectionUrl(); |
| 84 |
connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); |
| 85 |
connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); |
| 86 |
removeMojo.setWorkingDirectory( new File( getBasedir() ) ); |
| 87 |
removeMojo.setConnectionUrl( connectionUrl ); |
| 88 |
|
| 89 |
try |
| 90 |
{ |
| 91 |
removeMojo.execute(); |
| 92 |
fail( "At least one file needs to be included for removal" ); |
| 93 |
} |
| 94 |
catch ( MojoExecutionException e ) |
| 95 |
{ |
| 96 |
// we're expecting this exception |
| 97 |
} |
| 98 |
} |
| 99 |
finally |
| 100 |
{ |
| 101 |
// Just to be sure unedit anything that has been marked for delete |
| 102 |
UnEditMojo unEditMojo = (UnEditMojo) lookupMojo( "unedit", getTestFile( testConfig ) ); |
| 103 |
String connectionUrl = unEditMojo.getConnectionUrl(); |
| 104 |
connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); |
| 105 |
connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); |
| 106 |
unEditMojo.setWorkingDirectory( new File( getBasedir() ) ); |
| 107 |
unEditMojo.setConnectionUrl( connectionUrl ); |
| 108 |
unEditMojo.execute(); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
} |