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.Writer;
23 import java.nio.file.Files;
24 import java.nio.file.Path;
25
26 import org.apache.maven.scm.CommandParameter;
27 import org.apache.maven.scm.CommandParameters;
28 import org.apache.maven.scm.ScmBranch;
29 import org.apache.maven.scm.ScmFileSet;
30 import org.apache.maven.scm.ScmTckTestCase;
31 import org.apache.maven.scm.command.branch.BranchScmResult;
32 import org.apache.maven.scm.command.checkin.CheckInScmResult;
33 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
34 import org.codehaus.plexus.util.FileUtils;
35 import org.junit.Test;
36
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.assertFalse;
39
40
41
42
43
44
45
46 public abstract class BranchCommandTckTest extends ScmTckTestCase {
47
48 protected String getBranch() {
49 return "test-branch";
50 }
51
52 @Test
53 public void testBranchCommandTest() throws Exception {
54 String branch = getBranch();
55
56 @SuppressWarnings("deprecation")
57 BranchScmResult branchResult = getScmManager()
58 .getProviderByUrl(getScmUrl())
59 .branch(getScmRepository(), new ScmFileSet(getWorkingCopy()), branch);
60
61 assertResultIsSuccess(branchResult);
62
63
64
65
66 File readmeTxt = new File(getWorkingCopy(), "readme.txt");
67
68 assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
69
70 this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
71 changeReadmeTxt(readmeTxt.toPath());
72
73 CommandParameters commandParameters = new CommandParameters();
74 commandParameters.setString(CommandParameter.MESSAGE, "commit message");
75 commandParameters.setString(CommandParameter.SCM_COMMIT_SIGN, "false");
76
77 CheckInScmResult checkinResult =
78 getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), commandParameters);
79
80 assertResultIsSuccess(checkinResult);
81
82 CheckOutScmResult checkoutResult =
83 getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
84
85 assertResultIsSuccess(checkoutResult);
86
87 readmeTxt = new File(getAssertionCopy(), "readme.txt");
88
89 assertEquals("check readme.txt contents", "changed file", FileUtils.fileRead(readmeTxt));
90
91 deleteDirectory(getAssertionCopy());
92
93 assertFalse("check previous assertion copy deleted", getAssertionCopy().exists());
94
95 checkoutResult = getScmManager()
96 .getProviderByUrl(getScmUrl())
97 .checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmBranch(branch));
98
99 assertResultIsSuccess(checkoutResult);
100
101 assertEquals(
102 "check readme.txt contents is from branched version", "/readme.txt", FileUtils.fileRead(readmeTxt));
103 }
104
105 private void changeReadmeTxt(Path readmeTxt) throws Exception {
106 try (Writer output = Files.newBufferedWriter(readmeTxt)) {
107 output.write("changed file");
108 }
109 }
110 }