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