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  import org.codehaus.plexus.util.IOUtil;
30  
31  import java.io.File;
32  import java.io.FileWriter;
33  
34  /**
35   * This test tests the tag command.
36   *
37   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
38   * @version $Id: TagCommandTckTest.java 1306856 2012-03-29 13:40:58Z olamy $
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 }