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 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       * load property test case can be adjusted by modifying the basic.properties and
59       * basic_validation properties
60       *
61       * @throws Exception
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       * load property test case can be adjusted by modifying the basic.properties and
74       * basic_validation properties
75       *
76       * @throws Exception
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       * load property test case can be adjusted by modifying the basic.properties and
89       * basic_validation properties
90       *
91       * @throws Exception
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      * load property test case can be adjusted by modifying the basic.properties and
105      * basic_validation properties
106      *
107      * @throws Exception
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      * load property test case can be adjusted by modifying the basic.properties and
121      * basic_validation properties
122      *
123      * @throws Exception
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 }