1 package org.apache.maven.plugin.resources;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
48
49
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
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 }