001    package org.apache.maven.scm;
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    
022    import java.io.File;
023    import java.io.IOException;
024    import java.util.Iterator;
025    import java.util.List;
026    
027    import junit.framework.TestCase;
028    
029    /**
030     * @author dtran
031     */
032    public class ScmFileSetTest
033        extends TestCase
034    {
035        private static String basedirPath;
036    
037        public static String getBasedir()
038        {
039            if ( basedirPath != null )
040            {
041                return basedirPath;
042            }
043    
044            basedirPath = System.getProperty( "basedir" );
045    
046            if ( basedirPath == null )
047            {
048                basedirPath = new File( "" ).getAbsolutePath();
049            }
050    
051            return basedirPath;
052        }
053    
054        private String removeBasedir( String filename )
055        {
056            return filename.substring( getBasedir().length(), filename.length() );
057        }
058    
059        public void testFilesList()
060            throws IOException
061        {
062            ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ), "**/**" );
063            assertEquals( "src", fileSet.getBasedir().getName() );
064            assertEquals( "**/**", fileSet.getIncludes() );
065            // assertEquals( ScmFileSet.DEFAULT_EXCLUDES, fileSet.getExcludes() );
066            assertTrue( "List of files should be longer than 10 elements, but received: " + fileSet.getFileList().size(),
067                    fileSet.getFileList().size() > 10 );
068        }
069    
070        public void testFilesListWithoutIncludesResultsEmptyList()
071            throws IOException
072        {
073            ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ) );
074            assertEquals( 0, fileSet.getFileList().size() );
075        }
076    
077        public void testFilesListExcludes()
078            throws IOException
079        {
080            ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ), "**/**", "**/exclude/**" );
081    
082            List<File> files = fileSet.getFileList();
083    
084            Iterator<File> it = files.iterator();
085            while ( it.hasNext() )
086            {
087                File file = (File) it.next();
088                if ( removeBasedir( file.getAbsolutePath() ).indexOf( "exclude" ) != -1 )
089                {
090                    fail( "Found excludes in file set: " + file );
091                }
092            }
093        }
094    
095        public void testFilesListExcludes2()
096            throws IOException
097        {
098            ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ), "**/scmfileset/**", "**/exclude/**" );
099    
100            assertEquals( 2, fileSet.getFileList().size() );
101        }
102    
103        public void testFilesListNoExcludes()
104            throws IOException
105        {
106            ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ), "**/scmfileset/**" );
107    
108            assertEquals( 4, fileSet.getFileList().size() );
109        }
110    
111    }