View Javadoc

1   package org.apache.maven.plugin.resources;
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.util.LinkedList;
24  import java.util.List;
25  
26  import org.apache.maven.plugin.resources.stub.MavenProjectResourcesStub;
27  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
28  import org.codehaus.plexus.util.FileUtils;
29  
30  public class TestResourcesTest
31      extends AbstractMojoTestCase
32  {
33      protected final static String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml";
34  
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39      }
40  
41      protected void tearDown()
42      {
43  
44      }
45  
46      /**
47       * test mojo lookup, test harness should be working fine
48       *
49       * @throws Exception
50       */
51      public void testHarnessEnvironment()
52          throws Exception
53      {
54          File testPom = new File( getBasedir(), defaultPomFilePath );
55          ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "testResources", testPom );
56  
57          assertNotNull( mojo );
58      }
59  
60      /**
61       * @throws Exception
62       */
63      public void testTestResourceDirectoryCreation()
64          throws Exception
65      {
66          File testPom = new File( getBasedir(), defaultPomFilePath );
67          TestResourcesMojo mojo = (TestResourcesMojo) lookupMojo( "testResources", testPom );
68          MavenProjectResourcesStub project = new MavenProjectResourcesStub( "testResourceDirectoryStructure" );
69          List resources = project.getBuild().getResources();
70  
71          assertNotNull( mojo );
72  
73          project.addFile( "file4.txt" );
74          project.addFile( "package/file3.nottest" );
75          project.addFile( "notpackage/file1.include" );
76          project.addFile( "package/test/file1.txt" );
77          project.addFile( "notpackage/test/file2.txt" );
78          project.setupBuildEnvironment();
79  
80          setVariableValueToObject( mojo, "project", project );
81          setVariableValueToObject( mojo, "resources", resources );
82          setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getTestOutputDirectory() ) );
83          setVariableValueToObject( mojo, "buildFilters", new LinkedList() );
84          setVariableValueToObject( mojo, "useBuildFilters", Boolean.TRUE );
85          mojo.execute();
86  
87          String resorucesDir = project.getTestOutputDirectory();
88  
89          assertTrue( FileUtils.fileExists( resorucesDir + "/file4.txt" ) );
90          assertTrue( FileUtils.fileExists( resorucesDir + "/package/file3.nottest" ) );
91          assertTrue( FileUtils.fileExists( resorucesDir + "/notpackage/file1.include" ) );
92          assertTrue( FileUtils.fileExists( resorucesDir + "/package/test" ) );
93          assertTrue( FileUtils.fileExists( resorucesDir + "/notpackage/test" ) );
94      }
95  }