View Javadoc
1   package org.apache.maven.plugins.resources;
2   
3   import java.io.File;
4   import java.util.Collections;
5   
6   import org.apache.maven.model.Resource;
7   import org.apache.maven.plugin.testing.AbstractMojoTestCase;
8   import org.apache.maven.plugins.resources.ResourcesMojo;
9   import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub;
10  import org.codehaus.plexus.util.FileUtils;
11  
12  /*
13   * Licensed to the Apache Software Foundation (ASF) under one
14   * or more contributor license agreements.  See the NOTICE file
15   * distributed with this work for additional information
16   * regarding copyright ownership.  The ASF licenses this file
17   * to you under the Apache License, Version 2.0 (the
18   * "License"); you may not use this file except in compliance
19   * with the License.  You may obtain a copy of the License at
20   *
21   *    http://www.apache.org/licenses/LICENSE-2.0
22   *
23   * Unless required by applicable law or agreed to in writing,
24   * software distributed under the License is distributed on an
25   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26   * KIND, either express or implied.  See the License for the
27   * specific language governing permissions and limitations
28   * under the License.
29   */
30  
31  /**
32   * @author Olivier Lamy
33   * @version $Id$
34   */
35  public class CopyResourcesMojoTest
36      extends AbstractMojoTestCase
37  {
38  
39      protected final static String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml";
40  
41      File outputDirectory = new File( getBasedir(), "/target/copyResourcesTests" );
42  
43      protected void setUp()
44          throws Exception
45      {
46          super.setUp();
47          if ( !outputDirectory.exists() )
48          {
49              outputDirectory.mkdirs();
50          }
51          else
52          {
53              FileUtils.cleanDirectory( outputDirectory );
54          }
55      }
56  
57      public void testCopyWithoutFiltering()
58          throws Exception
59      {
60          File testPom = new File( getBasedir(), defaultPomFilePath );
61          ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
62  
63          mojo.setOutputDirectory( outputDirectory );
64  
65          Resource resource = new Resource();
66          resource.setDirectory( getBasedir() + "/src/test/unit-files/copy-resources-test/no-filter" );
67          resource.setFiltering( false );
68  
69          mojo.setResources( Collections.singletonList( resource ) );
70  
71          MavenProjectResourcesStub project = new MavenProjectResourcesStub( "CopyResourcesMojoTest" );
72          File targetFile =  new File( getBasedir(), "/target/copyResourcesTests" );
73          project.setBaseDir( targetFile );
74          setVariableValueToObject( mojo, "project", project );
75          mojo.execute();
76  
77          assertTrue( new File( targetFile, "config.properties" ).exists() );
78      }
79  
80  }