View Javadoc

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