View Javadoc

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