View Javadoc

1   package org.apache.maven.scm.provider.perforce.command.changelog;
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.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   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
36   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
37   * @version $Id: PerforceChangeLogCommandTest.java 770320 2009-04-30 16:50:15Z olamy $
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 }