1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
39
40
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
61
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 }