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.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 void tearDown()
64      {
65  
66      }
67  
68      protected boolean validateProperties( Properties prop )
69      {
70          boolean bRetVal = false;
71  
72          Enumeration<?> propKeys = prop.keys();
73          String key;
74  
75          while ( propKeys.hasMoreElements() )
76          {
77              key = (String) propKeys.nextElement();
78              bRetVal = prop.getProperty( key ).equals( validationProp.getProperty( key ) );
79              if ( !bRetVal )
80              {
81                  break;
82              }
83          }
84  
85          return bRetVal;
86      }
87  
88      /**
89       * load the property file for cross checking the
90       * values in the processed property file
91       *
92       * @param validationPropFile
93       */
94      private void loadValidationProperties( File validationPropFile )
95      {
96          validationProp = new Properties();
97          InputStream in = null;
98  
99          try
100         {
101             in = new FileInputStream( validationPropFile );
102             validationProp.load( in );
103         }
104         catch ( IOException ex )
105         {
106             // TODO: do error handling
107         }
108         finally
109         {
110             IOUtil.close( in );
111         }
112     }
113 }