View Javadoc

1   package org.apache.maven.scm.tck.command.status;
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.ScmFile;
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.ScmFileStatus;
25  import org.apache.maven.scm.ScmTckTestCase;
26  import org.apache.maven.scm.ScmTestCase;
27  import org.apache.maven.scm.command.checkin.CheckInScmResult;
28  import org.apache.maven.scm.command.status.StatusScmResult;
29  import org.apache.maven.scm.manager.ScmManager;
30  import org.apache.maven.scm.repository.ScmRepository;
31  
32  import java.io.File;
33  import java.util.Iterator;
34  import java.util.List;
35  import java.util.TreeSet;
36  
37  /**
38   * This test tests the status command.
39   * <p/>
40   * It works like this:
41   * <p/>
42   * <ol>
43   * <li>Check out the files to directory getWorkingCopy().
44   * <li>Check out the files to directory getUpdatingCopy().
45   * <li>Change the files in getWorkingCopy().
46   * <li>Commit the files in getWorkingCopy(). Note that the provider <b>must</b> not
47   * use the check in command as it can be guaranteed to work as it's not yet tested.
48   * <li>Use the update command in getUpdatingCopy() to assert that the files
49   * that was supposed to be updated actually was updated.
50   * </ol>
51   *
52   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
53   *
54   */
55  public abstract class StatusCommandTckTest
56      extends ScmTckTestCase
57  {
58  
59      protected void commit( File workingDirectory, ScmRepository repository )
60          throws Exception
61      {
62          CheckInScmResult result = getScmManager().checkIn( repository, new ScmFileSet( workingDirectory ), "No msg" );
63  
64          assertTrue( "Check result was successful, output: " + result.getCommandOutput(), result.isSuccess() );
65  
66          List<ScmFile> committedFiles = result.getCheckedInFiles();
67  
68          assertEquals( "Expected 2 files in the committed files list " + committedFiles, 2, committedFiles.size() );
69      }
70  
71  
72      public void testStatusCommand()
73          throws Exception
74      {
75          ScmRepository repository = makeScmRepository( getScmUrl() );
76  
77          checkOut( getUpdatingCopy(), repository );
78  
79          // ----------------------------------------------------------------------
80          // Change the files
81          // ----------------------------------------------------------------------
82  
83          /*
84           * readme.txt is changed (changed file in the root directory)
85           * project.xml is added (added file in the root directory)
86           */
87  
88          // /readme.txt
89          ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
90  
91          // /project.xml
92          ScmTestCase.makeFile( getWorkingCopy(), "/project.xml", "changed project.xml" );
93  
94          addToWorkingTree( getWorkingCopy(), new File( "project.xml" ), repository );
95  
96          commit( getWorkingCopy(), repository );
97  
98          // /pom.xml
99          ScmTestCase.makeFile( getUpdatingCopy(), "/pom.xml", "changed pom.xml" );
100 
101         // /src/test/java/org
102         ScmTestCase.makeDirectory( getUpdatingCopy(), "/src/test/java/org" );
103 
104         addToWorkingTree( getUpdatingCopy(), new File( "src/test/java/org" ), repository );
105 
106         // /src/main/java/org/Foo.java
107         ScmTestCase.makeFile( getUpdatingCopy(), "/src/main/java/org/Foo.java" );
108 
109         addToWorkingTree( getUpdatingCopy(), new File( "src/main/java/org" ), repository );
110 
111         // src/main/java/org/Foo.java
112         addToWorkingTree( getUpdatingCopy(), new File( "src/main/java/org/Foo.java" ), repository );
113 
114         ScmManager scmManager = getScmManager();
115 
116         // ----------------------------------------------------------------------
117         // Check status the project
118         // src/main/java/org/Foo.java is added
119         // /pom.xml is modified
120         // check that readme and project.xml are not updated/created
121         // ----------------------------------------------------------------------
122 
123         StatusScmResult result = scmManager.getProviderByUrl( getScmUrl() )
124             .status( repository, new ScmFileSet( getUpdatingCopy() ) );
125 
126         assertNotNull( "The command returned a null result.", result );
127 
128         assertResultIsSuccess( result );
129 
130         List<ScmFile> changedFiles = result.getChangedFiles();
131 
132         assertEquals( "Expected 2 files in the updated files list " + changedFiles, 2, changedFiles.size() );
133 
134         // ----------------------------------------------------------------------
135         // Assert the files in the updated files list
136         // ----------------------------------------------------------------------
137 
138         Iterator<ScmFile> files = new TreeSet<ScmFile>( changedFiles ).iterator();
139 
140         ScmFile file = files.next();
141         assertPath( "/src/main/java/org/Foo.java", file.getPath() );
142         assertEquals( ScmFileStatus.ADDED, file.getStatus() );
143 
144         file = files.next();
145         assertPath( "/pom.xml", file.getPath() );
146         assertEquals( ScmFileStatus.MODIFIED, file.getStatus() );
147 
148         assertFile( getUpdatingCopy(), "/readme.txt" );
149 
150         assertFalse( "project.xml created incorrectly", new File( getUpdatingCopy(), "/project.xml" ).exists() );
151     }
152 }