Coverage Report - org.apache.maven.scm.tck.command.diff.DiffCommandTckTest
 
Classes in this File Line Coverage Branch Coverage Complexity
DiffCommandTckTest
0 %
0/39
N/A
1
 
 1  
 package org.apache.maven.scm.tck.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 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  
  * This test tests the diff command.
 39  
  *
 40  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 41  
  * @version $Id: DiffCommandTckTest.java 1241523 2012-02-07 17:08:26Z hboutemy $
 42  
  */
 43  0
 public abstract class DiffCommandTckTest
 44  
     extends ScmTckTestCase
 45  
 {
 46  
 
 47  
     public void testDiffCommand()
 48  
         throws Exception
 49  
     {
 50  0
         ScmRepository repository = getScmRepository();
 51  
 
 52  
         // ----------------------------------------------------------------------
 53  
         // Change the files
 54  
         // ----------------------------------------------------------------------
 55  
 
 56  
         //
 57  
         // readme.txt is changed (changed file in the root directory)
 58  
         // project.xml is added (added file in the root directory)
 59  
         // src/test/resources is untouched (a empty directory is left untouched)
 60  
         // src/test/java is untouched (a non empty directory is left untouched)
 61  
         // src/test/java/org (a empty directory is added)
 62  
         // src/main/java/org/Foo.java (a non empty directory is added)
 63  
         //
 64  
 
 65  
         // /readme.txt
 66  0
         ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
 67  
 
 68  
         // /project.xml
 69  0
         ScmTestCase.makeFile( getWorkingCopy(), "/project.xml", "changed project.xml" );
 70  
 
 71  0
         addToWorkingTree( getWorkingCopy(), new File( "project.xml" ), repository );
 72  
 
 73  
         // /src/test/java/org
 74  0
         ScmTestCase.makeDirectory( getWorkingCopy(), "/src/test/java/org" );
 75  
 
 76  0
         addToWorkingTree( getWorkingCopy(), new File( "src/test/java/org" ), repository );
 77  
 
 78  
         // /src/main/java/org/Foo.java
 79  0
         ScmTestCase.makeFile( getWorkingCopy(), "/src/main/java/org/Foo.java" );
 80  
 
 81  0
         addToWorkingTree( getWorkingCopy(), new File( "src/main/java/org" ), repository );
 82  
 
 83  
         // src/main/java/org/Foo.java
 84  0
         addToWorkingTree( getWorkingCopy(), new File( "src/main/java/org/Foo.java" ), repository );
 85  
 
 86  
         // ----------------------------------------------------------------------
 87  
         // Diff the project
 88  
         // ----------------------------------------------------------------------
 89  
 
 90  0
         ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
 91  0
         ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
 92  0
         DiffScmResult result = provider.diff( repository, fileSet, null, (ScmVersion) null );
 93  
 
 94  0
         assertNotNull( "The command returned a null result.", result );
 95  
 
 96  0
         assertResultIsSuccess( result );
 97  
 
 98  0
         List<ScmFile> changedFiles = result.getChangedFiles();
 99  
 
 100  0
         Map<String, CharSequence> differences = result.getDifferences();
 101  
 
 102  0
         assertEquals( "Expected 3 files in the changed files list " + changedFiles, 3, changedFiles.size() );
 103  
 
 104  0
         assertEquals( "Expected 3 files in the differences list " + differences, 3, differences.size() );
 105  
 
 106  
         // ----------------------------------------------------------------------
 107  
         // Assert the files in the changed files list
 108  
         // ----------------------------------------------------------------------
 109  
 
 110  0
         Iterator<ScmFile> files = new TreeSet<ScmFile>( changedFiles ).iterator();
 111  
 
 112  
         //Check Foo.java
 113  0
         ScmFile file = files.next();
 114  
 
 115  0
         assertPath( "/src/main/java/org/Foo.java", file.getPath() );
 116  
 
 117  0
         assertTrue( file.getStatus().isDiff() );
 118  
 
 119  0
         String postRangeStr = "+/src/main/java/org/Foo.java\n\\ No newline at end of file\n";
 120  0
         String actualStr = differences.get( file.getPath() ).toString();
 121  0
         assertTrue( actualStr.endsWith( postRangeStr ) );
 122  
 
 123  
         //Check readme.txt
 124  0
         file = files.next();
 125  
 
 126  0
         assertPath( "/readme.txt", file.getPath() );
 127  
 
 128  0
         assertTrue( file.getStatus().isDiff() );
 129  
 
 130  0
         postRangeStr =
 131  
             "-/readme.txt\n\\ No newline at end of file\n+changed readme.txt\n\\ No newline at end of file\n";
 132  0
         actualStr = differences.get( file.getPath() ).toString();
 133  0
         assertTrue( actualStr.endsWith( postRangeStr ) );
 134  
 
 135  
         //Check project.xml
 136  0
         file = files.next();
 137  
 
 138  0
         assertPath( "/project.xml", file.getPath() );
 139  
 
 140  0
         postRangeStr = "+changed project.xml\n\\ No newline at end of file\n";
 141  0
         actualStr = differences.get( file.getPath() ).toString();
 142  0
         assertTrue( actualStr.endsWith( postRangeStr ) );
 143  
 
 144  0
         assertTrue( file.getStatus().isDiff() );
 145  0
     }
 146  
 }