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.CommandParameter; 025import org.apache.maven.scm.CommandParameters; 026import org.apache.maven.scm.ScmFile; 027import org.apache.maven.scm.ScmFileSet; 028import org.apache.maven.scm.ScmFileStatus; 029import org.apache.maven.scm.ScmTckTestCase; 030import org.apache.maven.scm.command.checkin.CheckInScmResult; 031import org.apache.maven.scm.command.checkout.CheckOutScmResult; 032import org.apache.maven.scm.command.remove.RemoveScmResult; 033import org.junit.Test; 034 035import static org.junit.Assert.assertEquals; 036import static org.junit.Assert.assertFalse; 037import static org.junit.Assert.assertNotNull; 038 039/** This test tests the remove command. */ 040public abstract class RemoveCommandTckTest extends ScmTckTestCase { 041 @Test 042 public void testRemoveCommand() throws Exception { 043 // existence has been tested in ScmTckTestCase.setup() already 044 ScmFileSet fileSet = new ScmFileSet(getWorkingCopy(), "src/main/java/Application.java"); 045 RemoveScmResult removeResult = getScmManager().remove(getScmRepository(), fileSet, "remove1"); 046 047 assertResultIsSuccess(removeResult); 048 // check removed files 049 List<ScmFile> files = removeResult.getRemovedFiles(); 050 assertNotNull(files); 051 assertEquals(1, files.size()); 052 ScmFile file1 = files.get(0); 053 assertEquals(ScmFileStatus.DELETED, file1.getStatus()); 054 assertPath("src/main/java/Application.java", file1.getPath()); 055 056 // remove file with different basedir 057 fileSet = new ScmFileSet(new File(getWorkingCopy(), "src"), new File("test/java/Test.java")); 058 removeResult = getScmManager().remove(getScmRepository(), fileSet, "remove2"); 059 060 assertResultIsSuccess(removeResult); 061 // check removed files 062 files = removeResult.getRemovedFiles(); 063 assertNotNull(files); 064 assertEquals(1, files.size()); 065 file1 = files.get(0); 066 assertEquals(ScmFileStatus.DELETED, file1.getStatus()); 067 assertPath("test/java/Test.java", file1.getPath()); 068 069 CommandParameters commandParameters = new CommandParameters(); 070 commandParameters.setString(CommandParameter.MESSAGE, "Commit message"); 071 commandParameters.setString(CommandParameter.SCM_COMMIT_SIGN, "false"); 072 073 // checkin changes 074 CheckInScmResult checkinResult = 075 getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), commandParameters); 076 077 assertResultIsSuccess(checkinResult); 078 079 // do a new checkout 080 CheckOutScmResult checkoutResult = 081 getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy())); 082 083 assertResultIsSuccess(checkoutResult); 084 085 File applicationJava = new File(getAssertionCopy(), "src/main/java/Application.java"); 086 087 assertFalse("Application.java does exist even though it has been removed before", applicationJava.canRead()); 088 089 File testJava = new File(getAssertionCopy(), "src/test/java/Test.java"); 090 091 assertFalse("Test.java does exist even though it has been removed before", testJava.canRead()); 092 } 093}