dermoritz
dermoritz

Reputation: 13001

How to access/set property via camel context programatically

I am using properties stored/defined in my blueprint.xml:

<cm:property-placeholder id="props.placeholder" persistent-id="props.blueprint">
    <cm:default-properties>
        ...
        <cm:property name="time.daysHistory" value="4" />
    </cm:default-properties>
</cm:property-placeholder>

I am using this properties via injection (@PropertyInject) or with this syntax{{time.daysHistory}}.

Is there a way to read and or set those properies from within my Bluprinttests? I tried context.getProperties() but this returns an empty map.

Upvotes: 2

Views: 3274

Answers (1)

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3193

Like Claus mentioned you need to use the useOverridePropertiesWithConfigAdmin method. However note, you need to return the same pid value as the one configured in your blueprint.

Your blueprint:

<cm:property-placeholder id="props.placeholder" persistent-id="props.blueprint">
    <cm:default-properties>
        ...
        <cm:property name="time.daysHistory" value="4" />
    </cm:default-properties>
</cm:property-placeholder>

In your test add:

@Override
protected String useOverridePropertiesWithConfigAdmin(Dictionary props) {
props.put("time.daysHistory", "1");
return "props.blueprint";
}

EDIT: Here is how I have done it:

In my route I have injected properties:

  @PropertyInject("DatasetConsumePath")
  private String datasetConsumePath;
  @PropertyInject("DatasetFileExtension")
  private String datasetFileExtension;

My blueprint:

  <cm:property-placeholder id="test" persistent-id="test" update-strategy="reload">
    <cm:default-properties>
      <cm:property name="DatasetConsumePath" value="test"/>
      <cm:property name="DatasetFileExtension" value="txt"/>
      <cm:property name="DatasetAggregateBatchSize" value="1000"/>
    </cm:default-properties>
  </cm:property-placeholder>

My test:

  @Override
  protected String useOverridePropertiesWithConfigAdmin(Dictionary props) {
    // add the properties we want to override
    props.put("DatasetConsumePath", "src/test/resources/test files/test/");

    // return the PID of the config-admin we are using in the blueprint xml file
    return "test";
  }

Upvotes: 2

Related Questions