001package org.apache.maven.scm.provider.starteam.command.add; 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.ScmTestCase; 024import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils; 025import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository; 026import org.apache.maven.scm.repository.ScmRepository; 027import org.codehaus.plexus.util.cli.Commandline; 028 029import java.io.File; 030 031/** 032 * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a> 033 */ 034public class StarteamAddCommandTest 035 extends ScmTestCase 036{ 037 038 public void testGetCommandLineWithFileOnRoot() 039 throws Exception 040 { 041 042 File testFile = new File( "testfile" ); 043 044 File testFileDir = testFile.getAbsoluteFile().getParentFile(); 045 046 String testFileDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( testFileDir.getAbsolutePath() ); 047 048 String expectedCmd = "stcmd add -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl" + " -fp " + 049 testFileDirAbsolutePath + " -eol on testfile"; 050 051 ScmFileSet fileSet = new ScmFileSet( testFileDir, testFile ); 052 testCommandLine( "scm:starteam:myusername:mypassword@myhost:1234/projecturl", fileSet, "", expectedCmd ); 053 } 054 055 public void testGetCommandLineWithCR() 056 throws Exception 057 { 058 File testFile = new File( "testfile" ); 059 060 File testFileDir = testFile.getAbsoluteFile().getParentFile(); 061 062 String testFileDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( testFileDir.getAbsolutePath() ); 063 064 String expectedCmd = "stcmd add -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl" + " -fp " + 065 testFileDirAbsolutePath + " -cr view_root/dummycr" + " -eol on testfile"; 066 067 ScmFileSet fileSet = new ScmFileSet( testFileDir, testFile ); 068 testCommandLine( "scm:starteam:myusername:mypassword@myhost:1234/projecturl", fileSet, "view_root/dummycr", 069 expectedCmd ); 070 071 } 072 073 public void testGetCommandLineWithFileInSubDir() 074 throws Exception 075 { 076 077 File testFile = new File( "target/testfile" ); 078 079 File testFileDir = testFile.getAbsoluteFile().getParentFile(); 080 081 String testFileDirAbsolutePath = 082 StarteamCommandLineUtils.toJavaPath( testFileDir.getAbsolutePath() ) + "/target"; 083 084 String expectedCmd = "stcmd add -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl/target" + 085 " -fp " + testFileDirAbsolutePath + " -eol on testfile"; 086 087 ScmFileSet fileSet = new ScmFileSet( testFileDir, testFile ); 088 testCommandLine( "scm:starteam:myusername:mypassword@myhost:1234/projecturl", fileSet, null, expectedCmd ); 089 090 } 091 092 // ---------------------------------------------------------------------- 093 // 094 // ---------------------------------------------------------------------- 095 096 private void testCommandLine( String scmUrl, ScmFileSet fileSet, String crPath, String commandLine ) 097 throws Exception 098 { 099 ScmRepository repo = getScmManager().makeScmRepository( scmUrl ); 100 101 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo.getProviderRepository(); 102 103 Commandline cl = StarteamAddCommand.createCommandLine( repository, fileSet, crPath ); 104 105 assertCommandLine( commandLine, null, cl ); 106 } 107}