Hi All,
We have a requirement to write the JUnit's, while writing I am encountering below @reference, how to mock this in AEMAACS for workflow?
@Reference
QueryBuilder queryBuilder; //null
@Reference
private DamPropertiesConfiguration damconfig; //null
@Reference
ResourceResolverFactory resourceResolverFactory; /null
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
{
try
{
ExampleWorkflowHelper exampleWorkflowHelper = new ExampleWorkflowHelper();
ResourceResolver resolver = workflowSession.adaptTo(ResourceResolver.class);
log.info("workflow started");
exampleWorkflowHelper.generateDamAssets(resolver, queryBuilder, damconfig);
}
}
above is the aem workflow code for that we need to write junits
and How to pass @Reference variable as a parameter in the below method
exampleWorkflowHelper.generateDamAssets(resolver, queryBuilder, damconfig);
Thanks & Regards
Solved! Go to Solution.
Views
Replies
Total Likes
@Vishal_Jain03 use @Mock instead of @reference
Make sure that you setup any objects / object attributes in the Setup method (this is the one with @BeforeEach annotation)
For instance, if you need the ResourceResolver from the ResoruceResolverFactory mock object, the inside the setup method, you should have something like this :
lenient().when(resourceResolverFactory.getServiceResourceResolver(Mockito.anyMap())).thenReturn(resourceResolver)
resourceResolver is a mock ResourceResolver object here that can in turn be mapped to a path using something similar as above.
Hope this helps.
@Vishal_Jain03 use @Mock instead of @reference
Make sure that you setup any objects / object attributes in the Setup method (this is the one with @BeforeEach annotation)
For instance, if you need the ResourceResolver from the ResoruceResolverFactory mock object, the inside the setup method, you should have something like this :
lenient().when(resourceResolverFactory.getServiceResourceResolver(Mockito.anyMap())).thenReturn(resourceResolver)
resourceResolver is a mock ResourceResolver object here that can in turn be mapped to a path using something similar as above.
Hope this helps.
Hi @Vishal_Jain03 ,
Please refer on writing junit test case for workflow https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-write-junit-for-wor...
@Vishal_Jain03Did you find the suggestions from users 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
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies