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 CleanAllPurgeExecutorTest
33      extends AbstractPurgeExecutorTest
34  {
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39  
40          purgeDefaultRepoTask = getCleanAllDefaultRepoPurgeTask();
41  
42          purgeReleasesDirTask = getCleanAllReleasesDirPurgeTask();
43  
44          purgeBuildOutputDirTask = getCleanAllBuildOutputDirPurgeTask();
45      }
46  
47      public void testCleanAllRepositoryPurging()
48          throws Exception
49      {
50          populateDefaultRepository();
51  
52          purgeExecutor.executeTask( purgeDefaultRepoTask );
53  
54          assertIsEmpty( getDefaultRepositoryLocation() );
55      }
56  
57      public void testCleanAllReleasesPurging()
58          throws Exception
59      {
60          populateReleasesDirectory();
61  
62          File workingDir = getReleasesDirectoryLocation();
63  
64          FilenameFilter filter = new ArtifactFilenameFilter( "releases-" );
65  
66          File[] releasesDir = workingDir.listFiles( filter );
67  
68          assertExists( workingDir.getAbsolutePath() + "/1" );
69  
70          assertEquals( "check # of releases directory", 3, releasesDir.length );
71  
72          purgeExecutor.executeTask( purgeReleasesDirTask );
73  
74          // check if no releases dir
75  
76          releasesDir = workingDir.listFiles( filter );
77  
78          assertEquals( "releases directory must be empty", 0, releasesDir.length );
79  
80          assertExists( workingDir.getAbsolutePath() + "/1" );
81      }
82  
83      public void testCleanAllBuildOutputPurging()
84          throws Exception
85      {
86          populateBuildOutputDirectory();
87  
88          File buildOutputDir = getBuildOutputDirectoryLocation();
89  
90          purgeExecutor.executeTask( purgeBuildOutputDirTask );
91  
92          FileFilter filter = DirectoryFileFilter.DIRECTORY;
93  
94          File[] projectsDir = buildOutputDir.listFiles( filter );
95  
96          for ( File projectDir : projectsDir )
97          {
98              assertIsEmpty( projectDir );
99          }
100     }
101 }