1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.scm.provider.hg.command.diff;
20
21 import java.io.File;
22
23 import org.apache.maven.scm.ScmFileSet;
24 import org.apache.maven.scm.ScmTestCase;
25 import org.apache.maven.scm.ScmVersion;
26 import org.apache.maven.scm.provider.ScmProvider;
27 import org.apache.maven.scm.provider.hg.HgRepoUtils;
28 import org.apache.maven.scm.repository.ScmRepository;
29 import org.apache.maven.scm.tck.command.diff.DiffCommandTckTest;
30 import org.junit.Test;
31
32 import static org.apache.maven.scm.provider.hg.HgRepoUtils.HG_COMMAND_LINE;
33 import static org.junit.Assert.assertTrue;
34
35 public class HgDiffCommandTckTest extends DiffCommandTckTest {
36 @Override
37 public String getScmProviderCommand() {
38 return HG_COMMAND_LINE;
39 }
40
41 public String getScmUrl() throws Exception {
42 return HgRepoUtils.getScmUrl();
43 }
44
45 public void initRepo() throws Exception {
46 HgRepoUtils.initRepo();
47 }
48
49 @Test
50 public void testDiffCommand() throws Exception {
51 ScmRepository repository = getScmRepository();
52
53 // ----------------------------------------------------------------------
54 // Change the files
55 // ----------------------------------------------------------------------
56
57 //
58 // readme.txt is changed (changed file in the root directory)
59 // project.xml is added (added file in the root directory)
60 // src/test/resources is untouched (a empty directory is left untouched)
61 // src/test/java is untouched (a non empty directory is left untouched)
62
63 // This following test has no meaning to mercurial as mercurial does not track
64 // empty directories, only the files contained within
65 // See: http://www.selenic.com/mercurial/wiki/index.cgi/FAQ
66 // src/test/java/org (a empty directory is added)
67
68 // src/main/java/org/Foo.java (a non empty directory is added)
69 //
70
71 // /readme.txt
72 ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
73
74 // /project.xml
75 ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml");
76
77 addToWorkingTree(getWorkingCopy(), new File("project.xml"), repository);
78
79 // /src/test/java/org
80 // ScmTestCase.makeDirectory(getWorkingCopy(), "/src/test/java/org");
81 //
82 // addToWorkingTree(getWorkingCopy(), new File("src/test/java/org"),
83 // repository);
84
85 // /src/main/java/org/Foo.java
86 ScmTestCase.makeFile(getWorkingCopy(), "/src/main/java/org/Foo.java");
87
88 // addToWorkingTree(getWorkingCopy(), new File("src/main/java/org"),
89 // repository);
90
91 // src/main/java/org/Foo.java
92 addToWorkingTree(getWorkingCopy(), new File("src/main/java/org/Foo.java"), repository);
93
94 // ----------------------------------------------------------------------
95 // Diff the project
96 // ----------------------------------------------------------------------
97
98 ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
99 ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
100 /*DiffScmResult result = */ provider.diff(repository, fileSet, (ScmVersion) null, null);
101
102 // todo: check asserts
103 // assertNotNull("The command returned a null result.", result);
104
105 // assertResultIsSuccess(result);
106
107 // List<ScmFile> changedFiles = result.getChangedFiles();
108
109 // Map<String, CharSequence> differences = result.getDifferences();
110
111 // assertEquals("Expected 3 files in the changed files list "
112 // + changedFiles, 3, changedFiles.size());
113
114 // assertEquals("Expected 3 files in the differences list " + differences,
115 // 3, differences.size());
116
117 // ----------------------------------------------------------------------
118 // Assert the files in the changed files list
119 // ----------------------------------------------------------------------
120
121 // Iterator<ScmFile> files = new TreeSet<ScmFile>(changedFiles).iterator();
122
123 // Check Foo.java
124 // ScmFile file = (ScmFile) files.next();
125
126 // assertPath("/src/main/java/org/Foo.java", file.getPath());
127
128 // assertTrue(file.getStatus().isDiff());
129
130 // String postRangeStr = "+/src/main/java/org/Foo.java\n\\ No newline at end of file\n";
131 // String actualStr = differences.get(file.getPath()).toString();
132 // assertTrue(actualStr.endsWith(postRangeStr));
133
134 // Check readme.txt
135 // file = (ScmFile) files.next();
136
137 // assertPath("/readme.txt", file.getPath());
138
139 // assertTrue(file.getStatus().isDiff());
140
141 // postRangeStr = "-/readme.txt\n\\ No newline at end of file\n+changed readme.txt\n\\ No newline at end of
142 // file\n";
143 // actualStr = differences.get(file.getPath()).toString();
144 // assertTrue(actualStr.endsWith(postRangeStr));
145
146 // Check project.xml
147 // file = (ScmFile) files.next();
148
149 // assertPath("/project.xml", file.getPath());
150
151 // postRangeStr = "+changed project.xml\n\\ No newline at end of file\n";
152 // actualStr = differences.get(file.getPath()).toString();
153 // assertTrue(actualStr.endsWith(postRangeStr));
154
155 // assertTrue(file.getStatus().isDiff());
156 assertTrue(true);
157 }
158 }