Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-8263

Osgi Mocks cannot handle r7 property names with $_$ in annotation config classes

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: Testing OSGi Mock 2.4.2
    • Fix Version/s: None
    • Component/s: Testing
    • Labels:
      None

      Description

      I try to unittest osgi components which use r7 property names containing the "$_$" style to embed the "-" character according to OSGI r7 (chapter 105.15.2, metatypes). I also use the annotation-style configuration approach.

      HealthCheckStatusEmail.java
      
      @Designate(ocd=HealthcheckService.Config)
      public class HealthCheckService, {
      
      @AttributeDefinnition(...)
      public @interface Config {
        @AttributeDefinition()
        String recipients_email$_$addresses;
      }
      
      @Activate
      protected void activate (Config conf) {
        String recipient = conf.recipients_email$_$addresses;
      }
      
      
      HealthCheckStatusEmailTest.java
      
         healthcheckService = new HealthCheckService();
      
         @Before
          public void setUp() throws Exception {
              configuration.put("recipients.email-addresses", "test@example.com");
        }
        @Test
        public void test () {
          context.registerInjectActivateService(healthcheckService, configuration);
          // test code
        }
      

      But debugging showed, that this value test@example.com was never written into the field recipient of the HealthCheckService component.

      I tracked it down into the OsgiMocks library, where in the shaded class "osgimock.org.apache.felix.scr.impl.inject.Annotations" the method toObject, where the the method "fixup" is called with the value recipients.email$_$addresses; it returns recipients.email.addresses, but I expect recipients.email.addresses.

      To me the problem seems to be that the shaded Felix SCR library does not support OSGI r7 here (and therefor not this specific mapping introduced in r7).

      The only workaround I see right now is to use a different signature for the activate() method to avoid this incorrect translation for these property names.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                joerghoh Jörg Hoh
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: