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