001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.hg.command.diff; 020 021import java.io.File; 022import java.util.Iterator; 023import java.util.List; 024import java.util.Map; 025import java.util.TreeSet; 026 027import org.apache.maven.scm.ScmFile; 028import org.apache.maven.scm.ScmFileSet; 029import org.apache.maven.scm.ScmTestCase; 030import org.apache.maven.scm.ScmVersion; 031import org.apache.maven.scm.command.diff.DiffScmResult; 032import org.apache.maven.scm.provider.ScmProvider; 033import org.apache.maven.scm.provider.hg.HgRepoUtils; 034import org.apache.maven.scm.repository.ScmRepository; 035import org.apache.maven.scm.tck.command.diff.DiffCommandTckTest; 036import org.junit.Test; 037 038import static org.apache.maven.scm.provider.hg.HgRepoUtils.HG_COMMAND_LINE; 039import static org.junit.Assert.assertTrue; 040 041public class HgDiffCommandTckTest extends DiffCommandTckTest { 042 @Override 043 public String getScmProviderCommand() { 044 return HG_COMMAND_LINE; 045 } 046 047 public String getScmUrl() throws Exception { 048 return HgRepoUtils.getScmUrl(); 049 } 050 051 public void initRepo() throws Exception { 052 HgRepoUtils.initRepo(); 053 } 054 055 @Test 056 public void testDiffCommand() throws Exception { 057 ScmRepository repository = getScmRepository(); 058 059 // ---------------------------------------------------------------------- 060 // Change the files 061 // ---------------------------------------------------------------------- 062 063 // 064 // readme.txt is changed (changed file in the root directory) 065 // project.xml is added (added file in the root directory) 066 // src/test/resources is untouched (a empty directory is left untouched) 067 // src/test/java is untouched (a non empty directory is left untouched) 068 069 // This following test has no meaning to mercurial as mercurial does not track 070 // empty directories, only the files contained within 071 // See: http://www.selenic.com/mercurial/wiki/index.cgi/FAQ 072 // src/test/java/org (a empty directory is added) 073 074 // src/main/java/org/Foo.java (a non empty directory is added) 075 // 076 077 // /readme.txt 078 ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt"); 079 080 // /project.xml 081 ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml"); 082 083 addToWorkingTree(getWorkingCopy(), new File("project.xml"), repository); 084 085 // /src/test/java/org 086 // ScmTestCase.makeDirectory(getWorkingCopy(), "/src/test/java/org"); 087 // 088 // addToWorkingTree(getWorkingCopy(), new File("src/test/java/org"), 089 // repository); 090 091 // /src/main/java/org/Foo.java 092 ScmTestCase.makeFile(getWorkingCopy(), "/src/main/java/org/Foo.java"); 093 094 // addToWorkingTree(getWorkingCopy(), new File("src/main/java/org"), 095 // repository); 096 097 // src/main/java/org/Foo.java 098 addToWorkingTree(getWorkingCopy(), new File("src/main/java/org/Foo.java"), repository); 099 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}