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.untag;
020
021import org.apache.maven.scm.CommandParameter;
022import org.apache.maven.scm.CommandParameters;
023import org.apache.maven.scm.ScmException;
024import org.apache.maven.scm.ScmFileSet;
025import org.apache.maven.scm.ScmTag;
026import org.apache.maven.scm.ScmTagParameters;
027import org.apache.maven.scm.ScmTckTestCase;
028import org.apache.maven.scm.command.checkout.CheckOutScmResult;
029import org.apache.maven.scm.command.tag.TagScmResult;
030import org.apache.maven.scm.command.untag.UntagScmResult;
031import org.apache.maven.scm.provider.ScmProvider;
032import org.apache.maven.scm.repository.ScmRepository;
033import org.junit.Test;
034
035import static org.junit.Assert.assertFalse;
036
037/**
038 * This test tests the untag command.
039 */
040public abstract class UntagCommandTckTest extends ScmTckTestCase {
041
042    protected String getTagName() {
043        return "test-untag";
044    }
045
046    @Test
047    public void testUntagCommandTest() throws Exception {
048        String tag = getTagName();
049        ScmProvider scmProvider = getScmManager().getProviderByUrl(getScmUrl());
050        ScmRepository scmRepository = getScmRepository();
051        ScmFileSet files = new ScmFileSet(getWorkingCopy());
052        TagScmResult tagResult = scmProvider.tag(scmRepository, files, tag, new ScmTagParameters());
053
054        assertResultIsSuccess(tagResult);
055        CommandParameters params = new CommandParameters();
056        params.setString(CommandParameter.TAG_NAME, tag);
057
058        UntagScmResult untagResult = scmProvider.untag(scmRepository, files, params);
059
060        assertResultIsSuccess(untagResult);
061
062        try {
063            untagResult = scmProvider.untag(scmRepository, files, params);
064            assertFalse(untagResult.isSuccess()); // already been deleted
065        } catch (ScmException ignored) {
066        }
067
068        try {
069            CheckOutScmResult checkoutResult =
070                    getScmManager().checkOut(scmRepository, new ScmFileSet(getAssertionCopy()), new ScmTag(tag));
071            assertFalse(checkoutResult.isSuccess()); // can't check out a deleted tags
072        } catch (ScmException ignored) {
073        }
074    }
075}