001package org.apache.maven.scm.provider.local.command.mkdir;
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;
023
024import org.apache.maven.scm.ScmFileSet;
025import org.apache.maven.scm.command.list.ListScmResult;
026import org.apache.maven.scm.command.mkdir.MkdirScmResult;
027import org.apache.maven.scm.tck.command.mkdir.MkdirCommandTckTest;
028
029/**
030 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
031 *
032 */
033public class LocalMkdirCommandTckTest
034    extends MkdirCommandTckTest
035{
036    private static final String moduleName = "checkin-tck";
037
038    public String getScmUrl()
039        throws Exception
040    {
041        return "scm:local|" + getRepositoryRoot() + "|" + moduleName;
042    }
043
044    public void initRepo()
045        throws Exception
046    {
047        makeRepo( getRepositoryRoot() );
048    }
049
050    private void makeRepo( File workingDirectory )
051        throws Exception
052    {
053        makeFile( workingDirectory, moduleName + "/pom.xml", "/pom.xml" );
054
055        makeFile( workingDirectory, moduleName + "/readme.txt", "/readme.txt" );
056
057        makeFile( workingDirectory, moduleName + "/src/main/java/Application.java", "/src/main/java/Application.java" );
058
059        makeFile( workingDirectory, moduleName + "/src/test/java/Test.java", "/src/test/java/Test.java" );
060
061        makeDirectory( workingDirectory, moduleName + "/src/test/resources" );
062    }
063
064    public void testMkdirCommandMkdirUrl()
065        throws Exception
066    {
067        ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( getMissingDirectory() ) );
068
069        MkdirScmResult result = getScmManager().mkdir( getScmRepository(), fileSet, "Mkdir message", false );
070
071        assertResultIsSuccess( result );
072
073        ListScmResult listResult = getScmManager().list( getScmRepository(), fileSet, true, null );
074
075        assertTrue( "Directory should have been found.", listResult.isSuccess() );
076    }
077
078    public void testMkdirCommandDirAlreadyAdded()
079        throws Exception
080    {
081        ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( getMissingDirectory() ) );
082
083        MkdirScmResult result = getScmManager().mkdir( getScmRepository(), fileSet, "Mkdir message", false );
084
085        assertResultIsSuccess( result );
086
087        ListScmResult listResult = getScmManager().list( getScmRepository(), fileSet, true, null );
088
089        assertTrue( "Directory should have been found.", listResult.isSuccess() );
090
091        // add the directory again
092        result = getScmManager().mkdir( getScmRepository(), fileSet, "Mkdir message", false );
093
094        assertFalse( result.isSuccess() );
095
096        printOutputError( result );
097    }
098}