View Javadoc

1   package org.apache.maven.scm.tck.command.tag;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * This test tests the tag command.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   * @version $Id: TagCommandTckTest.java 525259 2007-04-03 20:03:53Z evenisse $
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  }