acs-aem-commons
acs-aem-commons copied to clipboard
ChildResourceFromRequest fails to inject field for Test Class
Required Information
- [ ] AEM Version, including Service Packs, Cumulative Fix Packs, etc: AEM 6.5 CS
- [ ] ACS AEM Commons Version: 6.0.10
- [ ] Reproducible on Latest? yes
Expected Behavior
When I'm adapting a request to a sling model, I should be able to use @ChildResourceFromRequest
annotation to inject from the request
Actual Behavior
When the test classes are executed they return a null model when adapting because the ModelAdapterFactory fails to inject the required object. The ModelAdapterFactory throws the following error:
Could not adapt from class com.adobe.acs.commons.util.OverridePathSlingRequestWrapper to class <Sling-Model-Class> in collection
Steps to Reproduce
Create a test class for a sling model that uses @ChildResourceFromRequest
annotation, add the following instruction to your setUp method:
context.registerInjectActivateService(new ChildResourceFromRequestInjector());
Execute your test classes and when adapting the request you'll get a null object as a result.