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.tag; 020 021import java.io.File; 022import java.io.Writer; 023import java.nio.file.Files; 024import java.nio.file.Path; 025 026import org.apache.maven.scm.CommandParameter; 027import org.apache.maven.scm.CommandParameters; 028import org.apache.maven.scm.ScmFileSet; 029import org.apache.maven.scm.ScmTag; 030import org.apache.maven.scm.ScmTckTestCase; 031import org.apache.maven.scm.command.checkin.CheckInScmResult; 032import org.apache.maven.scm.command.checkout.CheckOutScmResult; 033import org.apache.maven.scm.command.tag.TagScmResult; 034import org.codehaus.plexus.util.FileUtils; 035import org.junit.Test; 036 037import static org.junit.Assert.assertEquals; 038import static org.junit.Assert.assertFalse; 039 040/** 041 * This test tests the tag command. 042 * 043 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 044 */ 045public abstract class TagCommandTckTest extends ScmTckTestCase { 046 047 protected String getTagName() { 048 return "test-tag"; 049 } 050 051 @Test 052 public void testTagCommandTest() throws Exception { 053 String tag = getTagName(); 054 055 @SuppressWarnings("deprecation") 056 TagScmResult tagResult = getScmManager() 057 .getProviderByUrl(getScmUrl()) 058 .tag(getScmRepository(), new ScmFileSet(getWorkingCopy()), tag); 059 060 assertResultIsSuccess(tagResult); 061 062 // see https://issues.apache.org/jira/browse/SCM-754 063 // assertEquals( "check all 4 files tagged", 4, tagResult.getTaggedFiles().size() ); 064 065 File readmeTxt = new File(getWorkingCopy(), "readme.txt"); 066 067 assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt)); 068 069 this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository()); 070 changeReadmeTxt(readmeTxt.toPath()); 071 072 CommandParameters commandParameters = new CommandParameters(); 073 commandParameters.setString(CommandParameter.MESSAGE, "Commit message"); 074 075 CheckInScmResult checkinResult = 076 getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), commandParameters); 077 078 assertResultIsSuccess(checkinResult); 079 080 CheckOutScmResult checkoutResult = 081 getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy())); 082 083 assertResultIsSuccess(checkoutResult); 084 085 readmeTxt = new File(getAssertionCopy(), "readme.txt"); 086 087 assertEquals("check readme.txt contents", "changed file", FileUtils.fileRead(readmeTxt)); 088 089 deleteDirectory(getAssertionCopy()); 090 091 assertFalse("check previous assertion copy deleted", getAssertionCopy().exists()); 092 093 checkoutResult = getScmManager() 094 .getProviderByUrl(getScmUrl()) 095 .checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmTag(tag)); 096 097 assertResultIsSuccess(checkoutResult); 098 099 assertEquals("check readme.txt contents is from tagged version", "/readme.txt", FileUtils.fileRead(readmeTxt)); 100 } 101 102 private void changeReadmeTxt(Path readmeTxt) throws Exception { 103 try (Writer output = Files.newBufferedWriter(readmeTxt)) { 104 output.write("changed file"); 105 } 106 } 107}