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