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