001package org.apache.maven.scm.provider.vss.commands.edit; 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 java.io.File; 023import java.util.Arrays; 024import java.util.List; 025 026import org.apache.maven.scm.ScmFileSet; 027import org.apache.maven.scm.ScmTestCase; 028import org.apache.maven.scm.manager.ScmManager; 029import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils; 030import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository; 031import org.apache.maven.scm.repository.ScmRepository; 032import org.codehaus.plexus.util.StringUtils; 033import org.codehaus.plexus.util.cli.Commandline; 034 035/** 036 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 037 * 038 */ 039public class VssEditCommandTest 040 extends ScmTestCase 041{ 042 private ScmManager scmManager; 043 044 public void setUp() 045 throws Exception 046 { 047 super.setUp(); 048 049 scmManager = getScmManager(); 050 } 051 052 public void testCommandLine() 053 throws Exception 054 { 055 ScmRepository repository = scmManager 056 .makeScmRepository( "scm:vss|username|password@C:/Program File/Visual Source Safe|D:/myProject" ); 057 ScmFileSet fileSet = new ScmFileSet( getTestFile( "target" ) ); 058 VssEditCommand command = new VssEditCommand(); 059 List<Commandline> commands = command.buildCmdLine( (VssScmProviderRepository) repository.getProviderRepository(), fileSet ); 060 Commandline cl = commands.get( 0 ); 061 String ssPath = VssCommandLineUtils.getSsDir().replace( '/', File.separatorChar ); 062 assertCommandLine( ssPath + "ss Checkout $D:/myProject -R -Yusername,password -I-", fileSet.getBasedir(), cl ); 063 } 064 065 public void testCommandLineFileSet() 066 throws Exception 067 { 068 File target = getTestFile( "." ); 069 ScmRepository repository = scmManager 070 .makeScmRepository( "scm:vss|username|password@C:/Program File/Visual Source Safe|D:/myProject" ); 071 ScmFileSet fileSet = new ScmFileSet( target, "**/target/**/VssEditCommandTest.class" ); 072 VssEditCommand command = new VssEditCommand(); 073 List<Commandline> commands = command.buildCmdLine( (VssScmProviderRepository) repository.getProviderRepository(), fileSet ); 074 Commandline cl =commands.get( 0 ); 075 String ssPath = VssCommandLineUtils.getSsDir().replace( '/', File.separatorChar ); 076 assertCommandLine( 077 ssPath 078 + "ss Checkout $D:/myProject/target/test-classes/org/apache/maven/scm/provider/vss/commands/edit/VssEditCommandTest.class -Yusername,password -I-", 079 ((File) fileSet.getFileList().get( 0 )).getParentFile().getCanonicalFile(), cl ); 080 } 081 082 public void testCommandLineRelativePath() 083 throws Exception 084 { 085 ScmRepository repository = scmManager 086 .makeScmRepository( "scm:vss|username|password@C:/Program File/Visual Source Safe|D:/myProject" ); 087 File target = getTestFile( "target" ); 088 089 ScmFileSet fileSet = new ScmFileSet( 090 target, 091 new File( target, 092 "test-classes/org/apache/maven/scm/provider/vss/commands/edit/VssEditCommandTest.class" ) ); 093 VssEditCommand command = new VssEditCommand(); 094 List<Commandline> commands = command.buildCmdLine( (VssScmProviderRepository) repository.getProviderRepository(), fileSet ); 095 Commandline cl = commands.get( 0 ); 096 String ssPath = VssCommandLineUtils.getSsDir().replace( '/', File.separatorChar ); 097 assertCommandLine( 098 ssPath 099 + "ss Checkout $D:/myProject/test-classes/org/apache/maven/scm/provider/vss/commands/edit/VssEditCommandTest.class -Yusername,password -I-", 100 ((File) fileSet.getFileList().get( 0 )).getParentFile().getCanonicalFile(), cl ); 101 } 102 103 public void testCommandLineMultipleFiles() 104 throws Exception 105 { 106 ScmRepository repository = scmManager 107 .makeScmRepository( "scm:vss|username|password@C:/Program File/Visual Source Safe|D:/myProject" ); 108 File target = getTestFile( "target" ); 109 ScmFileSet fileSet = new ScmFileSet( target, Arrays 110 .asList( new File[] { 111 new File( target, 112 "test-classes/org/apache/maven/scm/provider/vss/commands/edit/VssEditCommandTest.class" ), 113 new File( target, "test-classes/META-INF/LICENSE" ) } ) ); 114 VssEditCommand command = new VssEditCommand(); 115 List<Commandline> commands = command.buildCmdLine( (VssScmProviderRepository) repository.getProviderRepository(), fileSet ); 116 assertEquals( 2, commands.size() ); 117 118 Commandline cl; 119 String ssPath; 120 121 cl = (Commandline) commands.get( 0 ); 122 ssPath = VssCommandLineUtils.getSsDir().replace( '/', File.separatorChar ); 123 // vss is windauze so don't care about the case 124 assertEquals( StringUtils.lowerCase( normSep( target.getCanonicalPath() 125 + "/test-classes/org/apache/maven/scm/provider/vss/commands/edit" ) ), StringUtils.lowerCase( cl 126 .getWorkingDirectory().getCanonicalPath() ) ); 127 assertCommandLine( 128 ssPath 129 + "ss Checkout $D:/myProject/test-classes/org/apache/maven/scm/provider/vss/commands/edit/VssEditCommandTest.class -Yusername,password -I-", 130 ((File) fileSet.getFileList().get( 0 )).getParentFile().getCanonicalFile(), cl ); 131 132 cl = (Commandline) commands.get( 1 ); 133 ssPath = VssCommandLineUtils.getSsDir().replace( '/', File.separatorChar ); 134 // vss is windauze so don't care about the case 135 assertEquals( StringUtils.lowerCase( normSep( target.getCanonicalPath() + "/test-classes/META-INF" ) ), StringUtils 136 .lowerCase( cl.getWorkingDirectory().getCanonicalPath() ) ); 137 assertCommandLine( ssPath + "ss Checkout $D:/myProject/test-classes/META-INF/LICENSE -Yusername,password -I-", 138 ((File) fileSet.getFileList().get( 1 )).getParentFile().getCanonicalFile() , cl ); 139 140 } 141 142 private String normSep( String str ) 143 { 144 return str.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ); 145 } 146 147}