View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.resources;
20  
21  import java.io.File;
22  import java.util.Properties;
23  
24  import org.apache.maven.shared.filtering.PropertyUtils;
25  
26  public class BasicPropertyUtilsTest extends AbstractPropertyUtilsTest {
27  
28      protected File getPropertyFile() {
29          File propFile = new File(getBasedir(), "/target/test-classes/unit/propertiesutils-test/basic.properties");
30  
31          if (!propFile.exists()) {
32              propFile = null;
33          }
34  
35          return propFile;
36      }
37  
38      protected File getValidationFile() {
39          File validationFile =
40                  new File(getBasedir(), "/target/test-classes/unit/propertiesutils-test/basic_validation.properties");
41  
42          if (!validationFile.exists()) {
43              validationFile = null;
44          }
45  
46          return validationFile;
47      }
48  
49      /**
50       * load property test case can be adjusted by modifying the basic.properties and basic_validation properties
51       *
52       * @throws Exception
53       */
54      public void testBasicLoadPropertyFF() throws Exception {
55          Properties prop = PropertyUtils.loadPropertyFile(propertyFile, false, false);
56  
57          assertNotNull(prop);
58          assertTrue(validateProperties(prop));
59      }
60  
61      /**
62       * load property test case can be adjusted by modifying the basic.properties and basic_validation properties
63       *
64       * @throws Exception
65       */
66      public void testBasicLoadPropertyTF() throws Exception {
67          Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, false);
68  
69          assertNotNull(prop);
70          assertTrue(validateProperties(prop));
71      }
72  
73      /**
74       * load property test case can be adjusted by modifying the basic.properties and basic_validation properties
75       *
76       * @throws Exception
77       */
78      public void testBasicLoadPropertyTT() throws Exception {
79          Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, true);
80  
81          validationProp.putAll(System.getProperties());
82          assertNotNull(prop);
83          assertTrue(validateProperties(prop));
84      }
85  
86      /**
87       * load property test case can be adjusted by modifying the basic.properties and basic_validation properties
88       *
89       * @throws Exception
90       */
91      public void testNonExistentProperty() throws Exception {
92          Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, true);
93  
94          validationProp.putAll(System.getProperties());
95          assertNotNull(prop);
96          assertNull(prop.getProperty("does_not_exist"));
97      }
98  }