001package org.apache.maven.scm.provider.starteam.command.checkin; 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.ScmFileSet; 023import org.apache.maven.scm.ScmRevision; 024import org.apache.maven.scm.ScmTestCase; 025import org.apache.maven.scm.ScmVersion; 026import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils; 027import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository; 028import org.apache.maven.scm.repository.ScmRepository; 029import org.codehaus.plexus.util.cli.Commandline; 030 031import java.io.File; 032 033/** 034 * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a> 035 */ 036public class StarteamCheckInCommandTest 037 extends ScmTestCase 038{ 039 040 public void testGetCommandLineWithWorkingDirectory() 041 throws Exception 042 { 043 ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() ); 044 045 String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() ); 046 047 String starteamUrl = "user:password@host:1234/project/view"; 048 String mavenUrl = "scm:starteam:" + starteamUrl; 049 050 String expectedCmd = 051 "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + " -fp " + workingCopy + " -is -f NCI -eol on"; 052 053 testCommandLine( mavenUrl, fileSet, "", new ScmRevision( "" ), "", "", expectedCmd ); 054 055 } 056 057 public void testGetCommandLineWithFileOnRoot() 058 throws Exception 059 { 060 ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "test.txt" ) ); 061 062 String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() ); 063 064 String starteamUrl = "user:password@host:1234/project/view"; 065 String mavenUrl = "scm:starteam:" + starteamUrl; 066 067 String expectedCmd = 068 "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + " -fp " + workingCopy + " -eol on test.txt"; 069 070 testCommandLine( mavenUrl, fileSet, "", new ScmRevision( "" ), "", "", expectedCmd ); 071 072 } 073 074 public void testGetCommandLineWithFileInSubDir() 075 throws Exception 076 { 077 ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "src/test.txt" ) ); 078 079 String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() ); 080 081 String starteamUrl = "user:password@host:1234/project/view"; 082 String mavenUrl = "scm:starteam:" + starteamUrl; 083 084 String expectedCmd = "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + "/src" + " -fp " + workingCopy + 085 "/src" + " -eol on test.txt"; 086 087 testCommandLine( mavenUrl, fileSet, "", new ScmRevision( "" ), "", "", expectedCmd ); 088 089 } 090 091 public void testGetCommandLineWithDirInWorkingDirectory() 092 throws Exception 093 { 094 //physically create dir so that cmd can be generated correctly 095 new File( getWorkingCopy(), "src" ).mkdirs(); 096 097 ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "src" ) ); 098 099 String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() ); 100 101 String starteamUrl = "user:password@host:1234/project/view"; 102 String mavenUrl = "scm:starteam:" + starteamUrl; 103 104 String expectedCmd = "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + "/src" + " -fp " + workingCopy + 105 "/src" + " -is -f NCI -eol on"; 106 107 testCommandLine( mavenUrl, fileSet, "", new ScmRevision( "" ), "", "", expectedCmd ); 108 109 } 110 111 public void testGetCommandLineWithEmptyIssueValue() 112 throws Exception 113 { 114 ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "test.txt" ) ); 115 116 String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() ); 117 118 String starteamUrl = "user:password@host:1234/project/view"; 119 String mavenUrl = "scm:starteam:" + starteamUrl; 120 121 String expectedCmd = 122 "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + " -fp " + workingCopy + " -active -eol on test.txt"; 123 124 testCommandLine( mavenUrl, fileSet, null, new ScmRevision( "" ), "active", " ", expectedCmd ); 125 } 126// ---------------------------------------------------------------------- 127// 128// ---------------------------------------------------------------------- 129 130 private void testCommandLine( String scmUrl, ScmFileSet fileSet, String message, ScmVersion version, 131 String issueType, String issueValue, String commandLine ) 132 throws Exception 133 { 134 ScmRepository repo = getScmManager().makeScmRepository( scmUrl ); 135 136 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo.getProviderRepository(); 137 138 Commandline cl = 139 StarteamCheckInCommand.createCommandLine( repository, fileSet, message, version, issueType, issueValue ); 140 141 assertCommandLine( commandLine, null, cl ); 142 } 143 144 145}