Search code examples
apache-camelblueprint-osgi

CamelBlueprintTesting, why can't I override this propertyplaceholder?


I have a boolean flag propertyplaceholder that I'm trying to override in one of my unit tests but it's not working.

<cm:property-placeholder id="id" persistent-id="persistent-id>
  <cm:default-properties>
    <cm:property name="flag" value="true" />
  </cm:default-properties>
</cm:property-placeholder>

This flag gets use in a bean:

<bean id="myBean" class="com.myBean">
  <property name="flag" value="${flag}" />
</bean>

I'd like to override the property to be false when doing unit testing so I implemented the useOverridePropertiesWithPropertiesComponent() method:

@Override
protected Properties useOverridePropertiesWithPropertiesComponent() {
  Properties prop = new Properties();
  prop.put("errorQueue", "mock:error");
  prop.put("flag", false);

  return prop;

}

My errorQueue property is working fine and error messages are going to "mock:error" but the flag isn't overridden property. Does anyone know why this is?


Solution

  • You cannot do those overrides when its <bean>s

    eg the following ${flag} is 100% controlled by OSGi blueprint:

    <bean id="myBean" class="com.myBean"> <property name="flag" value="${flag}" /> </bean>

    And the useOverridePropertiesWithPropertiesComponent is for the Camel properties component for Camel property placeholders, eg the {{ }} syntax that Camel uses.

    http://camel.apache.org/using-propertyplaceholder.html