1 package org.apache.maven.scm.provider.vss.commands.edit;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Arrays;
24 import java.util.List;
25
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.ScmTestCase;
28 import org.apache.maven.scm.manager.ScmManager;
29 import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils;
30 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
31 import org.apache.maven.scm.repository.ScmRepository;
32 import org.codehaus.plexus.util.StringUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35
36
37
38
39 public class VssEditCommandTest
40 extends ScmTestCase
41 {
42 private ScmManager scmManager;
43
44 public void setUp()
45 throws Exception
46 {
47 super.setUp();
48
49 scmManager = getScmManager();
50 }
51
52 public void testCommandLine()
53 throws Exception
54 {
55 ScmRepository repository = scmManager
56 .makeScmRepository( "scm:vss|username|password@C:/Program File/Visual Source Safe|D:/myProject" );
57 ScmFileSet fileSet = new ScmFileSet( getTestFile( "target" ) );
58 VssEditCommand command = new VssEditCommand();
59 List<Commandline> commands = command.buildCmdLine( (VssScmProviderRepository) repository.getProviderRepository(), fileSet );
60 Commandline cl = commands.get( 0 );
61 String ssPath = VssCommandLineUtils.getSsDir().replace( '/', File.separatorChar );
62 assertCommandLine( ssPath + "ss Checkout $D:/myProject -R -Yusername,password -I-", fileSet.getBasedir(), cl );
63 }
64
65 public void testCommandLineFileSet()
66 throws Exception
67 {
68 File target = getTestFile( "." );
69 ScmRepository repository = scmManager
70 .makeScmRepository( "scm:vss|username|password@C:/Program File/Visual Source Safe|D:/myProject" );
71 ScmFileSet fileSet = new ScmFileSet( target, "**/target/**/VssEditCommandTest.class" );
72 VssEditCommand command = new VssEditCommand();
73 List<Commandline> commands = command.buildCmdLine( (VssScmProviderRepository) repository.getProviderRepository(), fileSet );
74 Commandline cl =commands.get( 0 );
75 String ssPath = VssCommandLineUtils.getSsDir().replace( '/', File.separatorChar );
76 assertCommandLine(
77 ssPath
78 + "ss Checkout $D:/myProject/target/test-classes/org/apache/maven/scm/provider/vss/commands/edit/VssEditCommandTest.class -Yusername,password -I-",
79 ((File) fileSet.getFileList().get( 0 )).getParentFile().getCanonicalFile(), cl );
80 }
81
82 public void testCommandLineRelativePath()
83 throws Exception
84 {
85 ScmRepository repository = scmManager
86 .makeScmRepository( "scm:vss|username|password@C:/Program File/Visual Source Safe|D:/myProject" );
87 File target = getTestFile( "target" );
88
89 ScmFileSet fileSet = new ScmFileSet(
90 target,
91 new File( target,
92 "test-classes/org/apache/maven/scm/provider/vss/commands/edit/VssEditCommandTest.class" ) );
93 VssEditCommand command = new VssEditCommand();
94 List<Commandline> commands = command.buildCmdLine( (VssScmProviderRepository) repository.getProviderRepository(), fileSet );
95 Commandline cl = commands.get( 0 );
96 String ssPath = VssCommandLineUtils.getSsDir().replace( '/', File.separatorChar );
97 assertCommandLine(
98 ssPath
99 + "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
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
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 }