View Javadoc
1   package org.apache.maven.scm;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.util.Iterator;
25  import java.util.List;
26  
27  import junit.framework.TestCase;
28  
29  /**
30   * @author dtran
31   */
32  public class ScmFileSetTest
33      extends TestCase
34  {
35      private static String basedirPath;
36  
37      public static String getBasedir()
38      {
39          if ( basedirPath != null )
40          {
41              return basedirPath;
42          }
43  
44          basedirPath = System.getProperty( "basedir" );
45  
46          if ( basedirPath == null )
47          {
48              basedirPath = new File( "" ).getAbsolutePath();
49          }
50  
51          return basedirPath;
52      }
53  
54      private String removeBasedir( String filename )
55      {
56          return filename.substring( getBasedir().length(), filename.length() );
57      }
58  
59      public void testFilesList()
60          throws IOException
61      {
62          ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ), "**/**" );
63          assertEquals( "src", fileSet.getBasedir().getName() );
64          assertEquals( "**/**", fileSet.getIncludes() );
65          // assertEquals( ScmFileSet.DEFAULT_EXCLUDES, fileSet.getExcludes() );
66          assertTrue( "List of files should be longer than 10 elements, but received: " + fileSet.getFileList().size(),
67                  fileSet.getFileList().size() > 10 );
68      }
69  
70      public void testFilesListWithoutIncludesResultsEmptyList()
71          throws IOException
72      {
73          ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ) );
74          assertEquals( 0, fileSet.getFileList().size() );
75      }
76  
77      public void testFilesListExcludes()
78          throws IOException
79      {
80          ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ), "**/**", "**/exclude/**" );
81  
82          List<File> files = fileSet.getFileList();
83  
84          Iterator<File> it = files.iterator();
85          while ( it.hasNext() )
86          {
87              File file = (File) it.next();
88              if ( removeBasedir( file.getAbsolutePath() ).indexOf( "exclude" ) != -1 )
89              {
90                  fail( "Found excludes in file set: " + file );
91              }
92          }
93      }
94  
95      public void testFilesListExcludes2()
96          throws IOException
97      {
98          ScmFileSet fileSet = new ScmFileSet( new File( getBasedir(), "src" ), "**/scmfileset/**", "**/exclude/**" );
99  
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 }