001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.tck.command.remove; 020 021import java.io.File; 022import java.util.List; 023 024import org.apache.maven.scm.ScmFile; 025import org.apache.maven.scm.ScmFileSet; 026import org.apache.maven.scm.ScmFileStatus; 027import org.apache.maven.scm.ScmTckTestCase; 028import org.apache.maven.scm.command.checkin.CheckInScmResult; 029import org.apache.maven.scm.command.checkout.CheckOutScmResult; 030import org.apache.maven.scm.command.remove.RemoveScmResult; 031import org.junit.Test; 032 033import static org.junit.Assert.assertEquals; 034import static org.junit.Assert.assertFalse; 035import static org.junit.Assert.assertNotNull; 036 037/** This test tests the remove command. */ 038public abstract class RemoveCommandTckTest extends ScmTckTestCase { 039 @Test 040 public void testRemoveCommand() throws Exception { 041 // existence has been tested in ScmTckTestCase.setup() already 042 ScmFileSet fileSet = new ScmFileSet(getWorkingCopy(), "src/main/java/Application.java"); 043 RemoveScmResult removeResult = getScmManager().remove(getScmRepository(), fileSet, "remove1"); 044 045 assertResultIsSuccess(removeResult); 046 // check removed files 047 List<ScmFile> files = removeResult.getRemovedFiles(); 048 assertNotNull(files); 049 assertEquals(1, files.size()); 050 ScmFile file1 = files.get(0); 051 assertEquals(ScmFileStatus.DELETED, file1.getStatus()); 052 assertPath("src/main/java/Application.java", file1.getPath()); 053 054 // remove file with different basedir 055 fileSet = new ScmFileSet(new File(getWorkingCopy(), "src"), new File("test/java/Test.java")); 056 removeResult = getScmManager().remove(getScmRepository(), fileSet, "remove2"); 057 058 assertResultIsSuccess(removeResult); 059 // check removed files 060 files = removeResult.getRemovedFiles(); 061 assertNotNull(files); 062 assertEquals(1, files.size()); 063 file1 = files.get(0); 064 assertEquals(ScmFileStatus.DELETED, file1.getStatus()); 065 assertPath("test/java/Test.java", file1.getPath()); 066 067 // checkin changes 068 CheckInScmResult checkinResult = 069 getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), "Commit message"); 070 071 assertResultIsSuccess(checkinResult); 072 073 // do a new checkout 074 CheckOutScmResult checkoutResult = 075 getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy())); 076 077 assertResultIsSuccess(checkoutResult); 078 079 File applicationJava = new File(getAssertionCopy(), "src/main/java/Application.java"); 080 081 assertFalse("Application.java does exist even though it has been removed before", applicationJava.canRead()); 082 083 File testJava = new File(getAssertionCopy(), "src/test/java/Test.java"); 084 085 assertFalse("Test.java does exist even though it has been removed before", testJava.canRead()); 086 } 087}