AEM 6.3, wcm.io: service test not working using OSGi annotations | Community
Skip to main content
Level 4
February 7, 2018

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

  • February 7, 2018
  • 2 replies
  • 4830 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

smacdonald2008
Level 10
February 7, 2018

Appears to be many issues here. First - to use the new DS Annotations - read this:

Official OSGi Declarative Services Annotations in AEM - Adobe Experience Manager | AEM/CQ | Apache Sling

For Sling Models  - you should use this annotation:

@Model(adaptables = Resource.class)

public class Multifield

NOT:

Sling Model:

@OSGiService 

private TestService testService; 

  public String getValue(){ 

  return testService.getValue(); 

See this artilce to build an AEM Component that uses Sling Models --

Adobe Experience Manager Help | Creating a HTL Repeating Data Set 6.3 Component that uses Sling Models

that will show you how to build a Repeating Data Set HTL component that successfully uses a Sling Model and renders the data in the component .

Hope this helps...

Level 4
February 7, 2018

But my TestService is no sling model. It is a simple service, I don't want to inject anything like they do in Multifield example.

smacdonald2008
Level 10
February 7, 2018

In your thread - it looks like you want to work with a Sling Model.

If all you want to do is create a service and get it running - i recommend going through this article - it uses Maven Archetype 11 and will use DS Annotations.

Take a look at some of the default Java files that use this annotation:

org.osgi.service.component.annotations.Component

Creating an Adobe Experience Manager 6.3 Project using Adobe Maven Archetype 11

This will get you familiar with DS Annotations and how to build AEM Projects that use them. ALso - read the article I linked above on DS ANNotations.

joerghoh
Adobe Employee
Adobe Employee
February 7, 2018

Hi,

the exception is descriptive:

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

And as you stated, you moved away from the SCR annotations to the offical OSGI annotations. That means, that it's quite unlikely that OSGI annotations provide SCR metadata :-) And therefor the mocking library cannot find them anymore.

First recommendation: Update your mocking libraries and use the latest one. Maybe the problem is solved there.

If that does not work, please report your problem on the Sling mailing list.

Jörg

Level 4
February 7, 2018

Seems like I am using the latest versions, I am not sure if wcm io's AemContext can handle a OSGI R6 annotated service.

joerghoh
Adobe Employee
Adobe Employee
February 7, 2018

In that case Stefan Seifert (or more general: the wcm.io people) are probably interested in knowing that (they probably already do, but it's always nice to know that others are using your software :-)).

Jörg