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