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.tag;
20
21 import java.io.File;
22 import java.io.FileWriter;
23
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.ScmTag;
26 import org.apache.maven.scm.ScmTckTestCase;
27 import org.apache.maven.scm.command.checkin.CheckInScmResult;
28 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
29 import org.apache.maven.scm.command.tag.TagScmResult;
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 TagCommandTckTest extends ScmTckTestCase {
44
45 protected String getTagName() {
46 return "test-tag";
47 }
48
49 @Test
50 public void testTagCommandTest() throws Exception {
51 String tag = getTagName();
52
53 @SuppressWarnings("deprecation")
54 TagScmResult tagResult = getScmManager()
55 .getProviderByUrl(getScmUrl())
56 .tag(getScmRepository(), new ScmFileSet(getWorkingCopy()), tag);
57
58 assertResultIsSuccess(tagResult);
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 ScmTag(tag));
91
92 assertResultIsSuccess(checkoutResult);
93
94 assertEquals("check readme.txt contents is from tagged version", "/readme.txt", FileUtils.fileRead(readmeTxt));
95 }
96
97 private void changeReadmeTxt(File readmeTxt) throws Exception {
98 FileWriter output = new FileWriter(readmeTxt);
99 try {
100 output.write("changed file");
101 } finally {
102 IOUtil.close(output);
103 }
104 }
105 }