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