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 public abstract class BranchCommandTckTest extends ScmTckTestCase {
46
47 protected String getBranch() {
48 return "test-branch";
49 }
50
51 @Test
52 public void testBranchCommandTest() throws Exception {
53 String branch = getBranch();
54
55 @SuppressWarnings("deprecation")
56 BranchScmResult branchResult = getScmManager()
57 .getProviderByUrl(getScmUrl())
58 .branch(getScmRepository(), new ScmFileSet(getWorkingCopy()), branch);
59
60 assertResultIsSuccess(branchResult);
61
62
63
64
65 File readmeTxt = new File(getWorkingCopy(), "readme.txt");
66
67 assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
68
69 this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
70 changeReadmeTxt(readmeTxt.toPath());
71
72 CommandParameters commandParameters = new CommandParameters();
73 commandParameters.setString(CommandParameter.MESSAGE, "commit message");
74
75 CheckInScmResult checkinResult =
76 getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), commandParameters);
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()
94 .getProviderByUrl(getScmUrl())
95 .checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmBranch(branch));
96
97 assertResultIsSuccess(checkoutResult);
98
99 assertEquals(
100 "check readme.txt contents is from branched version", "/readme.txt", FileUtils.fileRead(readmeTxt));
101 }
102
103 private void changeReadmeTxt(Path readmeTxt) throws Exception {
104 try (Writer output = Files.newBufferedWriter(readmeTxt)) {
105 output.write("changed file");
106 }
107 }
108 }