001 package 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
022 import org.apache.maven.scm.ScmBranch;
023 import org.apache.maven.scm.ScmFileSet;
024 import org.apache.maven.scm.ScmTckTestCase;
025 import org.apache.maven.scm.command.branch.BranchScmResult;
026 import org.apache.maven.scm.command.checkin.CheckInScmResult;
027 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
028 import org.codehaus.plexus.util.FileUtils;
029 import org.codehaus.plexus.util.IOUtil;
030
031 import java.io.File;
032 import 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 */
040 public abstract class BranchCommandTckTest
041 extends ScmTckTestCase
042 {
043
044 public void testBranchCommandTest()
045 throws Exception
046 {
047 String branch = "test-branch";
048
049 @SuppressWarnings( "deprecation" ) BranchScmResult branchResult =
050 getScmManager().getProviderByUrl( getScmUrl() ).branch( getScmRepository(),
051 new ScmFileSet( getWorkingCopy() ), branch );
052
053 assertResultIsSuccess( branchResult );
054
055 assertEquals( "check all 4 files branched", 4, branchResult.getBranchedFiles().size() );
056
057 File readmeTxt = new File( getWorkingCopy(), "readme.txt" );
058
059 assertEquals( "check readme.txt contents", "/readme.txt", FileUtils.fileRead( readmeTxt ) );
060
061 changeReadmeTxt( readmeTxt );
062
063 CheckInScmResult checkinResult =
064 getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy() ), "commit message" );
065
066 assertResultIsSuccess( checkinResult );
067
068 CheckOutScmResult checkoutResult =
069 getScmManager().checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ) );
070
071 assertResultIsSuccess( checkoutResult );
072
073 readmeTxt = new File( getAssertionCopy(), "readme.txt" );
074
075 assertEquals( "check readme.txt contents", "changed file", FileUtils.fileRead( readmeTxt ) );
076
077 FileUtils.deleteDirectory( getAssertionCopy() );
078
079 assertFalse( "check previous assertion copy deleted", getAssertionCopy().exists() );
080
081 checkoutResult = getScmManager().getProviderByUrl( getScmUrl() ).checkOut( getScmRepository(),
082 new ScmFileSet( getAssertionCopy() ),
083 new ScmBranch( branch ) );
084
085 assertResultIsSuccess( checkoutResult );
086
087 assertEquals( "check readme.txt contents is from branched version", "/readme.txt",
088 FileUtils.fileRead( readmeTxt ) );
089 }
090
091 private void changeReadmeTxt( File readmeTxt )
092 throws Exception
093 {
094 FileWriter output = new FileWriter( readmeTxt );
095 try
096 {
097 output.write( "changed file" );
098 }
099 finally
100 {
101 IOUtil.close( output );
102 }
103 }
104 }