Coverage Report - org.apache.maven.scm.tck.command.checkin.CheckInCommandTckTest
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckInCommandTckTest
0 %
0/92
N/A
1
 
 1  
 package org.apache.maven.scm.tck.command.checkin;
 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.ScmFileStatus;
 25  
 import org.apache.maven.scm.ScmTckTestCase;
 26  
 import org.apache.maven.scm.command.add.AddScmResult;
 27  
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
 28  
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 29  
 import org.codehaus.plexus.util.FileUtils;
 30  
 import org.codehaus.plexus.util.IOUtil;
 31  
 
 32  
 import java.io.File;
 33  
 import java.io.FileWriter;
 34  
 import java.io.PrintWriter;
 35  
 import java.util.List;
 36  
 import java.util.Map;
 37  
 
 38  
 /**
 39  
  * This test tests the check out command.
 40  
  *
 41  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 42  
  * @version $Id: CheckInCommandTckTest.java 1306856 2012-03-29 13:40:58Z olamy $
 43  
  */
 44  0
 public abstract class CheckInCommandTckTest
 45  
     extends ScmTckTestCase
 46  
 {
 47  
     public void testCheckInCommandTest()
 48  
         throws Exception
 49  
     {
 50  
         // Make sure that the correct files was checked out
 51  0
         File fooJava = new File( getWorkingCopy(), "src/main/java/Foo.java" );
 52  
 
 53  0
         File barJava = new File( getWorkingCopy(), "src/main/java/Bar.java" );
 54  
 
 55  0
         File readmeTxt = new File( getWorkingCopy(), "readme.txt" );
 56  
 
 57  0
         assertFalse( "check Foo.java doesn't yet exist", fooJava.canRead() );
 58  
 
 59  0
         assertFalse( "check Bar.java doesn't yet exist", barJava.canRead() );
 60  
 
 61  0
         assertTrue( "check can read readme.txt", readmeTxt.canRead() );
 62  
 
 63  
         // Change the files
 64  0
         createFooJava( fooJava );
 65  
 
 66  0
         createBarJava( barJava );
 67  
 
 68  0
         changeReadmeTxt( readmeTxt );
 69  
 
 70  0
         AddScmResult addResult = getScmManager().add( getScmRepository(),
 71  
                                                       new ScmFileSet( getWorkingCopy(), "src/main/java/Foo.java",
 72  
                                                                       null ) );
 73  
 
 74  0
         assertResultIsSuccess( addResult );
 75  
 
 76  0
         CheckInScmResult result =
 77  
             getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy() ), "Commit message" );
 78  
 
 79  0
         assertResultIsSuccess( result );
 80  
 
 81  0
         List<ScmFile> files = result.getCheckedInFiles();
 82  
 
 83  0
         assertNotNull( files );
 84  
 
 85  0
         assertEquals( 2, files.size() );
 86  
 
 87  0
         Map<String, ScmFile> fileMap = mapFilesByPath( files );
 88  0
         ScmFile file1 = fileMap.get( "src/main/java/Foo.java" );
 89  0
         assertNotNull( file1 );
 90  0
         assertEquals( ScmFileStatus.CHECKED_IN, file1.getStatus() );
 91  
 
 92  0
         ScmFile file2 = fileMap.get( "readme.txt" );
 93  0
         assertNotNull( file2 );
 94  0
         assertEquals( ScmFileStatus.CHECKED_IN, file2.getStatus() );
 95  
 
 96  0
         CheckOutScmResult checkoutResult =
 97  
             getScmManager().checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ) );
 98  
 
 99  0
         assertResultIsSuccess( checkoutResult );
 100  
 
 101  0
         fooJava = new File( getAssertionCopy(), "src/main/java/Foo.java" );
 102  
 
 103  0
         barJava = new File( getAssertionCopy(), "src/main/java/Bar.java" );
 104  
 
 105  0
         readmeTxt = new File( getAssertionCopy(), "readme.txt" );
 106  
 
 107  0
         assertTrue( "check can read Foo.java", fooJava.canRead() );
 108  
 
 109  0
         assertFalse( "check Bar.java doesn't exist", barJava.canRead() );
 110  
 
 111  0
         assertTrue( "check can read readme.txt", readmeTxt.canRead() );
 112  
 
 113  0
         assertEquals( "check readme.txt contents", "changed file", FileUtils.fileRead( readmeTxt ) );
 114  0
     }
 115  
 
 116  
     public void testCheckInCommandPartialFileset()
 117  
         throws Exception
 118  
     {
 119  
         // Make sure that the correct files was checked out
 120  0
         File fooJava = new File( getWorkingCopy(), "src/main/java/Foo.java" );
 121  
 
 122  0
         File barJava = new File( getWorkingCopy(), "src/main/java/Bar.java" );
 123  
 
 124  0
         File readmeTxt = new File( getWorkingCopy(), "readme.txt" );
 125  
 
 126  0
         assertFalse( "check Foo.java doesn't yet exist", fooJava.canRead() );
 127  
 
 128  0
         assertFalse( "check Bar.java doesn't yet exist", barJava.canRead() );
 129  
 
 130  0
         assertTrue( "check can read readme.txt", readmeTxt.canRead() );
 131  
 
 132  
         // Change the files
 133  0
         createFooJava( fooJava );
 134  
 
 135  0
         createBarJava( barJava );
 136  
 
 137  0
         changeReadmeTxt( readmeTxt );
 138  
 
 139  0
         AddScmResult addResult = getScmManager().getProviderByUrl( getScmUrl() ).add( getScmRepository(),
 140  
                                                                                       new ScmFileSet( getWorkingCopy(),
 141  
                                                                                                       "src/main/java/Foo.java",
 142  
                                                                                                       null ) );
 143  
 
 144  0
         assertResultIsSuccess( addResult );
 145  
 
 146  0
         CheckInScmResult result =
 147  
             getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy(), "**/Foo.java", null ),
 148  
                                      "Commit message" );
 149  
 
 150  0
         assertResultIsSuccess( result );
 151  
 
 152  0
         List<ScmFile> files = result.getCheckedInFiles();
 153  
 
 154  0
         assertNotNull( files );
 155  
 
 156  0
         assertEquals( 1, files.size() );
 157  
 
 158  0
         ScmFile file1 = files.get( 0 );
 159  
 
 160  0
         assertEquals( ScmFileStatus.CHECKED_IN, file1.getStatus() );
 161  
 
 162  0
         assertPath( "/test-repo/check-in/Foo.java", file1.getPath() );
 163  
 
 164  0
         CheckOutScmResult checkoutResult =
 165  
             getScmManager().checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ) );
 166  
 
 167  0
         assertResultIsSuccess( checkoutResult );
 168  
 
 169  0
         fooJava = new File( getAssertionCopy(), "src/main/java/Foo.java" );
 170  
 
 171  0
         barJava = new File( getAssertionCopy(), "src/main/java/Bar.java" );
 172  
 
 173  0
         readmeTxt = new File( getAssertionCopy(), "readme.txt" );
 174  
 
 175  0
         assertTrue( "check can read Foo.java", fooJava.canRead() );
 176  
 
 177  0
         assertFalse( "check Bar.java doesn't exist", barJava.canRead() );
 178  
 
 179  0
         assertTrue( "check can read readme.txt", readmeTxt.canRead() );
 180  
 
 181  0
         assertEquals( "check readme.txt contents", "/readme.txt", FileUtils.fileRead( readmeTxt ) );
 182  0
     }
 183  
 
 184  
     private void createFooJava( File fooJava )
 185  
         throws Exception
 186  
     {
 187  0
         FileWriter output = new FileWriter( fooJava );
 188  
 
 189  0
         PrintWriter printer = new PrintWriter( output );
 190  
         try
 191  
         {
 192  0
             printer.println( "public class Foo" );
 193  0
             printer.println( "{" );
 194  
 
 195  0
             printer.println( "    public void foo()" );
 196  0
             printer.println( "    {" );
 197  0
             printer.println( "        int i = 10;" );
 198  0
             printer.println( "    }" );
 199  
 
 200  0
             printer.println( "}" );
 201  
         }
 202  
         finally
 203  
         {
 204  0
             IOUtil.close( output );
 205  0
             IOUtil.close( printer );
 206  0
         }
 207  0
     }
 208  
 
 209  
     private void createBarJava( File barJava )
 210  
         throws Exception
 211  
     {
 212  0
         FileWriter output = new FileWriter( barJava );
 213  
 
 214  0
         PrintWriter printer = new PrintWriter( output );
 215  
 
 216  0
         printer.println( "public class Bar" );
 217  0
         printer.println( "{" );
 218  
 
 219  0
         printer.println( "    public int bar()" );
 220  0
         printer.println( "    {" );
 221  0
         printer.println( "        return 20;" );
 222  0
         printer.println( "    }" );
 223  
 
 224  0
         printer.println( "}" );
 225  
 
 226  0
         printer.close();
 227  
 
 228  0
         output.close();
 229  0
     }
 230  
 
 231  
     private void changeReadmeTxt( File readmeTxt )
 232  
         throws Exception
 233  
     {
 234  0
         FileWriter output = new FileWriter( readmeTxt );
 235  
 
 236  0
         output.write( "changed file" );
 237  
 
 238  0
         output.close();
 239  0
     }
 240  
 }