1 package org.apache.maven.scm.tck.command.diff;
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.ScmTckTestCase;
25 import org.apache.maven.scm.ScmTestCase;
26 import org.apache.maven.scm.ScmVersion;
27 import org.apache.maven.scm.command.diff.DiffScmResult;
28 import org.apache.maven.scm.provider.ScmProvider;
29 import org.apache.maven.scm.repository.ScmRepository;
30
31 import java.io.File;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.TreeSet;
36
37
38
39
40
41
42
43 public abstract class DiffCommandTckTest
44 extends ScmTckTestCase
45 {
46
47 public void testDiffCommand()
48 throws Exception
49 {
50 ScmRepository repository = getScmRepository();
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
67
68
69 ScmTestCase.makeFile( getWorkingCopy(), "/project.xml", "changed project.xml" );
70
71 addToWorkingTree( getWorkingCopy(), new File( "project.xml" ), repository );
72
73
74 ScmTestCase.makeDirectory( getWorkingCopy(), "/src/test/java/org" );
75
76 addToWorkingTree( getWorkingCopy(), new File( "src/test/java/org" ), repository );
77
78
79 ScmTestCase.makeFile( getWorkingCopy(), "/src/main/java/org/Foo.java" );
80
81 addToWorkingTree( getWorkingCopy(), new File( "src/main/java/org" ), repository );
82
83
84 addToWorkingTree( getWorkingCopy(), new File( "src/main/java/org/Foo.java" ), repository );
85
86
87
88
89
90 ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
91 ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
92 DiffScmResult result = provider.diff( repository, fileSet, null, (ScmVersion) null );
93
94 assertNotNull( "The command returned a null result.", result );
95
96 assertResultIsSuccess( result );
97
98 List<ScmFile> changedFiles = result.getChangedFiles();
99
100 Map<String, CharSequence> differences = result.getDifferences();
101
102 assertEquals( "Expected 3 files in the changed files list " + changedFiles, 3, changedFiles.size() );
103
104 assertEquals( "Expected 3 files in the differences list " + differences, 3, differences.size() );
105
106
107
108
109
110 Iterator<ScmFile> files = new TreeSet<ScmFile>( changedFiles ).iterator();
111
112
113 ScmFile file = files.next();
114
115 assertPath( "/src/main/java/org/Foo.java", file.getPath() );
116
117 assertTrue( file.getStatus().isDiff() );
118
119 String postRangeStr = "+/src/main/java/org/Foo.java\n\\ No newline at end of file\n";
120 String actualStr = differences.get( file.getPath() ).toString();
121 assertTrue( actualStr.endsWith( postRangeStr ) );
122
123
124 file = files.next();
125
126 assertPath( "/readme.txt", file.getPath() );
127
128 assertTrue( file.getStatus().isDiff() );
129
130 postRangeStr =
131 "-/readme.txt\n\\ No newline at end of file\n+changed readme.txt\n\\ No newline at end of file\n";
132 actualStr = differences.get( file.getPath() ).toString();
133 assertTrue( actualStr.endsWith( postRangeStr ) );
134
135
136 file = files.next();
137
138 assertPath( "/project.xml", file.getPath() );
139
140 postRangeStr = "+changed project.xml\n\\ No newline at end of file\n";
141 actualStr = differences.get( file.getPath() ).toString();
142 assertTrue( actualStr.endsWith( postRangeStr ) );
143
144 assertTrue( file.getStatus().isDiff() );
145 }
146 }