View Javadoc
1   package org.apache.maven.scm.tck.command.branch;
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.ScmBranch;
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.ScmTckTestCase;
25  import org.apache.maven.scm.command.branch.BranchScmResult;
26  import org.apache.maven.scm.command.checkin.CheckInScmResult;
27  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
28  import org.codehaus.plexus.util.FileUtils;
29  import org.codehaus.plexus.util.IOUtil;
30  
31  import java.io.File;
32  import java.io.FileWriter;
33  
34  /**
35   * This test tests the branch command.
36   *
37   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
38   *
39   */
40  public abstract class BranchCommandTckTest
41      extends ScmTckTestCase
42  {
43  
44      protected String getBranch()
45      {
46          return "test-branch";
47      }
48  
49      public void testBranchCommandTest()
50          throws Exception
51      {
52          String branch = getBranch();
53  
54          @SuppressWarnings( "deprecation" ) BranchScmResult branchResult =
55              getScmManager().getProviderByUrl( getScmUrl() ).branch( getScmRepository(),
56                                                                      new ScmFileSet( getWorkingCopy() ), branch );
57  
58          assertResultIsSuccess( branchResult );
59  
60          // see https://jira.codehaus.org/browse/SCM-754
61          //assertEquals( "check all 4 files branched", 4, branchResult.getBranchedFiles().size() );
62  
63          File readmeTxt = new File( getWorkingCopy(), "readme.txt" );
64  
65          assertEquals( "check readme.txt contents", "/readme.txt", FileUtils.fileRead( readmeTxt ) );
66  
67          this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
68          changeReadmeTxt( readmeTxt );
69  
70          CheckInScmResult checkinResult =
71              getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy() ), "commit message" );
72  
73          assertResultIsSuccess( checkinResult );
74  
75          CheckOutScmResult checkoutResult =
76              getScmManager().checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ) );
77  
78          assertResultIsSuccess( checkoutResult );
79  
80          readmeTxt = new File( getAssertionCopy(), "readme.txt" );
81  
82          assertEquals( "check readme.txt contents", "changed file", FileUtils.fileRead( readmeTxt ) );
83  
84          deleteDirectory( getAssertionCopy() );
85  
86          assertFalse( "check previous assertion copy deleted", getAssertionCopy().exists() );
87  
88          checkoutResult = getScmManager().getProviderByUrl( getScmUrl() ).checkOut( getScmRepository(),
89                                                                                     new ScmFileSet( getAssertionCopy() ),
90                                                                                     new ScmBranch( branch ) );
91  
92          assertResultIsSuccess( checkoutResult );
93  
94          assertEquals( "check readme.txt contents is from branched version", "/readme.txt",
95                        FileUtils.fileRead( readmeTxt ) );
96      }
97  
98      private void changeReadmeTxt( File readmeTxt )
99          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 }