Java tutorial
/** * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ package org.openmrs.contrib.metadatarepository.service; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.openmrs.contrib.metadatarepository.util.ConvertUtil; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; @ContextConfiguration(locations = { "classpath:/applicationContext-resources.xml", "classpath:/applicationContext-dao.xml", "classpath:/applicationContext-service.xml", "classpath*:/**/applicationContext.xml" }) /** * Test classes can extend this manager based on a spring context. * This test class can be moved to the test tree. * * @author mraible */ public abstract class BaseManagerTestCase extends AbstractTransactionalJUnit4SpringContextTests { /** * A simple logger */ protected final Log log = LogFactory.getLog(getClass()); /** * The resourceBundle */ protected ResourceBundle rb; /** * Default constructor will set the ResourceBundle if needed. */ public BaseManagerTestCase() { // Since a ResourceBundle is not required for each class, just // do a simple check to see if one exists String className = this.getClass().getName(); try { rb = ResourceBundle.getBundle(className); } catch (MissingResourceException mre) { // log.warn("No resource bundle found for: " + className); } } /** * Utility method to populate an object with values from a properties file * * @param obj the model object to populate * @return Object populated object * @throws Exception if BeanUtils fails to copy properly */ protected Object populate(Object obj) throws Exception { // loop through all the beans methods and set its properties from // its .properties file Map map = ConvertUtil.convertBundleToMap(rb); BeanUtils.copyProperties(obj, map); return obj; } }