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 import java.util.Iterator; 23 import java.util.List; 24 import java.util.Map; 25 import java.util.TreeSet; 26 27 import org.apache.maven.scm.ScmFile; 28 import org.apache.maven.scm.ScmFileSet; 29 import org.apache.maven.scm.ScmTestCase; 30 import org.apache.maven.scm.ScmVersion; 31 import org.apache.maven.scm.command.diff.DiffScmResult; 32 import org.apache.maven.scm.provider.ScmProvider; 33 import org.apache.maven.scm.provider.hg.HgRepoUtils; 34 import org.apache.maven.scm.repository.ScmRepository; 35 import org.apache.maven.scm.tck.command.diff.DiffCommandTckTest; 36 import org.junit.Test; 37 38 import static org.apache.maven.scm.provider.hg.HgRepoUtils.HG_COMMAND_LINE; 39 import static org.junit.Assert.assertTrue; 40 41 public class HgDiffCommandTckTest extends DiffCommandTckTest { 42 @Override 43 public String getScmProviderCommand() { 44 return HG_COMMAND_LINE; 45 } 46 47 public String getScmUrl() throws Exception { 48 return HgRepoUtils.getScmUrl(); 49 } 50 51 public void initRepo() throws Exception { 52 HgRepoUtils.initRepo(); 53 } 54 55 @Test 56 public void testDiffCommand() throws Exception { 57 ScmRepository repository = getScmRepository(); 58 59 // ---------------------------------------------------------------------- 60 // Change the files 61 // ---------------------------------------------------------------------- 62 63 // 64 // readme.txt is changed (changed file in the root directory) 65 // project.xml is added (added file in the root directory) 66 // src/test/resources is untouched (a empty directory is left untouched) 67 // src/test/java is untouched (a non empty directory is left untouched) 68 69 // This following test has no meaning to mercurial as mercurial does not track 70 // empty directories, only the files contained within 71 // See: http://www.selenic.com/mercurial/wiki/index.cgi/FAQ 72 // src/test/java/org (a empty directory is added) 73 74 // src/main/java/org/Foo.java (a non empty directory is added) 75 // 76 77 // /readme.txt 78 ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt"); 79 80 // /project.xml 81 ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml"); 82 83 addToWorkingTree(getWorkingCopy(), new File("project.xml"), repository); 84 85 // /src/test/java/org 86 // ScmTestCase.makeDirectory(getWorkingCopy(), "/src/test/java/org"); 87 // 88 // addToWorkingTree(getWorkingCopy(), new File("src/test/java/org"), 89 // repository); 90 91 // /src/main/java/org/Foo.java 92 ScmTestCase.makeFile(getWorkingCopy(), "/src/main/java/org/Foo.java"); 93 94 // addToWorkingTree(getWorkingCopy(), new File("src/main/java/org"), 95 // repository); 96 97 // src/main/java/org/Foo.java 98 addToWorkingTree(getWorkingCopy(), new File("src/main/java/org/Foo.java"), repository); 99 100 // ---------------------------------------------------------------------- 101 // Diff the project 102 // ---------------------------------------------------------------------- 103 104 ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl()); 105 ScmFileSet fileSet = new ScmFileSet(getWorkingCopy()); 106 DiffScmResult result = provider.diff(repository, fileSet, (ScmVersion) null, null); 107 108 // todo: check asserts 109 // assertNotNull("The command returned a null result.", result); 110 111 // assertResultIsSuccess(result); 112 113 List<ScmFile> changedFiles = result.getChangedFiles(); 114 115 Map<String, CharSequence> differences = result.getDifferences(); 116 117 // assertEquals("Expected 3 files in the changed files list " 118 // + changedFiles, 3, changedFiles.size()); 119 120 // assertEquals("Expected 3 files in the differences list " + differences, 121 // 3, differences.size()); 122 123 // ---------------------------------------------------------------------- 124 // Assert the files in the changed files list 125 // ---------------------------------------------------------------------- 126 127 Iterator<ScmFile> files = new TreeSet<ScmFile>(changedFiles).iterator(); 128 129 // Check Foo.java 130 ScmFile file = (ScmFile) files.next(); 131 132 // assertPath("/src/main/java/org/Foo.java", file.getPath()); 133 134 // assertTrue(file.getStatus().isDiff()); 135 136 String postRangeStr = "+/src/main/java/org/Foo.java\n\\ No newline at end of file\n"; 137 String actualStr = differences.get(file.getPath()).toString(); 138 // assertTrue(actualStr.endsWith(postRangeStr)); 139 140 // Check readme.txt 141 file = (ScmFile) files.next(); 142 143 // assertPath("/readme.txt", file.getPath()); 144 145 // assertTrue(file.getStatus().isDiff()); 146 147 postRangeStr = 148 "-/readme.txt\n\\ No newline at end of file\n+changed readme.txt\n\\ No newline at end of file\n"; 149 actualStr = differences.get(file.getPath()).toString(); 150 // assertTrue(actualStr.endsWith(postRangeStr)); 151 152 // Check project.xml 153 file = (ScmFile) files.next(); 154 155 // assertPath("/project.xml", file.getPath()); 156 157 postRangeStr = "+changed project.xml\n\\ No newline at end of file\n"; 158 actualStr = differences.get(file.getPath()).toString(); 159 // assertTrue(actualStr.endsWith(postRangeStr)); 160 161 // assertTrue(file.getStatus().isDiff()); 162 assertTrue(true); 163 } 164 }