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 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 TagCommandTckTest
41 extends ScmTckTestCase
42 {
43
44 public void testTagCommandTest()
45 throws Exception
46 {
47 String tag = "test-tag";
48
49 @SuppressWarnings( "deprecation" ) TagScmResult tagResult =
50 getScmManager().getProviderByUrl( getScmUrl() ).tag( getScmRepository(), new ScmFileSet( getWorkingCopy() ),
51 tag );
52
53 assertResultIsSuccess( tagResult );
54
55 assertEquals( "check all 4 files tagged", 4, tagResult.getTaggedFiles().size() );
56
57 File readmeTxt = new File( getWorkingCopy(), "readme.txt" );
58
59 assertEquals( "check readme.txt contents", "/readme.txt", FileUtils.fileRead( readmeTxt ) );
60
61 changeReadmeTxt( readmeTxt );
62
63 CheckInScmResult checkinResult =
64 getScmManager().checkIn( getScmRepository(), new ScmFileSet( getWorkingCopy() ), "commit message" );
65
66 assertResultIsSuccess( checkinResult );
67
68 CheckOutScmResult checkoutResult =
69 getScmManager().checkOut( getScmRepository(), new ScmFileSet( getAssertionCopy() ) );
70
71 assertResultIsSuccess( checkoutResult );
72
73 readmeTxt = new File( getAssertionCopy(), "readme.txt" );
74
75 assertEquals( "check readme.txt contents", "changed file", FileUtils.fileRead( readmeTxt ) );
76
77 FileUtils.deleteDirectory( getAssertionCopy() );
78
79 assertFalse( "check previous assertion copy deleted", getAssertionCopy().exists() );
80
81 checkoutResult = getScmManager().getProviderByUrl( getScmUrl() ).checkOut( getScmRepository(),
82 new ScmFileSet( getAssertionCopy() ),
83 new ScmTag( tag ) );
84
85 assertResultIsSuccess( checkoutResult );
86
87 assertEquals( "check readme.txt contents is from tagged version", "/readme.txt",
88 FileUtils.fileRead( readmeTxt ) );
89 }
90
91 private void changeReadmeTxt( File readmeTxt )
92 throws Exception
93 {
94 FileWriter output = new FileWriter( readmeTxt );
95 try
96 {
97 output.write( "changed file" );
98 }
99 finally
100 {
101 IOUtil.close( output );
102 }
103
104 }
105 }