View Javadoc
1   package org.apache.maven.scm.tck.command.changelog;
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.ChangeSet;
23  import org.apache.maven.scm.ScmBranch;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.ScmTckTestCase;
26  import org.apache.maven.scm.ScmTestCase;
27  import org.apache.maven.scm.ScmVersion;
28  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
29  import org.apache.maven.scm.command.checkin.CheckInScmResult;
30  import org.apache.maven.scm.provider.ScmProvider;
31  
32  import java.util.Date;
33  
34  /**
35   * Test Changlog command. <br>
36   * 1. Get initial log <br>
37   * 2. Add one revision <br>
38   * 3. Get the two logs <br>
39   * 4. Get the last log based on date <br>
40   * 5. Test last log for date and comment <br>
41   *
42   * @author <a href="mailto:torbjorn@smorgrav.org">Torbj�rn Eikli Sm�rgrav</a>
43   */
44  public abstract class ChangeLogCommandTckTest
45      extends ScmTckTestCase
46  {
47      private static final String COMMIT_MSG = "Second changelog";
48  
49      public void testChangeLogCommand()
50          throws Exception
51      {
52          Thread.sleep( 1000 );
53          ScmProvider provider = getScmManager().getProviderByRepository( getScmRepository() );
54          ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
55  
56          ChangeLogScmResult firstResult =
57              provider.changeLog( getScmRepository(), fileSet, null, null, 0, (ScmBranch) null, null );
58          assertTrue( firstResult.getProviderMessage() + ": " + firstResult.getCommandLine() + "\n"
59                          + firstResult.getCommandOutput(), firstResult.isSuccess() );
60  
61          //for svn, cvs, git, the repo get recreated for each test and therefore initial changelog size is 1
62          // for SCM like perforce, it is not possible to recreate the repo, therefor the size will be greater then 1
63          int firstLogSize = firstResult.getChangeLog().getChangeSets().size();
64          assertTrue( "Unexpected initial log size", firstLogSize >= 1 );
65  
66          //Make a timestamp that we know are after initial revision but before the second
67          Date timeBeforeSecond = new Date(); //Current time
68  
69          // pause a couple seconds... [SCM-244]
70          Thread.sleep( 2000 );
71  
72          //Make a change to the readme.txt and commit the change
73          this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
74          ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
75          CheckInScmResult checkInResult = provider.checkIn( getScmRepository(), fileSet, COMMIT_MSG );
76          assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess() );
77  
78          ChangeLogScmResult secondResult = provider.changeLog( getScmRepository(), fileSet, (ScmVersion) null, null );
79          assertTrue( secondResult.getProviderMessage(), secondResult.isSuccess() );
80          assertEquals( firstLogSize + 1, secondResult.getChangeLog().getChangeSets().size() );
81  
82          //Now only retrieve the changelog after timeBeforeSecondChangeLog
83          Date currentTime = new Date();
84          ChangeLogScmResult thirdResult = provider
85              .changeLog( getScmRepository(), fileSet, timeBeforeSecond, currentTime, 0, new ScmBranch( "" ) );
86  
87          //Thorough assert of the last result
88          assertTrue( thirdResult.getProviderMessage(), thirdResult.isSuccess() );
89          assertEquals( 1, thirdResult.getChangeLog().getChangeSets().size() );
90          ChangeSet changeset = thirdResult.getChangeLog().getChangeSets().get( 0 );
91          assertTrue( changeset.getDate().after( timeBeforeSecond ) );
92  
93  
94          assertEquals( COMMIT_MSG, changeset.getComment() );
95      }
96  }