1 package org.apache.maven.scm.provider.vss.commands;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmTestCase;
23
24 import java.io.File;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27
28
29
30
31
32 public class VssCommandLineUtilsTest
33 extends ScmTestCase
34 {
35
36 private static final String VSS_DIRECTORY_PROPERTY = "vssDirectory";
37
38
39
40 public void setUp()
41 throws Exception
42 {
43 super.setUp();
44 System.setProperty( VSS_DIRECTORY_PROPERTY, "" );
45
46
47 }
48
49 public void testGetSettings()
50 throws IOException
51 {
52
53
54
55
56
57
58
59
60 final String vssInstallPath = "c:\\wherever";
61 final String vssInstallPathAlt = "c:\\somewhere";
62 final String settingsXml =
63 "<vss-settings><vssDirectory>" + vssInstallPath + "</vssDirectory></vss-settings>";
64 final String settingsFilename = "vss-settings.xml";
65 final String backupFilename = settingsFilename + ".backup";
66 boolean preExistingScmFolder = false;
67 boolean preExistingSettings = false;
68
69
70
71
72 File scmUserHome = new File( getTestFile( "target/vssdir" ), ".scm" );
73 if ( scmUserHome.exists() )
74 {
75 preExistingScmFolder = true;
76 File settingsFile = new File( scmUserHome, settingsFilename );
77 if ( settingsFile.exists() )
78 {
79 preExistingSettings = true;
80 settingsFile.renameTo( new File( scmUserHome, backupFilename ) );
81 }
82 }
83 else
84 {
85 scmUserHome.mkdirs();
86 }
87
88
89
90
91 File testSettings = new File( scmUserHome, settingsFilename );
92 FileOutputStream fos = new FileOutputStream( testSettings );
93 fos.write( settingsXml.getBytes() );
94 fos.flush();
95 fos.close();
96 fos = null;
97
98
99
100
101 VssCommandLineUtils.setScmConfDir( scmUserHome );
102 assertEquals( vssInstallPath, VssCommandLineUtils.getSettings().getVssDirectory() );
103
104
105
106
107 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathAlt );
108 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathAlt ) );
109 assertEquals( vssInstallPathAlt, VssCommandLineUtils.getSettings().getVssDirectory() );
110
111
112
113
114 testSettings.delete();
115
116
117
118
119 assertEquals( vssInstallPathAlt, VssCommandLineUtils.getSettings().getVssDirectory() );
120
121
122
123
124 if ( preExistingSettings )
125 {
126 File backup = new File( scmUserHome, backupFilename );
127 backup.renameTo( new File( scmUserHome, settingsFilename ) );
128 }
129
130 if ( !preExistingScmFolder )
131 {
132 scmUserHome.delete();
133 }
134
135 }
136
137 public void testGetSsDir()
138 {
139 final String vssInstallPathWindowsStyle = "c:\\vss\\bin";
140 final String vssInstallPathUnixStyle = "c:/vss/bin";
141 final String targetValue = "c:/vss/bin/";
142
143
144 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathWindowsStyle );
145 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathWindowsStyle ) );
146 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
147
148
149 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle );
150 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathUnixStyle ) );
151 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
152
153
154 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathWindowsStyle + "\\" );
155 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathWindowsStyle ) );
156 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
157
158
159 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle + "/" );
160 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathUnixStyle ) );
161 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
162
163
164 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle + "\\" );
165 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathUnixStyle ) );
166 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
167
168 }
169 }