You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Jyrki Ruuskanen (JIRA)" <ji...@apache.org> on 2014/07/26 14:12:38 UTC

[jira] [Comment Edited] (FELIX-4584) Change retention to RUNTIME for Property and Properties annotations

    [ https://issues.apache.org/jira/browse/FELIX-4584?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14074737#comment-14074737 ] 

Jyrki Ruuskanen edited comment on FELIX-4584 at 7/26/14 12:11 PM:
------------------------------------------------------------------

Our components rely heavily on properties (PropertiesComponent of Apache Camel, to be exact). We want to use the exact same values set in the Property annotations in our unit tests.

With retention changed to runtime we can copy, as you suggested, Property annotation values from the class in an unit test or statically in the annotated class itself. Something like below (I don't have the real code at hand right now):

private static final Map<String, String> defaultProperties;
static {
  Map<String, String> props = new HashMap<>();
  ...felix.scr.annotations.Property[] properties = OurComponent.class.getDeclaredAnnotation(Properties.class).value();
  for (Property prop : properties) {
     props.put(prop.getName(), prop.getValue());
  }
  defaultProperties = Collections.unmodifiableMap(props);
}

Then we can test using this Map and be sure the values are in sync with the Property annotations.


was (Author: yuruki):
Our components rely heavily on properties (PropertiesComponent of Camel, to be exact). We want to use the exact same properties set in the Property annotations in our unit tests.

With retention changed to runtime we can copy, as you suggested, the values in Property annotations into a member in our component class statically. Something like below (I don't have the real code at hand right now):

private static final Map<String, String> defaultProperties;
static {
  Map<String, String> props = new HashMap<>();
  ...felix.scr.annotations.Property[] properties = OurComponent.class.getDeclaredAnnotation(Properties.class).value();
  for (Property prop : properties) {
     props.put(prop.getName(), prop.getValue());
  }
  defaultProperties = Collections.unmodifiableMap(props);
}

Then we can test using this Map and be sure it's in sync with the Property annotations.

> Change retention to RUNTIME for Property and Properties annotations
> -------------------------------------------------------------------
>
>                 Key: FELIX-4584
>                 URL: https://issues.apache.org/jira/browse/FELIX-4584
>             Project: Felix
>          Issue Type: Improvement
>          Components: SCR Tooling
>            Reporter: Jyrki Ruuskanen
>            Priority: Minor
>
> This change allows us to access Property annotation values in plain java unit tests. Without this our unit tests would have to run in an SCR-capable container.
> You may consider changing the retention for the whole lot (why not), but at least these two are necessary.
> https://github.com/apache/felix/pull/9



--
This message was sent by Atlassian JIRA
(v6.2#6252)