View Javadoc

1   package org.apache.maven.scm.tck.command.blame;
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.ScmTckTestCase;
24  import org.apache.maven.scm.ScmTestCase;
25  import org.apache.maven.scm.command.blame.BlameLine;
26  import org.apache.maven.scm.command.blame.BlameScmRequest;
27  import org.apache.maven.scm.command.blame.BlameScmResult;
28  import org.apache.maven.scm.command.checkin.CheckInScmResult;
29  import org.apache.maven.scm.manager.ScmManager;
30  import org.apache.maven.scm.provider.ScmProvider;
31  import org.apache.maven.scm.repository.ScmRepository;
32  
33  import java.util.Date;
34  
35  /**
36   * @author Evgeny Mandrikov
37   */
38  public abstract class BlameCommandTckTest
39      extends ScmTckTestCase
40  {
41      private static final String COMMIT_MSG = "Second changelog";
42  
43      public void testBlameCommand()
44          throws Exception
45      {
46          ScmRepository repository = getScmRepository();
47          ScmManager manager = getScmManager();
48          ScmProvider provider = manager.getProviderByRepository( getScmRepository() );
49          ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
50  
51          BlameScmResult result;
52          BlameLine line;
53  
54          // === readme.txt ===
55          BlameScmRequest blameScmRequest = new BlameScmRequest( repository, fileSet );
56          blameScmRequest.setFilename( "readme.txt" );
57          //result = manager.blame( repository, fileSet, "readme.txt" );
58          result = manager.blame( blameScmRequest );
59          assertNotNull( "The command returned a null result.", result );
60          assertResultIsSuccess( result );
61          assertEquals( "Expected 1 line in blame", 1, result.getLines().size() );
62          line = result.getLines().get( 0 );
63          String initialRevision = line.getRevision();
64  
65          //Make a timestamp that we know are after initial revision but before the second
66          Date timeBeforeSecond = new Date(); // Current time
67          // pause a couple seconds...
68          Thread.sleep( 2000 );
69          //Make a change to the readme.txt and commit the change
70          ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
71          CheckInScmResult checkInResult = provider.checkIn( getScmRepository(), fileSet, COMMIT_MSG );
72          assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess() );
73  
74          result = manager.blame( repository, fileSet, "readme.txt" );
75  
76          // pause a couple seconds...
77          Thread.sleep( 2000 );
78          Date timeAfterSecond = new Date(); // Current time
79  
80          assertNotNull( "The command returned a null result.", result );
81          assertResultIsSuccess( result );
82  
83          assertEquals( "Expected 1 line in blame", 1, result.getLines().size() );
84          line = result.getLines().get( 0 );
85  
86          assertNotNull( "Expected not null author", line.getAuthor() );
87          assertNotNull( "Expected not null revision", line.getRevision() );
88          assertNotNull( "Expected not null date", line.getDate() );
89  
90          assertTrue( "Expected another revision", !initialRevision.equals( line.getRevision() ) );
91          if ( isTestDateTime() )
92          {
93              assertDateBetween( timeBeforeSecond, timeAfterSecond, line.getDate() );
94          }
95  
96          // === pom.xml ===
97          result = manager.blame( repository, fileSet, "pom.xml" );
98  
99          assertNotNull( "The command returned a null result.", result );
100 
101         assertResultIsSuccess( result );
102 
103         verifyResult( result );
104     }
105 
106     protected boolean isTestDateTime()
107     {
108         return true;
109     }
110 
111     protected void assertDateBetween( Date start, Date end, Date actual )
112     {
113         assertTrue( "Expected date between " + start + " and " + end + ", but was " + actual,
114                     start.before( actual ) && actual.before( end ) );
115     }
116 
117     protected abstract void verifyResult( BlameScmResult result );
118 }