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      protected static final String validationFileName =
28              "/target/test-classes/unit/propertiesutils-test/basic_validation.properties";
29  
30      protected static final String propFileName = "/target/test-classes/unit/propertiesutils-test/basic.properties";
31  
32      protected File getPropertyFile() {
33          File propFile = new File(getBasedir(), propFileName);
34  
35          if (!propFile.exists()) {
36              propFile = null;
37          }
38  
39          return propFile;
40      }
41  
42      protected File getValidationFile() {
43          File validationFile = new File(getBasedir(), validationFileName);
44  
45          if (!validationFile.exists()) {
46              validationFile = null;
47          }
48  
49          return validationFile;
50      }
51  
52      /**
53       * load property test case can be adjusted by modifying the basic.properties and basic_validation properties
54       *
55       * @throws Exception
56       */
57      public void testBasicLoadProperty_FF() throws Exception {
58          Properties prop = PropertyUtils.loadPropertyFile(propertyFile, false, false);
59  
60          assertNotNull(prop);
61          assertTrue(validateProperties(prop));
62      }
63  
64      /**
65       * load property test case can be adjusted by modifying the basic.properties and basic_validation properties
66       *
67       * @throws Exception
68       */
69      public void testBasicLoadProperty_TF() throws Exception {
70          Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, false);
71  
72          assertNotNull(prop);
73          assertTrue(validateProperties(prop));
74      }
75  
76      /**
77       * load property test case can be adjusted by modifying the basic.properties and basic_validation properties
78       *
79       * @throws Exception
80       */
81      public void testBasicLoadProperty_TT() throws Exception {
82          Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, true);
83  
84          validationProp.putAll(System.getProperties());
85          assertNotNull(prop);
86          assertTrue(validateProperties(prop));
87      }
88  
89      /**
90       * load property test case can be adjusted by modifying the basic.properties and basic_validation properties
91       *
92       * @throws Exception
93       */
94      public void testNonExistentProperty() throws Exception {
95          Properties prop = PropertyUtils.loadPropertyFile(propertyFile, true, true);
96  
97          validationProp.putAll(System.getProperties());
98          assertNotNull(prop);
99          assertNull(prop.getProperty("does_not_exist"));
100     }
101 }