Issues
Cannot register service with ModelFactory reference in AemContext
Description
Details
Details
Assignee
Reporter

Components
Fix versions
Affects versions
Priority
Activity
Stefan SeifertMarch 4, 2019 at 5:46 PM
thanks, i could reproduce the problem. the source of the problem was different than described in this ticket, though - they really where multiple references present and osgi-mock did throw an exception because of this. this was wrong, and is fixed in SLING-8303 - in OSGi Mock 2.4.8 / AEM Mock 2.4.2

David GonzalezMarch 3, 2019 at 7:41 PM
@Stefan Seifert .. Sorry for the delay.
I pushed a failing test here: https://github.com/davidjgonzalez/asset-share-commons/blob/tests/action-helper/core/src/test/java/com/adobe/aem/commons/assetshare/components/actions/impl/ActionHelperImplTest.java
Thanks!
Stefan SeifertFebruary 19, 2019 at 11:43 AM
do you have a test project available to reproduce the problem?
alternatively, can you attach the output of mvn dependency:tree
of your project?

David GonzalezFebruary 18, 2019 at 5:23 PM
@Stefan Seifert,
I moved the `osgi-mock` and `aem-mock` dependencies to the top of my bundle project's dependencies to ensure those versions are used, but to no avail.
I don't see anything else that would override these dependencies..? (I had Sling's `sling-mock` but removed that). I am using the AEM 6.3.1 UberJar but I wouldn't imagine any of these should/would be in that?
Any thoughts on where this might be overridden?
I noticed when I move the `sling-mock` dependency above the UberJar,
`modelFactory.getModelFromWrappedRequest(...)` could not be resolved, i'm not sure if that is a clue.
Stefan SeifertFebruary 18, 2019 at 9:14 AM
the issue was resolved in the underlying osgi mock 2.4.4 - can you cross-check that you have not overridden the osgi mock dependency in your project and osgi mock 2.4.4 or higher is in use?
I'm trying to test one of my services, which uses OSGi annotation @Reference to inject org.apache.sling.models.factory.ModelFactory.
I'm using AemMocks 2.3.2 (also tested with 2.2.12) and get following error on attempt of service registration:
aemContext.registerInjectActivateService(new MyServiceImpl());
org.apache.sling.testing.mock.osgi.ReferenceViolationException: Multiple matches found for unary reference 'modelFactory' for class ../MyServiceImpl.class
Debugger says that there are 110 matching services of ModelFactory are registered, so it cannot pick any particular one.
It works fine with any other References we inject in our project.