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.Properties;
24
25 public class BasicPropertyUtilsTest
26 extends AbstractPropertyUtilsTest
27 {
28 final static protected String validationFileName =
29 "/target/test-classes/unit/propertiesutils-test/basic_validation.properties";
30
31 final static protected String propFileName = "/target/test-classes/unit/propertiesutils-test/basic.properties";
32
33 protected File getPropertyFile()
34 {
35 File propFile = new File( getBasedir(), propFileName );
36
37 if ( !propFile.exists() )
38 {
39 propFile = null;
40 }
41
42 return propFile;
43 }
44
45 protected File getValidationFile()
46 {
47 File validationFile = new File( getBasedir(), validationFileName );
48
49 if ( !validationFile.exists() )
50 {
51 validationFile = null;
52 }
53
54 return validationFile;
55 }
56
57
58
59
60
61
62
63 public void testBasicLoadProperty_FF()
64 throws Exception
65 {
66 Properties prop = PropertyUtils.loadPropertyFile( propertyFile, false, false );
67
68 assertNotNull( prop );
69 assertTrue( validateProperties( prop ) );
70 }
71
72
73
74
75
76
77
78 public void testBasicLoadProperty_TF()
79 throws Exception
80 {
81 Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, false );
82
83 assertNotNull( prop );
84 assertTrue( validateProperties( prop ) );
85 }
86
87
88
89
90
91
92
93 public void testBasicLoadProperty_TT()
94 throws Exception
95 {
96 Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, true );
97
98 validationProp.putAll( System.getProperties() );
99 assertNotNull( prop );
100 assertTrue( validateProperties( prop ) );
101 }
102
103
104
105
106
107
108
109 public void testNonExistentProperty()
110 throws Exception
111 {
112 Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, true );
113
114 validationProp.putAll( System.getProperties() );
115 assertNotNull( prop );
116 assertNull( prop.getProperty( "does_not_exist" ) );
117 }
118
119
120
121
122
123
124
125 public void testException()
126 throws Exception
127 {
128 boolean failed = false;
129
130 try
131 {
132 Properties prop = PropertyUtils.loadPropertyFile( new File( "NON_EXISTENT_FILE" ), true, true );
133 }
134 catch ( Exception ex )
135 {
136 failed = true;
137 }
138
139 assertTrue( failed );
140 }
141 }