2014-02-20 41 views
3

我需要從Mule FunctionalTestCase訪問Spring屬性佔位符屬性。從Mule FunctionalTestCase獲取安全的彈簧屬性

我使用的是secure屬性佔位符,它是spring屬性佔位符的包裝,因此無法在我的測試用例中手動加載屬性。

有沒有辦法讓他們從騾馬上下文?所以我可以得到解密值?

回答

0

它可以完成,但您將不得不創建並添加使用BeanFactory查找屬性值的properties accessor helper bean。在此之後,您可以從Mule上下文獲取該bean並使用它來檢索屬性值。

PropertiesAccessor propertiesAccessor = muleContext.getRegistry().get("propertiesAccessor"); 
Assert.assertEquals("expectedvalue", propertiesAccessor.getProperty("key")); 

如果你不希望有PropertiesAccessor豆在您的生產代碼,你可以把這個定義成一個單獨的XML文件。

<?xml version="1.0" encoding="UTF-8"?> 
<spring:beans xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
"> 
    <context:annotation-config /> 
    <spring:bean id="propertiesAccessor" class="PropertiesAccessor" />  
</spring:beans> 

然後用你的主騾子配置XML一起加載,在你的FunctionalTestCase

@Override 
protected String[] getConfigFiles() { 
     return new String[] { 
         "src/main/app/mule-config.xml", 
         "src/test/resources/propertiesAccessor.xml", 
     }; 
}