1 package org.apache.maven.scm.tck.command.branch;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmBranch;
23 import org.apache.maven.scm.ScmFileSet;
24 import org.apache.maven.scm.ScmTckTestCase;
25 import org.apache.maven.scm.command.branch.BranchScmResult;
26 import org.apache.maven.scm.command.checkin.CheckInScmResult;
27 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
28 import org.codehaus.plexus.util.FileUtils;
29 import org.codehaus.plexus.util.IOUtil;
30 import org.junit.Test;
31
32 import java.io.File;
33 import java.io.FileWriter;
34
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertFalse;
37
38
39
40
41
42
43
44 public abstract class BranchCommandTckTest
45 extends ScmTckTestCase
46 {
47
48 protected String getBranch()
49 {
50 return "test-branch";
51 }
52
53 @Test
54 public void testBranchCommandTest()
55 throws Exception
56 {
57 String branch = getBranch();
58
59 @SuppressWarnings( "deprecation" ) BranchScmResult branchResult =
60 getScmManager().getProviderByUrl( getScmUrl() ).branch( getScmRepository(),
61 new ScmFileSet( getWorkingCopy() ), branch );
62
63 assertResultIsSuccess( branchResult );
64
65
66
67
68 File readmeTxt = new File( getWorkingCopy(), "readme.txt" );
69
70 assertEquals( "check readme.txt contents", "/readme.txt", FileUtils.fileRead( readmeTxt ) );
71
72 this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
73 changeReadmeTxt( readmeTxt );
74
75 CheckInScmResult checkinResult =
76 getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy() ), "commit message" );
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().getProviderByUrl( getScmUrl() ).checkOut( getScmRepository(),
94 new ScmFileSet( getAssertionCopy() ),
95 new ScmBranch( branch ) );
96
97 assertResultIsSuccess( checkoutResult );
98
99 assertEquals( "check readme.txt contents is from branched version", "/readme.txt",
100 FileUtils.fileRead( readmeTxt ) );
101 }
102
103 private void changeReadmeTxt( File readmeTxt )
104 throws Exception
105 {
106 FileWriter output = new FileWriter( readmeTxt );
107 try
108 {
109 output.write( "changed file" );
110 }
111 finally
112 {
113 IOUtil.close( output );
114 }
115 }
116 }