1 | |
package org.apache.maven.scm.provider.cvslib.command.update; |
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.ScmFile; |
23 | |
import org.apache.maven.scm.ScmFileSet; |
24 | |
import org.apache.maven.scm.ScmFileStatus; |
25 | |
import org.apache.maven.scm.command.update.UpdateScmResult; |
26 | |
import org.apache.maven.scm.manager.ScmManager; |
27 | |
import org.apache.maven.scm.provider.cvslib.AbstractCvsScmTest; |
28 | |
import org.apache.maven.scm.provider.cvslib.CvsScmTestUtils; |
29 | |
import org.apache.maven.scm.repository.ScmRepository; |
30 | |
import org.codehaus.plexus.util.FileUtils; |
31 | |
import org.codehaus.plexus.util.IOUtil; |
32 | |
|
33 | |
import java.io.File; |
34 | |
import java.io.FileWriter; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class CvsUpdateCommandTest |
42 | |
extends AbstractCvsScmTest |
43 | |
{ |
44 | |
private File repository; |
45 | |
|
46 | |
private File workingDirectory; |
47 | |
|
48 | |
private File assertionDirectory; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public void setUp() |
54 | |
throws Exception |
55 | |
{ |
56 | 0 | super.setUp(); |
57 | |
|
58 | 0 | repository = getTestFile( "target/update-test/repository" ); |
59 | |
|
60 | 0 | workingDirectory = getTestFile( "target/update-test/working-directory" ); |
61 | |
|
62 | 0 | assertionDirectory = getTestFile( "target/update-test/assertion-directory" ); |
63 | |
|
64 | 0 | CvsScmTestUtils.initRepo( repository, workingDirectory, assertionDirectory ); |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
protected String getModule() |
71 | |
{ |
72 | 0 | return "test-repo/update"; |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public void testCvsUpdate() |
79 | |
throws Exception |
80 | |
{ |
81 | |
|
82 | 0 | FileWriter writer = null; |
83 | |
try |
84 | |
{ |
85 | 0 | if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) ) |
86 | |
{ |
87 | 0 | System.err.println( |
88 | |
"'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored " + getName() + "." ); |
89 | |
return; |
90 | |
} |
91 | |
|
92 | 0 | ScmManager scmManager = getScmManager(); |
93 | |
|
94 | 0 | String scmUrl = CvsScmTestUtils.getScmUrl( repository, getModule() ); |
95 | |
|
96 | |
|
97 | 0 | String arguments = |
98 | |
"-f -d " + repository.getAbsolutePath() + " " + "co -d " + workingDirectory.getName() + " " |
99 | |
+ getModule(); |
100 | |
|
101 | 0 | CvsScmTestUtils.executeCVS( workingDirectory.getParentFile(), arguments ); |
102 | |
|
103 | |
|
104 | 0 | arguments = "-f -d " + repository.getAbsolutePath() + " " + "co -d " + assertionDirectory.getName() + " " |
105 | |
+ getModule(); |
106 | |
|
107 | 0 | CvsScmTestUtils.executeCVS( assertionDirectory.getParentFile(), arguments ); |
108 | |
|
109 | |
|
110 | 0 | ScmRepository scmRepository = scmManager.makeScmRepository( scmUrl ); |
111 | |
|
112 | 0 | UpdateScmResult result = scmManager.update( scmRepository, new ScmFileSet( assertionDirectory ) ); |
113 | |
|
114 | 0 | assertNotNull( result ); |
115 | |
|
116 | 0 | if ( !result.isSuccess() ) |
117 | |
{ |
118 | 0 | System.out.println( "result.providerMessage: " + result.getProviderMessage() ); |
119 | |
|
120 | 0 | System.out.println( "result.commandOutput: " + result.getCommandOutput() ); |
121 | |
|
122 | 0 | fail( "Command failed" ); |
123 | |
} |
124 | |
|
125 | 0 | assertNull( result.getProviderMessage() ); |
126 | |
|
127 | 0 | assertNull( result.getCommandOutput() ); |
128 | |
|
129 | 0 | assertNotNull( result.getUpdatedFiles() ); |
130 | |
|
131 | 0 | assertEquals( 0, result.getUpdatedFiles().size() ); |
132 | |
|
133 | |
|
134 | 0 | File fooJava = new File( workingDirectory, "Foo.java" ); |
135 | |
|
136 | 0 | String content = FileUtils.fileRead( fooJava ); |
137 | |
|
138 | 0 | writer = new FileWriter( fooJava ); |
139 | |
|
140 | 0 | writer.write( content + System.getProperty( "line.separator" ) ); |
141 | 0 | writer.write( "extra line" ); |
142 | |
|
143 | 0 | writer.close(); |
144 | |
|
145 | |
|
146 | 0 | writer = new FileWriter( new File( workingDirectory, "New.txt" ) ); |
147 | |
|
148 | 0 | writer.write( "new file" ); |
149 | |
|
150 | 0 | writer.close(); |
151 | |
|
152 | 0 | arguments = "-f -d " + repository.getAbsolutePath() + " add New.txt"; |
153 | |
|
154 | 0 | CvsScmTestUtils.executeCVS( workingDirectory, arguments ); |
155 | |
|
156 | |
|
157 | 0 | arguments = "-f -d " + repository.getAbsolutePath() + " commit -m ."; |
158 | |
|
159 | 0 | CvsScmTestUtils.executeCVS( workingDirectory, arguments ); |
160 | |
|
161 | |
|
162 | 0 | result = scmManager.update( scmRepository, new ScmFileSet( assertionDirectory ) ); |
163 | |
|
164 | 0 | assertNotNull( result ); |
165 | |
|
166 | 0 | if ( !result.isSuccess() ) |
167 | |
{ |
168 | 0 | System.out.println( "result.providerMessage: " + result.getProviderMessage() ); |
169 | |
|
170 | 0 | System.out.println( "result.commandOutput: " + result.getCommandOutput() ); |
171 | |
|
172 | 0 | fail( "Command failed" ); |
173 | |
} |
174 | |
|
175 | 0 | assertNull( result.getProviderMessage() ); |
176 | |
|
177 | 0 | assertNull( result.getCommandOutput() ); |
178 | |
|
179 | 0 | assertNotNull( result.getUpdatedFiles() ); |
180 | |
|
181 | 0 | assertEquals( 2, result.getUpdatedFiles().size() ); |
182 | |
|
183 | 0 | ScmFile file1 = result.getUpdatedFiles().get( 0 ); |
184 | |
|
185 | 0 | assertPath( "Foo.java", file1.getPath() ); |
186 | |
|
187 | 0 | assertEquals( ScmFileStatus.UPDATED, file1.getStatus() ); |
188 | |
|
189 | 0 | ScmFile file2 = result.getUpdatedFiles().get( 1 ); |
190 | |
|
191 | 0 | assertPath( "New.txt", file2.getPath() ); |
192 | |
|
193 | 0 | assertEquals( ScmFileStatus.UPDATED, file2.getStatus() ); |
194 | |
} |
195 | |
finally |
196 | |
{ |
197 | 0 | IOUtil.close( writer ); |
198 | 0 | } |
199 | 0 | } |
200 | |
} |