从Mule FunctionalTestCase获得安全的弹簧属性

时间:2014-02-20 16:05:52

标签: mule

我需要从Mule FunctionalTestCase访问Spring属性占位符属性。

我使用的是secure-property-placeholder,它是spring属性占位符的包装器,因此无法在我的测试用例中手动加载属性。

有没有办法从骡子环境中获取它们?我可以获得解密的值吗?

1 个答案:

答案 0 :(得分:0)

可以这样做但您必须创建并添加使用BeanFactory查找属性值的properties accessor helper bean。在此之后,您可以从Mule上下文中获取该bean,并使用它来检索属性值。

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

如果您不想在生产代码中使用PropertiesAccessor bean,可以将其定义放在单独的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>

然后将它与主要mule-config xml一起加载到FunctionalTestCase

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