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
31 import java.io.File;
32 import java.io.FileWriter;
33
34
35
36
37
38
39
40 public abstract class BranchCommandTckTest
41 extends ScmTckTestCase
42 {
43
44 protected String getBranch()
45 {
46 return "test-branch";
47 }
48
49 public void testBranchCommandTest()
50 throws Exception
51 {
52 String branch = getBranch();
53
54 @SuppressWarnings( "deprecation" ) BranchScmResult branchResult =
55 getScmManager().getProviderByUrl( getScmUrl() ).branch( getScmRepository(),
56 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().getProviderByUrl( getScmUrl() ).checkOut( getScmRepository(),
89 new ScmFileSet( getAssertionCopy() ),
90 new ScmBranch( branch ) );
91
92 assertResultIsSuccess( checkoutResult );
93
94 assertEquals( "check readme.txt contents is from branched version", "/readme.txt",
95 FileUtils.fileRead( readmeTxt ) );
96 }
97
98 private void changeReadmeTxt( File readmeTxt )
99 throws Exception
100 {
101 FileWriter output = new FileWriter( readmeTxt );
102 try
103 {
104 output.write( "changed file" );
105 }
106 finally
107 {
108 IOUtil.close( output );
109 }
110 }
111 }