I have a model where i am obtaining resource resolver from resourceresolverFactory . This model is a generic model referenced in multiple classes
In one such test case , i want resolver.map("path") to give me the resolved paths according to my configurations. Is there a way to register these configurations to the aem context so that when resolver.map() is called it maps url correctly
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi,
You could try to mock the resourceResolver object so you can return the expected value when resolver.map() is invoked. Try something like this:
@Mock
private ResourceResolverFactory resourceResolverFactory;
private ResourceResolver mockResolver;
private AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);
@BeforeEach
void setUp() throws LoginException {
MockitoAnnotations.openMocks(this);
context.registerService(ResourceResolverFactory.class, resourceResolverFactory);
mockResolver = context.resourceResolver().clone(null);
when(resourceResolverFactory.getServiceResourceResolver(any())).thenReturn(mockResolver);
}
Hope this helps
I mainly need help in adding mappings to my resource resolver factory / resolver for my context,
I have code where using resourceResolverFactory.getServiceResourceResolver(map);
link=resolver.map(link);
resolver is getting mocked but due to no mappings its not mapping my link , i need the link to be mapped for accurate test anyway to set this mapping to the context
@Zendarkke Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes