Coverage report

  %line %branch
org.apache.jetspeed.testhelpers.AbstractTestHelper
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.testhelpers;
 18  
 
 19  
 import java.io.File;
 20  
 import java.util.HashMap;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.commons.configuration.CompositeConfiguration;
 24  
 import org.apache.commons.configuration.Configuration;
 25  
 import org.apache.commons.configuration.ConfigurationException;
 26  
 import org.apache.commons.configuration.PropertiesConfiguration;
 27  
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
 28  
 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
 29  
 
 30  
 public abstract class AbstractTestHelper implements TestHelper
 31  
 {
 32  
     public static final String APP_CONTEXT = "AppContext";
 33  
 
 34  
     private final Map context;
 35  
 
 36  
     private static final CompositeConfiguration USER_PROPERTIES;
 37  
     static
 38  
     {
 39  
         try
 40  
         {
 41  0
             File userBuildFile = new File(System.getProperty("user.home"), "build.properties");
 42  0
             Configuration userBuildProps = loadConfiguration(userBuildFile);
 43  
 
 44  0
             File mavenBuildFile = new File("../../build.properties");
 45  0
             Configuration mavenBuildProps = loadConfiguration(mavenBuildFile);
 46  
 
 47  0
             File mavenProjectFile = new File("../../project.properties");
 48  0
             Configuration mavenProjectProps = loadConfiguration(mavenProjectFile);
 49  
 
 50  0
             USER_PROPERTIES = new CompositeConfiguration();
 51  0
             USER_PROPERTIES.addConfiguration(userBuildProps);
 52  0
             USER_PROPERTIES.addConfiguration(mavenBuildProps);
 53  0
             USER_PROPERTIES.addConfiguration(mavenProjectProps);
 54  
         }
 55  0
         catch (ConfigurationException e)
 56  
         {
 57  
 
 58  0
             throw new IllegalStateException("Unable to load ${USER_HOME}/build.properties");
 59  0
         }
 60  0
     }
 61  
 
 62  
     private static Configuration loadConfiguration(File propsFile) throws ConfigurationException
 63  
     {
 64  0
         if (propsFile.exists())
 65  
         {
 66  0
             return new PropertiesConfiguration(propsFile);
 67  
         }
 68  
         else
 69  
         {
 70  0
             return new PropertiesConfiguration();
 71  
         }
 72  
     }
 73  
 
 74  
     public AbstractTestHelper(Map context)
 75  0
     {
 76  0
         this.context = context;
 77  0
     }
 78  
     
 79  
     public AbstractTestHelper()
 80  0
     {
 81  0
         context = new HashMap();
 82  0
     }
 83  
 
 84  
     public Map getContext()
 85  
     {
 86  0
         return context;
 87  
     }
 88  
 
 89  
     public final String getUserProperty(String key)
 90  
     {
 91  
         // use system properties passed to test via the
 92  
         // maven.junit.sysproperties configuration from
 93  
         // maven build.properties and/or project.properties
 94  0
         String prop = System.getProperty(key);
 95  0
         if (prop == null)
 96  
         {
 97  0
             return USER_PROPERTIES.getString(key);
 98  
         }
 99  
         else
 100  
         {
 101  0
             return prop;
 102  
         }
 103  
     }
 104  
 
 105  
     protected final void addBeanFactory(ConfigurableBeanFactory bf)
 106  
     {
 107  0
         ConfigurableBeanFactory currentBf = (ConfigurableBeanFactory) context.get(APP_CONTEXT);
 108  0
         if (currentBf != null)
 109  
         {
 110  0
             bf.setParentBeanFactory(currentBf);
 111  0
             context.put(APP_CONTEXT, new DefaultListableBeanFactory(bf));
 112  
         }
 113  
         else
 114  
         {
 115  0
             context.put(APP_CONTEXT, bf);
 116  
         }
 117  0
     }
 118  
 
 119  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.