001package org.apache.maven.scm.tck.command.branch; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.scm.ScmBranch; 023import org.apache.maven.scm.ScmFileSet; 024import org.apache.maven.scm.ScmTckTestCase; 025import org.apache.maven.scm.command.branch.BranchScmResult; 026import org.apache.maven.scm.command.checkin.CheckInScmResult; 027import org.apache.maven.scm.command.checkout.CheckOutScmResult; 028import org.codehaus.plexus.util.FileUtils; 029import org.codehaus.plexus.util.IOUtil; 030 031import java.io.File; 032import java.io.FileWriter; 033 034/** 035 * This test tests the branch command. 036 * 037 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 038 * 039 */ 040public abstract class BranchCommandTckTest 041 extends ScmTckTestCase 042{ 043 044 protected String getBranch() 045 { 046 return "test-branch"; 047 } 048 049 public void testBranchCommandTest() 050 throws Exception 051 { 052 String branch = getBranch(); 053 054 @SuppressWarnings( "deprecation" ) BranchScmResult branchResult = 055 getScmManager().getProviderByUrl( getScmUrl() ).branch( getScmRepository(), 056 new ScmFileSet( getWorkingCopy() ), branch ); 057 058 assertResultIsSuccess( branchResult ); 059 060 // see https://jira.codehaus.org/browse/SCM-754 061 //assertEquals( "check all 4 files branched", 4, branchResult.getBranchedFiles().size() ); 062 063 File readmeTxt = new File( getWorkingCopy(), "readme.txt" ); 064 065 assertEquals( "check readme.txt contents", "/readme.txt", FileUtils.fileRead( readmeTxt ) ); 066 067 this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() ); 068 changeReadmeTxt( readmeTxt ); 069 070 CheckInScmResult checkinResult = 071 getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy() ), "commit message" ); 072 073 assertResultIsSuccess( checkinResult ); 074 075 CheckOutScmResult checkoutResult = 076 getScmManager().checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ) ); 077 078 assertResultIsSuccess( checkoutResult ); 079 080 readmeTxt = new File( getAssertionCopy(), "readme.txt" ); 081 082 assertEquals( "check readme.txt contents", "changed file", FileUtils.fileRead( readmeTxt ) ); 083 084 deleteDirectory( getAssertionCopy() ); 085 086 assertFalse( "check previous assertion copy deleted", getAssertionCopy().exists() ); 087 088 checkoutResult = getScmManager().getProviderByUrl( getScmUrl() ).checkOut( getScmRepository(), 089 new ScmFileSet( getAssertionCopy() ), 090 new ScmBranch( branch ) ); 091 092 assertResultIsSuccess( checkoutResult ); 093 094 assertEquals( "check readme.txt contents is from branched version", "/readme.txt", 095 FileUtils.fileRead( readmeTxt ) ); 096 } 097 098 private void changeReadmeTxt( File readmeTxt ) 099 throws Exception 100 { 101 FileWriter output = new FileWriter( readmeTxt ); 102 try 103 { 104 output.write( "changed file" ); 105 } 106 finally 107 { 108 IOUtil.close( output ); 109 } 110 } 111}