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
45
46 }
47
48 public void testGetSettings()
49 throws IOException
50 {
51
52
53
54
55
56
57
58
59 final String vssInstallPath = "c:\\wherever";
60 final String vssInstallPathAlt = "c:\\somewhere";
61 final String settingsXml =
62 "<vss-settings><Settings><vssDirectory>" + vssInstallPath + "</vssDirectory></Settings></vss-settings>";
63 final String settingsFilename = "vss-settings.xml";
64 final String backupFilename = settingsFilename + ".backup";
65 boolean preExistingScmFolder = false;
66 boolean preExistingSettings = false;
67
68
69
70
71 File scmUserHome = new File( getTestFile( "target/vssdir" ), ".scm" );
72 if ( scmUserHome.exists() )
73 {
74 preExistingScmFolder = true;
75 File settingsFile = new File( scmUserHome, settingsFilename );
76 if ( settingsFile.exists() )
77 {
78 preExistingSettings = true;
79 settingsFile.renameTo( new File( scmUserHome, backupFilename ) );
80 }
81 }
82 else
83 {
84 scmUserHome.mkdirs();
85 }
86
87
88
89
90 File testSettings = new File( scmUserHome, settingsFilename );
91 FileOutputStream fos = new FileOutputStream( testSettings );
92 fos.write( settingsXml.getBytes() );
93 fos.flush();
94 fos.close();
95 fos = null;
96
97
98
99
100 VssCommandLineUtils.setScmConfDir( scmUserHome );
101 assertEquals( vssInstallPath, VssCommandLineUtils.getSettings().getVssDirectory() );
102
103
104
105
106 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathAlt );
107 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathAlt ) );
108 assertEquals( vssInstallPathAlt, VssCommandLineUtils.getSettings().getVssDirectory() );
109
110
111
112
113 testSettings.delete();
114
115
116
117
118 assertEquals( vssInstallPathAlt, VssCommandLineUtils.getSettings().getVssDirectory() );
119
120
121
122
123 if ( preExistingSettings )
124 {
125 File backup = new File( scmUserHome, backupFilename );
126 backup.renameTo( new File( scmUserHome, settingsFilename ) );
127 }
128
129 if ( !preExistingScmFolder )
130 {
131 scmUserHome.delete();
132 }
133
134 }
135
136 public void testGetSsDir()
137 {
138 final String vssInstallPathWindowsStyle = "c:\\vss\\bin";
139 final String vssInstallPathUnixStyle = "c:/vss/bin";
140 final String targetValue = "c:/vss/bin/";
141
142
143 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathWindowsStyle );
144 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathWindowsStyle ) );
145 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
146
147
148 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle );
149 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathUnixStyle ) );
150 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
151
152
153 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathWindowsStyle + "\\" );
154 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathWindowsStyle ) );
155 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
156
157
158 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle + "/" );
159 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathUnixStyle ) );
160 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
161
162
163 System.setProperty( VSS_DIRECTORY_PROPERTY, vssInstallPathUnixStyle + "\\" );
164 VssCommandLineUtils.setScmConfDir( new File( vssInstallPathUnixStyle ) );
165 assertEquals( targetValue, VssCommandLineUtils.getSsDir() );
166
167 }
168 }