001package org.apache.maven.scm.provider.perforce.command.changelog; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.scm.ScmTestCase; 023import org.apache.maven.scm.ScmRevision; 024import org.apache.maven.scm.ScmVersion; 025import org.apache.maven.scm.provider.perforce.PerforceScmProvider; 026import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository; 027import org.apache.maven.scm.repository.ScmRepository; 028import org.codehaus.plexus.util.cli.Commandline; 029 030import java.io.File; 031import java.text.SimpleDateFormat; 032import java.util.Date; 033 034/** 035 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 036 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> 037 * 038 */ 039public class PerforceChangeLogCommandTest 040 extends ScmTestCase 041{ 042 private static final File workingDirectory = getTestFile( "target/perforce-changelog-command-test" ); 043 044 private static final String cmdPrefix = "p4 -d " + workingDirectory.getAbsolutePath(); 045 046 @Override 047 protected void tearDown() 048 throws Exception 049 { 050 // Some tests don't expect this property, so when tests are executed in random order these might fail 051 System.clearProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY ); 052 } 053 054 public void testGetCommandLine() 055 throws Exception 056 { 057 testCommandLine( "scm:perforce://depot/projects/pathname", cmdPrefix + " changes -t ..." ); 058 } 059 060 public void testGetCommandLineWithHost() 061 throws Exception 062 { 063 testCommandLine( "scm:perforce:a:username@//depot/projects/pathname", 064 cmdPrefix + " -p a -u username changes -t ..." ); 065 } 066 067 public void testGetCommandLineWithHostAndPort() 068 throws Exception 069 { 070 System.setProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY, "foo" ); 071 testCommandLine( "scm:perforce:myhost:1234:username@//depot/projects/pathname", 072 cmdPrefix + " -p myhost:1234 -u username -c foo changes -t ..." ); 073 } 074 075 // ---------------------------------------------------------------------- 076 // 077 // ---------------------------------------------------------------------- 078 079 private void testCommandLine( String scmUrl, String commandLine ) 080 throws Exception 081 { 082 ScmRepository repository = getScmManager().makeScmRepository( scmUrl ); 083 084 PerforceScmProviderRepository repo = (PerforceScmProviderRepository) repository.getProviderRepository(); 085 086 Commandline cl = PerforceChangeLogCommand.createCommandLine( repo, workingDirectory, 087 System.getProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY ), 088 null, null, null, null, null ); 089 090 assertCommandLine( commandLine, null, cl ); 091 } 092 093 public void testGetCommandLineWithStartAndEndDates() 094 throws Exception 095 { 096 System.setProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY, "foo" ); 097 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 098 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") ); 099 } 100 101 public void testGetCommandLineWithStartAndEndChangelists() 102 throws Exception 103 { 104 System.setProperty( PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY, "foo" ); 105 testCommandLineRevs( cmdPrefix + " -c foo changes -t ...@123456,234567", new ScmRevision( "123456" ), new ScmRevision( "234567" ) ); 106 } 107 108 private void testCommandLineRevs( String commandLine, ScmVersion version1, ScmVersion version2 ) 109 throws Exception 110 { 111 ScmRepository repository = getScmManager().makeScmRepository( "scm:perforce://depot/projects/pathname"); 112 113 PerforceScmProviderRepository repo = (PerforceScmProviderRepository) repository.getProviderRepository(); 114 115 Commandline cl = PerforceChangeLogCommand.createCommandLine( repo, workingDirectory, System.getProperty( 116 PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY ), null, null, null, version1, version2 ); 117 118 assertCommandLine( commandLine, null, cl ); 119 } 120 121 private void testCommandLineDates( String commandLine, Date date1, Date date2 ) 122 throws Exception 123 { 124 ScmRepository repository = getScmManager().makeScmRepository( "scm:perforce://depot/projects/pathname"); 125 126 PerforceScmProviderRepository repo = (PerforceScmProviderRepository) repository.getProviderRepository(); 127 128 Commandline cl = PerforceChangeLogCommand.createCommandLine( repo, workingDirectory, System.getProperty( 129 PerforceScmProvider.DEFAULT_CLIENTSPEC_PROPERTY ), null, date1, date2, null, null ); 130 131 assertCommandLine( commandLine, null, cl ); 132 } 133}