View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.tck.command.tag;
20  
21  import java.io.File;
22  import java.io.FileWriter;
23  
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.ScmTag;
26  import org.apache.maven.scm.ScmTckTestCase;
27  import org.apache.maven.scm.command.checkin.CheckInScmResult;
28  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
29  import org.apache.maven.scm.command.tag.TagScmResult;
30  import org.codehaus.plexus.util.FileUtils;
31  import org.codehaus.plexus.util.IOUtil;
32  import org.junit.Test;
33  
34  import static org.junit.Assert.assertEquals;
35  import static org.junit.Assert.assertFalse;
36  
37  /**
38   * This test tests the tag command.
39   *
40   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
41   *
42   */
43  public abstract class TagCommandTckTest extends ScmTckTestCase {
44  
45      protected String getTagName() {
46          return "test-tag";
47      }
48  
49      @Test
50      public void testTagCommandTest() throws Exception {
51          String tag = getTagName();
52  
53          @SuppressWarnings("deprecation")
54          TagScmResult tagResult = getScmManager()
55                  .getProviderByUrl(getScmUrl())
56                  .tag(getScmRepository(), new ScmFileSet(getWorkingCopy()), tag);
57  
58          assertResultIsSuccess(tagResult);
59  
60          // see https://issues.apache.org/jira/browse/SCM-754
61          // assertEquals( "check all 4 files tagged", 4, tagResult.getTaggedFiles().size() );
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()
89                  .getProviderByUrl(getScmUrl())
90                  .checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmTag(tag));
91  
92          assertResultIsSuccess(checkoutResult);
93  
94          assertEquals("check readme.txt contents is from tagged version", "/readme.txt", FileUtils.fileRead(readmeTxt));
95      }
96  
97      private void changeReadmeTxt(File readmeTxt) throws Exception {
98          FileWriter output = new FileWriter(readmeTxt);
99          try {
100             output.write("changed file");
101         } finally {
102             IOUtil.close(output);
103         }
104     }
105 }