View Javadoc
1   package org.apache.maven.plugins.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.io.FileInputStream;
24  import java.io.IOException;
25  import java.io.InputStream;
26  import java.util.Enumeration;
27  import java.util.Properties;
28  
29  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
30  import org.codehaus.plexus.util.IOUtil;
31  
32  /**
33   * Base class for propertyutils test case
34   */
35  public abstract class AbstractPropertyUtilsTest
36      extends AbstractMojoTestCase
37  {
38      protected File propertyFile;
39  
40      protected File validationFile;
41  
42      protected Properties validationProp;
43  
44      protected abstract File getPropertyFile();
45  
46      protected abstract File getValidationFile();
47  
48      protected void setUp()
49          throws Exception
50      {
51          super.setUp();
52  
53          // load data
54          propertyFile = getPropertyFile();
55          assertNotNull( propertyFile );
56  
57          validationFile = getValidationFile();
58          assertNotNull( validationFile );
59  
60          loadValidationProperties( validationFile );
61      }
62  
63      protected boolean validateProperties( Properties prop )
64      {
65          boolean bRetVal = false;
66  
67          Enumeration<?> propKeys = prop.keys();
68          String key;
69  
70          while ( propKeys.hasMoreElements() )
71          {
72              key = (String) propKeys.nextElement();
73              bRetVal = prop.getProperty( key ).equals( validationProp.getProperty( key ) );
74              if ( !bRetVal )
75              {
76                  break;
77              }
78          }
79  
80          return bRetVal;
81      }
82  
83      /**
84       * load the property file for cross checking the
85       * values in the processed property file
86       *
87       * @param validationPropFile
88       */
89      private void loadValidationProperties( File validationPropFile )
90      {
91          validationProp = new Properties();
92          InputStream in = null;
93  
94          try
95          {
96              in = new FileInputStream( validationPropFile );
97              validationProp.load( in );
98              in.close();
99              in = null;
100         }
101         catch ( IOException ex )
102         {
103             // TODO: do error handling
104         }
105         finally
106         {
107             IOUtil.close( in );
108         }
109     }
110 }