View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.tck.command.branch;
20  
21  import java.io.File;
22  import java.io.FileWriter;
23  
24  import org.apache.maven.scm.ScmBranch;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.ScmTckTestCase;
27  import org.apache.maven.scm.command.branch.BranchScmResult;
28  import org.apache.maven.scm.command.checkin.CheckInScmResult;
29  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
30  import org.codehaus.plexus.util.FileUtils;
31  import org.codehaus.plexus.util.IOUtil;
32  import org.junit.Test;
33  
34  import static org.junit.Assert.assertEquals;
35  import static org.junit.Assert.assertFalse;
36  
37  /**
38   * This test tests the branch command.
39   *
40   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
41   *
42   */
43  public abstract class BranchCommandTckTest extends ScmTckTestCase {
44  
45      protected String getBranch() {
46          return "test-branch";
47      }
48  
49      @Test
50      public void testBranchCommandTest() throws Exception {
51          String branch = getBranch();
52  
53          @SuppressWarnings("deprecation")
54          BranchScmResult branchResult = getScmManager()
55                  .getProviderByUrl(getScmUrl())
56                  .branch(getScmRepository(), new ScmFileSet(getWorkingCopy()), branch);
57  
58          assertResultIsSuccess(branchResult);
59  
60          // see https://issues.apache.org/jira/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()
89                  .getProviderByUrl(getScmUrl())
90                  .checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmBranch(branch));
91  
92          assertResultIsSuccess(checkoutResult);
93  
94          assertEquals(
95                  "check readme.txt contents is from branched version", "/readme.txt", FileUtils.fileRead(readmeTxt));
96      }
97  
98      private void changeReadmeTxt(File readmeTxt) throws Exception {
99          FileWriter output = new FileWriter(readmeTxt);
100         try {
101             output.write("changed file");
102         } finally {
103             IOUtil.close(output);
104         }
105     }
106 }