org.test4j.tools.commons
类 ConfigHelper

java.lang.Object
  继承者 org.test4j.tools.commons.ConfigHelper
所有已实现的接口:
IPropItem

public class ConfigHelper
extends Object
implements IPropItem

test4j配置文件工具类

作者:
darui.wudr

字段摘要
static String PROPKEY_DATABASE_DIALECT
          Property key of the SQL dialect of the underlying DBMS implementation
 
从接口 org.test4j.module.core.utility.IPropItem 继承的字段
CONNECT_ONLY_TESTDB, dbexport_auto, DBMAINTAINER_DISABLECONSTRAINTS, LOG4J_XML_FILE, PROPKEY_DATABASE_TYPE, PROPKEY_DATASOURCE_DRIVERCLASSNAME, PROPKEY_DATASOURCE_PASSWORD, PROPKEY_DATASOURCE_SCHEMAS, PROPKEY_DATASOURCE_URL, PROPKEY_DATASOURCE_USERNAME, PROPKEY_MODULES, SPRING_APPLICATION_CONTEXT_FACTORY_CLASS_NAME, SPRING_DATASOURCE_NAME, TRANSACTIONAL_MODE_DEFAULT
 
构造方法摘要
ConfigHelper()
           
 
方法摘要
static boolean autoExport()
           
static String databaseDriver()
          默认数据库驱动class
static String databasePassword()
           
static String databaseType()
          默认的数据库类型
static String databaseUrl()
          默认数据库连接url
static String databaseUserName()
           
static String dbfitDir()
          dbfit测试结果文件输出目录
static void disableDbMaintain()
           
static boolean doesDisableConstraints()
           
static boolean doesOnlyTestDatabase()
          除非显示的声明了database.istest=false,否则test4j认为只能连接测试库
static boolean getBoolean(String key)
           
static boolean getBoolean(String key, boolean defaultValue)
           
static Properties getConfiguration()
          Returns all properties that are used to configure test4j.
static String getConfiguredClassName(Class type, String... implementationDiscriminatorValues)
          Retrieves the class name of the concrete instance of the class with the given type as configured by the given Configuration.
static
<T> T
getInstance(String clazNameProperty)
          Gets an instance of the type specified by the property with the given name.
static
<T> T
getInstanceOf(Class<? extends T> type, String... implementationDiscriminatorValues)
          Retrieves the concrete instance of the class with the given type as configured by the given Configuration.
static int getInteger(String key, int defaultValue)
           
static String getString(Properties properties, String key)
          先从properties中获取key的属性值,如果找不到再从test4j配置中查找

Gets the string value for the property with the given name.
static String getString(Properties properties, String key, String defaultValue)
          Gets the string value for the property with the given name.
static String getString(String key)
           
static String getString(String key, String defaultValue)
          获取test4j配置项
static List<String> getStringList(String propertyName)
          Gets the list of comma separated string values for the property with the given name.
static List<String> getStringList(String propertyName, boolean required)
          Gets the list of comma separated string values for the property with the given name.
static boolean hasProperty(String key)
          Checks whether the property with the given name exists in the test4j or in the given properties.
static boolean isScript()
           
static boolean isSpringDataSourceName(String beanName)
          判断是否是spring的data source bean name

beanName.equals("spring.datasource.name")是为了兼容老版本中属性的定义
static int logLevel()
          返回log级别
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

PROPKEY_DATABASE_DIALECT

public static final String PROPKEY_DATABASE_DIALECT
Property key of the SQL dialect of the underlying DBMS implementation

另请参见:
常量字段值
构造方法详细信息

ConfigHelper

public ConfigHelper()
方法详细信息

getConfiguration

public static Properties getConfiguration()
Returns all properties that are used to configure test4j.

返回:
a Properties object

logLevel

public static int logLevel()
返回log级别

返回:

getString

public static String getString(String key)

getString

public static String getString(String key,
                               String defaultValue)
获取test4j配置项

参数:
key -
defaultValue - 默认值
返回:

getString

public static String getString(Properties properties,
                               String key)
先从properties中获取key的属性值,如果找不到再从test4j配置中查找

Gets the string value for the property with the given name.
If no such property is found or the value is empty, then to find in test4j configuration.
If the final value is empty or null, an exception will be raised.

参数:
properties -
key -
返回:

getString

public static String getString(Properties properties,
                               String key,
                               String defaultValue)
Gets the string value for the property with the given name. If no such property is found or the value is empty, the given default value is returned.

参数:
propertyName - The name, not null
defaultValue - The default value
properties - The properties, not null
返回:
The trimmed string value, not null

getStringList

public static List<String> getStringList(String propertyName)
Gets the list of comma separated string values for the property with the given name. If no such property is found or the value is empty, an empty list is returned. Empty elements (",,") will not be added. A space (", ,") is not empty, a "" will be added.

参数:
propertyName - The name, not null
返回:
The trimmed string list, empty if none found

getStringList

public static List<String> getStringList(String propertyName,
                                         boolean required)
Gets the list of comma separated string values for the property with the given name. If no such property is found or the value is empty, an empty list is returned if not required, else an exception is raised. Empty elements (",,") will not be added. A space (", ,") is not empty, a "" will be added.

参数:
propertyName - The name, not null
required - If true an exception will be raised when the property is not found or empty
返回:
The trimmed string list, empty or exception if none found

getBoolean

public static boolean getBoolean(String key)

getBoolean

public static boolean getBoolean(String key,
                                 boolean defaultValue)

getInteger

public static int getInteger(String key,
                             int defaultValue)

hasProperty

public static boolean hasProperty(String key)
Checks whether the property with the given name exists in the test4j or in the given properties.

参数:
key - The property name, not null
返回:
True if the property exitsts

getInstance

public static <T> T getInstance(String clazNameProperty)
Gets an instance of the type specified by the property with the given name. If no such property is found, the value is empty or the instance cannot be created, an exception will be raised.

参数:
clazNameProperty - the property of class name, not null.
返回:
The instance value, not null

getInstanceOf

public static <T> T getInstanceOf(Class<? extends T> type,
                                  String... implementationDiscriminatorValues)
Retrieves the concrete instance of the class with the given type as configured by the given Configuration. Tries to retrieve a specific implementation first (propery key = fully qualified name of the interface type + '.impl.className.' + implementationDiscriminatorValue). If this key does not exist, the generally configured instance is retrieved (same property key without the implementationDiscriminatorValue).

参数:
type - The type of the instance
implementationDiscriminatorValues - The values that define which specific implementation class should be used. This is typically an environment specific property, like the DBMS that is used.
返回:
The configured instance

databaseDriver

public static String databaseDriver()
默认数据库驱动class

返回:

databaseUrl

public static String databaseUrl()
默认数据库连接url

返回:

databaseUserName

public static String databaseUserName()

databasePassword

public static String databasePassword()

doesDisableConstraints

public static boolean doesDisableConstraints()

doesOnlyTestDatabase

public static boolean doesOnlyTestDatabase()
除非显示的声明了database.istest=false,否则test4j认为只能连接测试库

返回:

isSpringDataSourceName

public static boolean isSpringDataSourceName(String beanName)
判断是否是spring的data source bean name

beanName.equals("spring.datasource.name")是为了兼容老版本中属性的定义

参数:
beanName -
返回:

autoExport

public static boolean autoExport()

isScript

public static boolean isScript()

databaseType

public static String databaseType()
默认的数据库类型

返回:

dbfitDir

public static String dbfitDir()
dbfit测试结果文件输出目录

返回:

disableDbMaintain

public static void disableDbMaintain()

getConfiguredClassName

public static String getConfiguredClassName(Class type,
                                            String... implementationDiscriminatorValues)
Retrieves the class name of the concrete instance of the class with the given type as configured by the given Configuration. Tries to retrieve a specific implementation first (propery key = fully qualified name of the interface type + '.impl.className.' + implementationDiscriminatorValue). If this key does not exist, the generally configured instance is retrieved (same property key without the implementationDiscriminatorValue).

参数:
type - The type of the instance
implementationDiscriminatorValues - The values that define which specific implementation class should be used. This is typically an environment specific property, like the DBMS that is used.
返回:
The configured class name


Copyright © 2013. All rights reserved.