1 package org.apache.maven.scm.tck.command.tag;
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.ScmFileSet;
23 import org.apache.maven.scm.ScmTag;
24 import org.apache.maven.scm.ScmTckTestCase;
25 import org.apache.maven.scm.command.checkin.CheckInScmResult;
26 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
27 import org.apache.maven.scm.command.tag.TagScmResult;
28 import org.codehaus.plexus.util.FileUtils;
29
30 import java.io.File;
31 import java.io.FileWriter;
32
33
34
35
36
37
38
39 public abstract class TagCommandTckTest
40 extends ScmTckTestCase
41 {
42
43 public void testTagCommandTest()
44 throws Exception
45 {
46 String tag = "test-tag";
47
48 TagScmResult tagResult = getScmManager().getProviderByUrl( getScmUrl() )
49 .tag( getScmRepository(), new ScmFileSet( getWorkingCopy() ), tag );
50
51 assertResultIsSuccess( tagResult );
52
53 assertEquals( "check all 4 files tagged", 4, tagResult.getTaggedFiles().size() );
54
55 File readmeTxt = new File( getWorkingCopy(), "readme.txt" );
56
57 assertEquals( "check readme.txt contents", "/readme.txt", FileUtils.fileRead( readmeTxt ) );
58
59 changeReadmeTxt( readmeTxt );
60
61 CheckInScmResult checkinResult =
62 getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy() ), "commit message" );
63
64 assertResultIsSuccess( checkinResult );
65
66 CheckOutScmResult checkoutResult =
67 getScmManager().checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ) );
68
69 assertResultIsSuccess( checkoutResult );
70
71 readmeTxt = new File( getAssertionCopy(), "readme.txt" );
72
73 assertEquals( "check readme.txt contents", "changed file", FileUtils.fileRead( readmeTxt ) );
74
75 FileUtils.deleteDirectory( getAssertionCopy() );
76
77 assertFalse( "check previous assertion copy deleted", getAssertionCopy().exists() );
78
79 checkoutResult = getScmManager().getProviderByUrl( getScmUrl() )
80 .checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ), new ScmTag( tag ) );
81
82 assertResultIsSuccess( checkoutResult );
83
84 assertEquals( "check readme.txt contents is from tagged version", "/readme.txt",
85 FileUtils.fileRead( readmeTxt ) );
86 }
87
88 private void changeReadmeTxt( File readmeTxt )
89 throws Exception
90 {
91 FileWriter output = new FileWriter( readmeTxt );
92
93 output.write( "changed file" );
94
95 output.close();
96 }
97 }