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