it should work quote out-of-the-box with bnd-maven-plugin integrated into the 
maven build, with an execution for the bnd-process goal. [1] shows an rather 
full-featured example, but you do not need all this for simple use cases.

some IDEs may have problems generating the OSGi metadata during the build 
rightaway, test it first on the command line. IntelliJ IDEA and Eclipse should 
basically work fine.

stefan

[1] 
https://github.com/wcm-io/wcm-io-tooling/blob/23b28c1795a0dba9f5e51c429eecea102ae8e289/maven/aem-global-parent/pom.xml#L246-L306

>-----Original Message-----
>From: Cris Rockwell <cmroc...@umich.edu>
>Sent: Thursday, February 25, 2021 12:18 AM
>To: dev@sling.apache.org
>Subject: No OSGi SCR metadata in Unit Tests
>
>Hi, I have a problem getting a resource resolver factory working in my unit
>tests. The error looks like this
>
>org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR
>metadata found for class
>org.apache.sling.api.resource.ResourceResolverFactory
>
>My code looks like this
>    @Test
>    public void test_authn_request(){
>        BundleContext bundleContext = MockOsgi.newBundleContext();
>        ResourceResolverFactory mockFactory =
>Mockito.mock(ResourceResolverFactory.class);
>        MockOsgi.injectServices(mockFactory, bundleContext); //fails
>
>
>...
>    }
>https://github.com/apache/sling-whiteboard/blob/SLING-9397/improve-test-
>coverage/saml-
>handler/src/test/java/org/apache/sling/auth/saml2/impl/OsgiSamlTest.java#L1
>13 <https://github.com/apache/sling-whiteboard/blob/SLING-9397/improve-
>test-coverage/saml-
>handler/src/test/java/org/apache/sling/auth/saml2/impl/OsgiSamlTest.java#L1
>13>
>
>
>It’s a similar issue mentioned in
>https://issues.apache.org/jira/browse/SLING-7182
>The comment in SLING-7182 suggests the maven-bundle-plugin configs
>
>http://felix.apache.org/documentation/faqs/apache-felix-bundle-plugin-
>faq.html#use-scr-metadata-generated-by-bnd-in-unit-tests
>
>My project uses bnd-maven-plugin (not maven-bundle-plugin), so I’m asking
>if anyone has examples of bnd.bnd or pom.xml examples that show how to
>configure that for bnd-maven-plugin. Or perhaps other suggestions that will
>help clear this error...
>
>Thank you!
>Cris

Reply via email to