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.status;
20
21 import java.io.File;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.TreeSet;
25
26 import org.apache.maven.scm.CommandParameter;
27 import org.apache.maven.scm.CommandParameters;
28 import org.apache.maven.scm.ScmFile;
29 import org.apache.maven.scm.ScmFileSet;
30 import org.apache.maven.scm.ScmFileStatus;
31 import org.apache.maven.scm.ScmTckTestCase;
32 import org.apache.maven.scm.ScmTestCase;
33 import org.apache.maven.scm.command.checkin.CheckInScmResult;
34 import org.apache.maven.scm.command.status.StatusScmResult;
35 import org.apache.maven.scm.manager.ScmManager;
36 import org.apache.maven.scm.repository.ScmRepository;
37 import org.junit.Test;
38
39 import static org.junit.Assert.assertEquals;
40 import static org.junit.Assert.assertFalse;
41 import static org.junit.Assert.assertNotNull;
42 import static org.junit.Assert.assertTrue;
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 public abstract class StatusCommandTckTest extends ScmTckTestCase {
63
64 protected void commit(File workingDirectory, ScmRepository repository) throws Exception {
65 CommandParameters commandParameters = new CommandParameters();
66 commandParameters.setString(CommandParameter.MESSAGE, "No msg");
67 commandParameters.setString(CommandParameter.SCM_COMMIT_SIGN, "false");
68 CheckInScmResult result =
69 getScmManager().checkIn(repository, new ScmFileSet(workingDirectory), commandParameters);
70
71 assertTrue("Check result was successful, output: " + result.getCommandOutput(), result.isSuccess());
72
73 List<ScmFile> committedFiles = result.getCheckedInFiles();
74
75 assertEquals("Expected 2 files in the committed files list " + committedFiles, 2, committedFiles.size());
76 }
77
78 protected boolean commitUpdateCopy() {
79 return false;
80 }
81
82 @Test
83 public void testStatusCommand() throws Exception {
84 ScmRepository repository = makeScmRepository(getScmUrl());
85
86 checkOut(getUpdatingCopy(), repository);
87
88
89
90
91
92
93
94
95
96
97
98 this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
99 ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
100
101
102 ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml");
103
104 addToWorkingTree(getWorkingCopy(), new File("project.xml"), getScmRepository());
105
106 commit(getWorkingCopy(), getScmRepository());
107
108
109 this.edit(getUpdatingCopy(), "pom.xml", null, repository);
110 ScmTestCase.makeFile(getUpdatingCopy(), "/pom.xml", "changed pom.xml");
111
112
113 ScmTestCase.makeDirectory(getUpdatingCopy(), "/src/test/java/org");
114
115 addToWorkingTree(getUpdatingCopy(), new File("src/test/java/org"), repository);
116
117
118 ScmTestCase.makeFile(getUpdatingCopy(), "/src/main/java/org/Foo.java");
119
120 addToWorkingTree(getUpdatingCopy(), new File("src/main/java/org"), repository);
121
122
123 addToWorkingTree(getUpdatingCopy(), new File("src/main/java/org/Foo.java"), repository);
124
125 ScmManager scmManager = getScmManager();
126
127
128
129
130
131
132
133
134 StatusScmResult result =
135 scmManager.getProviderByUrl(getScmUrl()).status(repository, new ScmFileSet(getUpdatingCopy()));
136
137 if (this.commitUpdateCopy()) {
138
139 commit(getUpdatingCopy(), repository);
140 }
141
142 assertNotNull("The command returned a null result.", result);
143
144 assertResultIsSuccess(result);
145
146 List<ScmFile> changedFiles = result.getChangedFiles();
147
148 assertEquals("Expected 2 files in the updated files list " + changedFiles, 2, changedFiles.size());
149
150
151
152
153
154 Iterator<ScmFile> files = new TreeSet<>(changedFiles).iterator();
155
156 ScmFile file = files.next();
157 assertPath("src/main/java/org/Foo.java", file.getPath());
158 assertEquals(ScmFileStatus.ADDED, file.getStatus());
159
160 file = files.next();
161 assertPath("pom.xml", file.getPath());
162 assertEquals(ScmFileStatus.MODIFIED, file.getStatus());
163
164 assertFile(getUpdatingCopy(), "/readme.txt");
165
166 assertFalse("project.xml created incorrectly", new File(getUpdatingCopy(), "/project.xml").exists());
167 }
168 }