View Javadoc
1   package org.apache.maven.scm.provider.accurev.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 static org.apache.maven.scm.ChangeSetMatcher.changeSet;
23  import static org.hamcrest.Matchers.is;
24  import static org.junit.Assert.assertThat;
25  
26  import java.io.File;
27  import java.io.InputStream;
28  import java.util.ArrayList;
29  import java.util.Date;
30  import java.util.List;
31  
32  import org.apache.maven.scm.ChangeSet;
33  import org.apache.maven.scm.ScmBranch;
34  import org.apache.maven.scm.ScmFileSet;
35  import org.apache.maven.scm.ScmTestCase;
36  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
37  import org.apache.maven.scm.command.checkin.CheckInScmResult;
38  import org.apache.maven.scm.provider.ScmProvider;
39  import org.apache.maven.scm.provider.accurev.cli.AccuRevCommandLine;
40  import org.apache.maven.scm.provider.accurev.cli.AccuRevJUnitUtil;
41  import org.apache.maven.scm.provider.accurev.command.AccuRevTckUtil;
42  import org.apache.maven.scm.repository.ScmRepository;
43  import org.apache.maven.scm.tck.command.changelog.ChangeLogCommandTckTest;
44  import org.hamcrest.Matchers;
45  import org.junit.After;
46  import org.junit.Before;
47  import org.junit.Test;
48  import org.junit.runner.RunWith;
49  import org.junit.runners.JUnit4;
50  
51  @RunWith( JUnit4.class )
52  public class AccuRevChangeLogCommandTckTest
53      extends ChangeLogCommandTckTest
54  {
55  
56      protected AccuRevTckUtil accurevTckTestUtil = new AccuRevTckUtil();
57  
58      @Override
59      @Test
60      public void testChangeLogCommand()
61          throws Exception
62      {
63          super.testChangeLogCommand();
64      }
65  
66      @SuppressWarnings( "unchecked" )
67      @Test
68      public void testUpstreamChangesIncludedInChangeLog()
69          throws Exception
70      {
71  
72          AccuRevCommandLine accurev = accurevTckTestUtil.getAccuRevCL();
73  
74          // UpdatingCopy is a workspace rooted at a substream
75          String workingStream = accurevTckTestUtil.getWorkingStream();
76          String subStream = accurevTckTestUtil.getDepotName() + "_sub_stream";
77          accurev.mkstream( workingStream, subStream );
78  
79          ScmRepository mainRepository = getScmRepository();
80          ScmProvider provider = getScmManager().getProviderByRepository( mainRepository );
81  
82          // Create a workspace at the updating copy location backed by the substream
83          ScmBranch branch = new ScmBranch( "sub_stream" );
84          provider.checkOut( mainRepository, new ScmFileSet( getUpdatingCopy() ), branch );
85  
86          Thread.sleep( 1000 );
87          ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
88  
89          // Make a timestamp that we know are after initial revision but before the second
90          Date timeBeforeUpstreamCheckin = new Date(); // Current time
91  
92          // pause a couple seconds... [SCM-244]
93          Thread.sleep( 2000 );
94  
95          // Make a change to the readme.txt and commit the change
96          ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
97          ScmTestCase.makeFile( getWorkingCopy(), "/src/test/java/Test.java", "changed Test.java" );
98          CheckInScmResult checkInResult = provider.checkIn( mainRepository, fileSet, "upstream workspace promote" );
99          assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess() );
100 
101         Thread.sleep( 2000 );
102 
103         Date timeBeforeDownstreamCheckin = new Date();
104 
105         Thread.sleep( 2000 );
106 
107         ScmFileSet updateFileSet = new ScmFileSet( getUpdatingCopy() );
108         provider.update( mainRepository, updateFileSet );
109         ScmTestCase.makeFile( getUpdatingCopy(), "/pom.xml", "changed pom.xml" );
110         ScmTestCase.makeFile( getUpdatingCopy(), "/src/test/java/Test.java", "changed again Test.java" );
111         checkInResult = provider.checkIn( mainRepository, updateFileSet, "downstream workspace promote" );
112         assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess() );
113 
114         Thread.sleep( 2000 );
115 
116         Date timeBeforeDownstreamPromote = new Date();
117 
118         List<File> promotedFiles = new ArrayList<File>();
119         accurev.promoteStream( subStream, "stream promote", promotedFiles );
120 
121         Thread.sleep( 2000 );
122 
123         Date timeEnd = new Date();
124 
125         // Changelog beforeUpstreamCheckin to end should contain both upstream and downstream changes. upstream change
126         // should NOT include Test.java
127 
128         ChangeLogScmResult result =
129             provider.changeLog( mainRepository, fileSet, timeBeforeUpstreamCheckin, timeEnd, 0, branch );
130         assertTrue( "changelog beforeUpstreamCheckin to end", result.isSuccess() );
131 
132         List<ChangeSet> changeSets = result.getChangeLog().getChangeSets();
133         assertThat( changeSets.size(), is( 2 ) );
134         assertThat( changeSets, Matchers.<ChangeSet>hasItems( changeSet( "Upstream changes", "/readme.txt" ),
135                                                               changeSet( "downstream workspace promote", "/./pom.xml",
136                                                                          "/./src/test/java/Test.java" ) ) );
137 
138         // Changelog beforeUpstreamCheckin to beforeDownstreamCheckin should include just upstream change including
139         // Test.java
140         result =
141             provider.changeLog( mainRepository, fileSet, timeBeforeUpstreamCheckin, timeBeforeDownstreamCheckin, 0,
142                                 branch );
143         assertTrue( "changelog beforeUpstreamCheckin to beforeDownstreamCheckin", result.isSuccess() );
144 
145         changeSets = result.getChangeLog().getChangeSets();
146         assertThat( changeSets.size(), is( 1 ) );
147         assertThat( changeSets.get( 0 ), changeSet( "Upstream changes", "/readme.txt", "/src/test/java/Test.java" ) );
148 
149         // Changelog beforeDownstreamCheckin to end should include just downstream change
150         result = provider.changeLog( mainRepository, fileSet, timeBeforeDownstreamCheckin, timeEnd, 0, branch );
151         assertTrue( "changelog beforeDownstreamCheckin to end", result.isSuccess() );
152 
153         changeSets = result.getChangeLog().getChangeSets();
154         assertThat( changeSets.size(), is( 1 ) );
155         assertThat( changeSets.get( 0 ), changeSet( "downstream workspace promote", "/./pom.xml",
156                                                     "/./src/test/java/Test.java" ) );
157 
158         // Changelog beforeDownstreamPromote to end should be empty
159         result = provider.changeLog( mainRepository, fileSet, timeBeforeDownstreamPromote, timeEnd, 0, branch );
160         assertTrue( "changelog beforeDownstreamPromote to end", result.isSuccess() );
161 
162         changeSets = result.getChangeLog().getChangeSets();
163         assertThat( changeSets.size(), is( 0 ) );
164 
165     }
166 
167     @Override
168     @Before
169     public void setUp()
170         throws Exception
171     {
172         super.setUp();
173     }
174 
175     @Override
176     protected File getWorkingCopy()
177     {
178         return accurevTckTestUtil.getWorkingCopy();
179     }
180 
181     @Override
182     protected File getAssertionCopy()
183     {
184         return accurevTckTestUtil.getAssertionCopy();
185     }
186 
187     @Override
188     protected File getUpdatingCopy()
189     {
190         return accurevTckTestUtil.getUpdatingCopy();
191     }
192 
193     @Override
194     public String getScmUrl()
195         throws Exception
196     {
197         return accurevTckTestUtil.getScmUrl();
198     }
199 
200     @Override
201     public void initRepo()
202         throws Exception
203     {
204         accurevTckTestUtil.initRepo( getContainer() );
205 
206     }
207 
208     @Override
209     @After
210     public void tearDown()
211         throws Exception
212     {
213         try
214         {
215             accurevTckTestUtil.tearDown();
216             accurevTckTestUtil.removeWorkSpace( getWorkingCopy() );
217             accurevTckTestUtil.removeWorkSpace( getAssertionCopy() );
218         }
219         finally
220         {
221             super.tearDown();
222         }
223     }
224 
225     @Override
226     protected InputStream getCustomConfiguration()
227         throws Exception
228 
229     {
230         return AccuRevJUnitUtil.getPlexusConfiguration();
231     }
232 
233 }