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.codehaus.plexus.util.StringUtils;
26
27 import java.io.File;
28
29
30
31
32 public abstract class RemoveMojoTest
33 extends AbstractMojoTestCase
34 {
35
36 public void testShouldInvokeP4Delete()
37 throws Exception
38 {
39
40 if ( !ScmTestCase.isSystemCmd( "p4" ) )
41 {
42 System.out.println( "'skip test as p4 is not available" );
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
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 System.out.println( "'skip test as p4 is not available" );
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
97 }
98 }
99 finally
100 {
101
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 }