1 package org.apache.maven.shared.filtering;
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.io.FileInputStream;
24 import java.util.Properties;
25
26 import org.apache.maven.project.MavenProject;
27 import org.codehaus.plexus.PlexusTestCase;
28
29
30
31
32
33
34 public class TestReflectionProperties
35 extends PlexusTestCase
36 {
37
38 public void testSimpleFiltering()
39 throws Exception
40 {
41 FileInputStream readFileInputStream = null;
42 try
43 {
44 MavenProject mavenProject = new MavenProject();
45 mavenProject.setVersion( "1.0" );
46 mavenProject.setGroupId( "org.apache" );
47 Properties executionProperties = new Properties();
48 executionProperties.setProperty( "foo", "bar" );
49 MavenFileFilter mavenFileFilter = (MavenFileFilter) lookup( MavenFileFilter.class.getName(), "default" );
50
51 File from = new File( getBasedir() + "/src/test/units-files/reflection-test.properties" );
52 File to = new File( getBasedir() + "/target/reflection-test.properties" );
53
54 if (to.exists())
55 {
56 to.delete();
57 }
58
59 mavenFileFilter.copyFile( from, to, true, mavenProject, null, false, null,
60 new StubMavenSession( executionProperties ) );
61
62 Properties reading = new Properties();
63 readFileInputStream = new FileInputStream( to );
64 reading.load( readFileInputStream );
65 assertEquals( "1.0", reading.get( "version" ) );
66 assertEquals( "org.apache", reading.get( "groupId" ) );
67 assertEquals( "bar", reading.get( "foo" ) );
68 assertEquals( "none filtered", reading.get( "none" ) );
69 }
70 finally
71 {
72 if ( readFileInputStream != null )
73 {
74 readFileInputStream.close();
75 }
76 }
77
78 }
79
80 public void testSimpleNonFiltering()
81 throws Exception
82 {
83 FileInputStream readFileInputStream = null;
84 try
85 {
86 MavenProject mavenProject = new MavenProject();
87 mavenProject.setVersion( "1.0" );
88 mavenProject.setGroupId( "org.apache" );
89 Properties executionProperties = new Properties();
90 executionProperties.setProperty( "foo", "bar" );
91 MavenFileFilter mavenFileFilter = (MavenFileFilter) lookup( MavenFileFilter.class.getName(), "default" );
92
93 File from = new File( getBasedir() + "/src/test/units-files/reflection-test.properties" );
94 File to = new File( getBasedir() + "/target/reflection-test.properties" );
95
96 if (to.exists())
97 {
98 to.delete();
99 }
100
101 mavenFileFilter.copyFile( from, to, false, mavenProject, null, false, null,
102 new StubMavenSession( executionProperties ) );
103
104 Properties reading = new Properties();
105 readFileInputStream = new FileInputStream( to );
106 reading.load( readFileInputStream );
107 assertEquals( "${pom.version}", reading.get( "version" ) );
108 assertEquals( "${pom.groupId}", reading.get( "groupId" ) );
109 assertEquals( "${foo}", reading.get( "foo" ) );
110 assertEquals( "none filtered", reading.get( "none" ) );
111 }
112 finally
113 {
114 if ( readFileInputStream != null )
115 {
116 readFileInputStream.close();
117 }
118 }
119
120 }
121
122 }