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