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.remove;
20  
21  import java.io.File;
22  import java.util.List;
23  
24  import org.apache.maven.scm.CommandParameter;
25  import org.apache.maven.scm.CommandParameters;
26  import org.apache.maven.scm.ScmFile;
27  import org.apache.maven.scm.ScmFileSet;
28  import org.apache.maven.scm.ScmFileStatus;
29  import org.apache.maven.scm.ScmTckTestCase;
30  import org.apache.maven.scm.command.checkin.CheckInScmResult;
31  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
32  import org.apache.maven.scm.command.remove.RemoveScmResult;
33  import org.junit.Test;
34  
35  import static org.junit.Assert.assertEquals;
36  import static org.junit.Assert.assertFalse;
37  import static org.junit.Assert.assertNotNull;
38  
39  /** This test tests the remove command. */
40  public abstract class RemoveCommandTckTest extends ScmTckTestCase {
41      @Test
42      public void testRemoveCommand() throws Exception {
43          // existence has been tested in ScmTckTestCase.setup() already
44          ScmFileSet fileSet = new ScmFileSet(getWorkingCopy(), "src/main/java/Application.java");
45          RemoveScmResult removeResult = getScmManager().remove(getScmRepository(), fileSet, "remove1");
46  
47          assertResultIsSuccess(removeResult);
48          // check removed files
49          List<ScmFile> files = removeResult.getRemovedFiles();
50          assertNotNull(files);
51          assertEquals(1, files.size());
52          ScmFile file1 = files.get(0);
53          assertEquals(ScmFileStatus.DELETED, file1.getStatus());
54          assertPath("src/main/java/Application.java", file1.getPath());
55  
56          // remove file with different basedir
57          fileSet = new ScmFileSet(new File(getWorkingCopy(), "src"), new File("test/java/Test.java"));
58          removeResult = getScmManager().remove(getScmRepository(), fileSet, "remove2");
59  
60          assertResultIsSuccess(removeResult);
61          // check removed files
62          files = removeResult.getRemovedFiles();
63          assertNotNull(files);
64          assertEquals(1, files.size());
65          file1 = files.get(0);
66          assertEquals(ScmFileStatus.DELETED, file1.getStatus());
67          assertPath("test/java/Test.java", file1.getPath());
68  
69          CommandParameters commandParameters = new CommandParameters();
70          commandParameters.setString(CommandParameter.MESSAGE, "Commit message");
71  
72          // checkin changes
73          CheckInScmResult checkinResult =
74                  getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), commandParameters);
75  
76          assertResultIsSuccess(checkinResult);
77  
78          // do a new checkout
79          CheckOutScmResult checkoutResult =
80                  getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
81  
82          assertResultIsSuccess(checkoutResult);
83  
84          File applicationJava = new File(getAssertionCopy(), "src/main/java/Application.java");
85  
86          assertFalse("Application.java does exist even though it has been removed before", applicationJava.canRead());
87  
88          File testJava = new File(getAssertionCopy(), "src/test/java/Test.java");
89  
90          assertFalse("Test.java does exist even though it has been removed before", testJava.canRead());
91      }
92  }