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  import org.junit.Test;
31  
32  import java.io.File;
33  import java.io.FileWriter;
34  
35  import static org.junit.Assert.assertEquals;
36  import static org.junit.Assert.assertFalse;
37  
38  /**
39   * This test tests the branch command.
40   *
41   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
42   *
43   */
44  public abstract class BranchCommandTckTest
45      extends ScmTckTestCase
46  {
47  
48      protected String getBranch()
49      {
50          return "test-branch";
51      }
52  
53      @Test
54      public void testBranchCommandTest()
55          throws Exception
56      {
57          String branch = getBranch();
58  
59          @SuppressWarnings( "deprecation" ) BranchScmResult branchResult =
60              getScmManager().getProviderByUrl( getScmUrl() ).branch( getScmRepository(),
61                                                                      new ScmFileSet( getWorkingCopy() ), branch );
62  
63          assertResultIsSuccess( branchResult );
64  
65          // see https://issues.apache.org/jira/browse/SCM-754
66          //assertEquals( "check all 4 files branched", 4, branchResult.getBranchedFiles().size() );
67  
68          File readmeTxt = new File( getWorkingCopy(), "readme.txt" );
69  
70          assertEquals( "check readme.txt contents", "/readme.txt", FileUtils.fileRead( readmeTxt ) );
71  
72          this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
73          changeReadmeTxt( readmeTxt );
74  
75          CheckInScmResult checkinResult =
76              getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy() ), "commit message" );
77  
78          assertResultIsSuccess( checkinResult );
79  
80          CheckOutScmResult checkoutResult =
81              getScmManager().checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ) );
82  
83          assertResultIsSuccess( checkoutResult );
84  
85          readmeTxt = new File( getAssertionCopy(), "readme.txt" );
86  
87          assertEquals( "check readme.txt contents", "changed file", FileUtils.fileRead( readmeTxt ) );
88  
89          deleteDirectory( getAssertionCopy() );
90  
91          assertFalse( "check previous assertion copy deleted", getAssertionCopy().exists() );
92  
93          checkoutResult = getScmManager().getProviderByUrl( getScmUrl() ).checkOut( getScmRepository(),
94                                                                                     new ScmFileSet( getAssertionCopy() ),
95                                                                                     new ScmBranch( branch ) );
96  
97          assertResultIsSuccess( checkoutResult );
98  
99          assertEquals( "check readme.txt contents is from branched version", "/readme.txt",
100                       FileUtils.fileRead( readmeTxt ) );
101     }
102 
103     private void changeReadmeTxt( File readmeTxt )
104         throws Exception
105     {
106         FileWriter output = new FileWriter( readmeTxt );
107         try
108         {
109             output.write( "changed file" );
110         }
111         finally
112         {
113             IOUtil.close( output );
114         }
115     }
116 }