2

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.

dermoritz
  • 12,519
  • 25
  • 97
  • 185

2 Answers2

2

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";
  }
Souciance Eqdam Rashti
  • 3,143
  • 3
  • 15
  • 31
  • This isn't working. The injection of the fields and methods including those annotaded with @PropertyInject happens before the call of "useOverridePropertiesWithConfigAdmin". And as mentioned before the props Object given has always a size of 0 if the method gets called. – dermoritz Dec 22 '16 at 07:51
  • You are sure you are returning the correct persistent-id? Can you paste your test code and the code where you do the propertyinject. I just recently did something similar and it works for me. I can compare it to my test. – Souciance Eqdam Rashti Dec 22 '16 at 08:03
  • yes i am sure but the main problem is that the properties get injected before the call of the overridden method - so what ever i set there (correct or not) will be ignored. the property must be changed before camel injects them - i am not very familiar with camel life cycle. – dermoritz Dec 22 '16 at 08:30
  • I will edit my answer so you can see how it looks in my code. – Souciance Eqdam Rashti Dec 22 '16 at 08:32
  • thanks. the only difference i see is ``update-strategy="reload"``. If you debug your test, what is called first? useOverridePropertiesWithConfigAdmin or the RoutBuilder that injects the fields? – dermoritz Dec 22 '16 at 09:00
  • Unfortunately it is a bit cumbersome to debug that code right now, but I can take a look at it later. Did it work for you when you changed the update-strategy? – Souciance Eqdam Rashti Dec 22 '16 at 09:02
0

See the documentation: http://camel.apache.org/using-propertyplaceholder.html about the loadConfigAdminConfigurationFile and useOverridePropertiesWithConfigAdmin methods you can use from unit tests.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • this isn't working. Dictionary given with ``useOverridePropertiesWithConfigAdmin`` has a size of 0. And The value given in blueprint.xml is still used. - I want to overide/read the value given in blueprint.xml from within my test. – dermoritz Dec 21 '16 at 16:50