1 package org.apache.maven.scm.provider.perforce.command.changelog;
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.scm.ScmTestCase;
23 import org.apache.maven.scm.ScmRevision;
24 import org.apache.maven.scm.ScmVersion;
25 import org.apache.maven.scm.provider.perforce.PerforceScmProvider;
26 import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository;
27 import org.apache.maven.scm.repository.ScmRepository;
28 import org.codehaus.plexus.util.cli.Commandline;
29
30 import java.io.File;
31 import java.text.SimpleDateFormat;
32 import java.util.Date;
33
34
35
36
37
38
39 public class PerforceChangeLogCommandTest
40 extends ScmTestCase
41 {
42 private static final File workingDirectory = getTestFile( "target/perforce-changelog-command-test" );
43
44 private static final String cmdPrefix = "p4 -d " + workingDirectory.getAbsolutePath();
45
46 public void testGetCommandLine()
47 throws Exception
48 {
49 testCommandLine( "scm:perforce://depot/projects/pathname", cmdPrefix + " changes -t ..." );
50 }
51
52 public void testGetCommandLineWithHost()
53 throws Exception
54 {
55 testCommandLine( "scm:perforce:a:username@//depot/projects/pathname",
56 cmdPrefix + " -p a -u username changes -t ..." );
57 }
58
59 public void testGetCommandLineWithHostAndPort()
60 throws Exception
61 {
62 System.setProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY, "foo" );
63 testCommandLine( "scm:perforce:myhost:1234:username@//depot/projects/pathname",
64 cmdPrefix + " -p myhost:1234 -u username -c foo changes -t ..." );
65 }
66
67
68
69
70
71 private void testCommandLine( String scmUrl, String commandLine )
72 throws Exception
73 {
74 ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
75
76 PerforceScmProviderRepository repo = (PerforceScmProviderRepository) repository.getProviderRepository();
77
78 Commandline cl = PerforceChangeLogCommand.createCommandLine( repo, workingDirectory,
79 System.getProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY ),
80 null, null, null, null, null );
81
82 assertCommandLine( commandLine, null, cl );
83 }
84
85 public void testGetCommandLineWithStartAndEndDates()
86 throws Exception
87 {
88 System.setProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY, "foo" );
89 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
90 testCommandLineDates( cmdPrefix + " -c foo changes -t ...@2008/07/15:00:00:00,2008/07/16:00:00:00", sdf.parse("2008/07/15 00:00:00"), sdf.parse("2008/07/16 00:00:00") );
91 }
92
93 public void testGetCommandLineWithStartAndEndChangelists()
94 throws Exception
95 {
96 System.setProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY, "foo" );
97 testCommandLineRevs( cmdPrefix + " -c foo changes -t ...@123456,234567", new ScmRevision( "123456" ), new ScmRevision( "234567" ) );
98 }
99
100 private void testCommandLineRevs( String commandLine, ScmVersion version1, ScmVersion version2 )
101 throws Exception
102 {
103 ScmRepository repository = getScmManager().makeScmRepository( "scm:perforce://depot/projects/pathname");
104
105 PerforceScmProviderRepository repo = (PerforceScmProviderRepository) repository.getProviderRepository();
106
107 Commandline cl = PerforceChangeLogCommand.createCommandLine( repo, workingDirectory, System.getProperty(
108 PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY ), null, null, null, version1, version2 );
109
110 assertCommandLine( commandLine, null, cl );
111 }
112
113 private void testCommandLineDates( String commandLine, Date date1, Date date2 )
114 throws Exception
115 {
116 ScmRepository repository = getScmManager().makeScmRepository( "scm:perforce://depot/projects/pathname");
117
118 PerforceScmProviderRepository repo = (PerforceScmProviderRepository) repository.getProviderRepository();
119
120 Commandline cl = PerforceChangeLogCommand.createCommandLine( repo, workingDirectory, System.getProperty(
121 PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY ), null, date1, date2, null, null );
122
123 assertCommandLine( commandLine, null, cl );
124 }
125 }