Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

AEM 6.3, wcm.io: service test not working using OSGi annotations

Avatar

Level 5

I am experiencing a test issue. My service tests work for my older services (Felix annotation based -> org.apache.felix.scr.annotations.Component) but when I try this for a newer service (OSGI annotation based -> org.osgi.service.component.annotations.Component), I get an error.

Service:

...
import org.osgi.service.component.annotations.Component;

@Component(service = TestService.class, immediate = true, property = {
  Constants.SERVICE_DESCRIPTION + "=" + "Test Service",
  Constants.SERVICE_VENDOR + "=" + BundleConstants.SERVICE_VENDOR
})
public class TestServiceImpl implements TestService {

@Override
public String getValue() {
  return "test-value-from-service";
  }
}

Sling Model:

@OSGiService
private TestService testService;

public String getValue(){
  return testService.getValue();
}

Register:

TestService testService = aemContext.registerInjectActivateService(new TestServiceImpl());

Error:

Caused by: org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR metadata found for class com.asadventure.core.service.TestServiceImpl

enter image description here

Am I missing something here?

12 Replies