Get protected spring properties from Mule FunctionalTestCase

I need to access Spring property placeholder properties from a Mule FunctionalTestCase.

I use a protective-place-placeholder, which is a wrapper around the Spring property placeholder, so I cannot load properties manually in my test case.

Is there any way to get them from the context of the mule? Can I get decrypted values?

+3
source share
1 answer

You can do this, but you will need to create and add a helper bean property helper that uses the BeanFactory to find the property value. After that, you can get this bean from the Mule context and use it to retrieve the property value.

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

PropertyAccessor 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",
        };
}
0

All Articles