David
David

Reputation: 579

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?

Upvotes: 1

Views: 818

Answers (2)

Claus Ibsen
Claus Ibsen

Reputation: 55550

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

Upvotes: 2

Alessandro Da Rugna
Alessandro Da Rugna

Reputation: 4695

I am not sure, but I think that your value is not accepted. Javadoc for Properties states:

The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.

You are using a boolean, try with

prop.put("flag", "false");

In general key-values for property-placeholder are strings and converted to the appropriate type at runtime.

Upvotes: 0

Related Questions