


It's still a problem. I am using the latest AEM Maven Archetype to customize the Teaser component, but unable to pass my tests because of the delegation pattern. I scaveraged through the net and have already reviewed all the possible answers like:
@arunpatidar and other folks, can you please help me out by giving me a working version of a Delegation pattern?
Here's a very simple sling model component that needs JUNIT5. I am also on the latest AEM 6.5 version + Latest AEM Maven Archetype version
@Model(adaptables = SlingHttpServletRequest.class, resourceType = CustomTeaser.RESOURCE_TYPE,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class CustomTeaser implements com.adobe.cq.wcm.core.components.models.Teaser {
public static final String RESOURCE_TYPE = "mycomp/components/customteaser";
@Self
@Via(type = ResourceSuperType.class)
private com.adobe.cq.wcm.core.components.models.Teaser teaser;
@Override
public String getTitle() {
return teaser.getTitle();
}
}
Whenever I am using AEMContext or Mocks, while in debug mode, teaser is ALWAYS NULL.
Views
Replies
Sign in to like this content
Total Likes
Hello, what is the CustomTeaserTest.json can you please share it?
I appreciate it, but this does not work...
Hello @2490242973 ,
Please follow my article. I gave two examples for considering different cases. (Breadcrumb & Language Navigation).
Hope this will help you and your problem will be solved.
https://sadyrifat.medium.com/aem-unit-test-case-for-sling-delegation-pattern-1f011b947fb3
The main problem of the delegation pattern you just mention is null. This is solved.