View Javadoc

1   package org.apache.continuum.purge.executor;
2   
3   import org.apache.commons.io.filefilter.DirectoryFileFilter;
4   import org.apache.maven.archiva.consumers.core.repository.ArtifactFilenameFilter;
5   
6   import java.io.File;
7   import java.io.FileFilter;
8   import java.io.FilenameFilter;
9   
10  /*
11   * Licensed to the Apache Software Foundation (ASF) under one
12   * or more contributor license agreements.  See the NOTICE file
13   * distributed with this work for additional information
14   * regarding copyright ownership.  The ASF licenses this file
15   * to you under the Apache License, Version 2.0 (the
16   * "License"); you may not use this file except in compliance
17   * with the License.  You may obtain a copy of the License at
18   *
19   *   http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing,
22   * software distributed under the License is distributed on an
23   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24   * KIND, either express or implied.  See the License for the
25   * specific language governing permissions and limitations
26   * under the License.
27   */
28  
29  /**
30   * @author Maria Catherine Tan
31   */
32  public class RetentionCountDirectoryPurgeExecutorTest
33      extends AbstractPurgeExecutorTest
34  {
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39  
40          purgeReleasesDirTask = getRetentionCountReleasesDirPurgeTask();
41  
42          purgeBuildOutputDirTask = getRetentionCountBuildOutputDirPurgeTask();
43      }
44  
45      public void testReleasesDirPurging()
46          throws Exception
47      {
48          populateReleasesDirectory();
49  
50          String dirPath = getReleasesDirectoryLocation().getAbsolutePath();
51          FilenameFilter filter = new ArtifactFilenameFilter( "releases-" );
52  
53          File[] workingDir = new File( dirPath ).listFiles();
54          File[] releasesDir = new File( dirPath ).listFiles( filter );
55  
56          assertEquals( "# of folders inside working directory", 4, workingDir.length );
57          assertEquals( "# of releases folders inside working directory", 3, releasesDir.length );
58          assertExists( dirPath + "/1" );
59  
60          purgeExecutor.executeTask( purgeReleasesDirTask );
61  
62          workingDir = new File( dirPath ).listFiles();
63          releasesDir = new File( dirPath ).listFiles( filter );
64  
65          assertEquals( "# of folders inside working directory", 3, workingDir.length );
66          assertEquals( "# of releases folders inside working directory", 2, releasesDir.length );
67          assertExists( dirPath + "/1" );
68      }
69  
70      public void testBuildOutputDirPurging()
71          throws Exception
72      {
73          populateBuildOutputDirectory();
74  
75          String dirPath = getBuildOutputDirectoryLocation().getAbsolutePath();
76  
77          File projectPath1 = new File( dirPath, "1" );
78          File projectPath2 = new File( dirPath, "2" );
79  
80          FileFilter filter = DirectoryFileFilter.DIRECTORY;
81          File[] files1 = projectPath1.listFiles( filter );
82          File[] files2 = projectPath2.listFiles( filter );
83  
84          assertEquals( "check # of build output dir", 3, files1.length );
85          assertEquals( "check # of build output dir", 3, files2.length );
86  
87          purgeExecutor.executeTask( purgeBuildOutputDirTask );
88  
89          files1 = projectPath1.listFiles( filter );
90          files2 = projectPath2.listFiles( filter );
91  
92          assertEquals( "check # of build output dir", 2, files1.length );
93          assertEquals( "check # of build output dir", 2, files2.length );
94  
95          for ( File file : files1 )
96          {
97              assertExists( file.getAbsolutePath() + ".log.txt" );
98          }
99  
100         for ( File file : files2 )
101         {
102             assertExists( file.getAbsolutePath() + ".log.txt" );
103         }
104     }
105 }