1 | |
package org.apache.maven.scm.tck.command.update; |
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.Date; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.List; |
26 | |
import java.util.TreeSet; |
27 | |
|
28 | |
import org.apache.maven.scm.ChangeSet; |
29 | |
import org.apache.maven.scm.ScmFile; |
30 | |
import org.apache.maven.scm.ScmFileSet; |
31 | |
import org.apache.maven.scm.ScmFileStatus; |
32 | |
import org.apache.maven.scm.ScmTckTestCase; |
33 | |
import org.apache.maven.scm.ScmTestCase; |
34 | |
import org.apache.maven.scm.command.checkin.CheckInScmResult; |
35 | |
import org.apache.maven.scm.command.update.UpdateScmResult; |
36 | |
import org.apache.maven.scm.manager.ScmManager; |
37 | |
import org.apache.maven.scm.repository.ScmRepository; |
38 | |
import org.codehaus.plexus.util.FileUtils; |
39 | |
import org.codehaus.plexus.util.StringUtils; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | 0 | public abstract class UpdateCommandTckTest |
60 | |
extends ScmTckTestCase |
61 | |
{ |
62 | |
|
63 | |
private void commit( File workingDirectory, ScmRepository repository ) |
64 | |
throws Exception |
65 | |
{ |
66 | 0 | CheckInScmResult result = getScmManager().checkIn( repository, new ScmFileSet( workingDirectory ), "No msg" ); |
67 | |
|
68 | 0 | assertTrue( "Check result was successful, output: " + result.getCommandOutput(), result.isSuccess() ); |
69 | |
|
70 | 0 | List<ScmFile> committedFiles = result.getCheckedInFiles(); |
71 | |
|
72 | 0 | assertEquals( |
73 | |
"Expected 3 files in the committed files list:\n " + StringUtils.join( committedFiles.iterator(), "\n " ), |
74 | |
3, committedFiles.size() ); |
75 | 0 | } |
76 | |
|
77 | |
public void testUpdateCommand() |
78 | |
throws Exception |
79 | |
{ |
80 | |
|
81 | 0 | FileUtils.deleteDirectory( getUpdatingCopy() ); |
82 | |
|
83 | 0 | assertFalse( getUpdatingCopy().exists() ); |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 0 | ScmRepository repository = makeScmRepository( getScmUrl() ); |
90 | |
|
91 | 0 | checkOut( getUpdatingCopy(), repository ); |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | 0 | ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" ); |
108 | |
|
109 | |
|
110 | 0 | ScmTestCase.makeFile( getWorkingCopy(), "/project.xml", "changed project.xml" ); |
111 | |
|
112 | 0 | addToWorkingTree( getWorkingCopy(), new File( "project.xml" ), repository ); |
113 | |
|
114 | |
|
115 | 0 | ScmTestCase.makeDirectory( getWorkingCopy(), "/src/test/java/org" ); |
116 | |
|
117 | 0 | addToWorkingTree( getWorkingCopy(), new File( "src/test/java/org" ), repository ); |
118 | |
|
119 | |
|
120 | 0 | ScmTestCase.makeFile( getWorkingCopy(), "/src/main/java/org/Foo.java" ); |
121 | |
|
122 | 0 | addToWorkingTree( getWorkingCopy(), new File( "src/main/java/org" ), repository ); |
123 | |
|
124 | |
|
125 | 0 | addToWorkingTree( getWorkingCopy(), new File( "src/main/java/org/Foo.java" ), repository ); |
126 | |
|
127 | 0 | ScmManager scmManager = getScmManager(); |
128 | |
|
129 | 0 | Date lastUpdate = new Date( System.currentTimeMillis() - 1000000 ); |
130 | |
|
131 | 0 | commit( getWorkingCopy(), repository ); |
132 | |
|
133 | 0 | Thread.sleep( 5000 ); |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | 0 | UpdateScmResult result = scmManager.update( repository, new ScmFileSet( getUpdatingCopy() ), lastUpdate ); |
140 | |
|
141 | 0 | assertNotNull( "The command returned a null result.", result ); |
142 | |
|
143 | 0 | assertResultIsSuccess( result ); |
144 | |
|
145 | 0 | List<ScmFile> updatedFiles = result.getUpdatedFiles(); |
146 | |
|
147 | 0 | List<ChangeSet> changedSets = result.getChanges(); |
148 | |
|
149 | 0 | assertEquals( "Expected 3 files in the updated files list " + updatedFiles, 3, updatedFiles.size() ); |
150 | |
|
151 | 0 | assertNotNull( "The changed files list is null", changedSets ); |
152 | |
|
153 | 0 | assertFalse( "The changed files list is empty ", changedSets.isEmpty() ); |
154 | |
|
155 | 0 | for ( ChangeSet changeSet : changedSets ) |
156 | |
{ |
157 | 0 | System.out.println( changeSet.toXML() ); |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | 0 | Iterator<ScmFile> files = new TreeSet<ScmFile>( updatedFiles ).iterator(); |
165 | |
|
166 | |
|
167 | 0 | ScmFile file = files.next(); |
168 | 0 | assertPath( "/src/main/java/org/Foo.java", file.getPath() ); |
169 | |
|
170 | 0 | assertTrue( file.getStatus().isUpdate() || file.getStatus() == ScmFileStatus.ADDED ); |
171 | |
|
172 | |
|
173 | 0 | file = files.next(); |
174 | 0 | assertPath( "/readme.txt", file.getPath() ); |
175 | 0 | assertTrue( file.getStatus().isUpdate() ); |
176 | |
|
177 | |
|
178 | 0 | file = files.next(); |
179 | 0 | assertPath( "/project.xml", file.getPath() ); |
180 | |
|
181 | 0 | assertTrue( file.getStatus().isUpdate() || file.getStatus() == ScmFileStatus.ADDED ); |
182 | 0 | } |
183 | |
|
184 | |
} |