Trying to get MOCK session object in workflow process class to satisfy below statement, but getting null value for jcrSession.
Session jcrSession = workflowSession.adaptTo(Session.class);
Code Snippet from Junit class
==================================
public final AemContext context = new AemContext();
@BeforeEach
public void setup() throws Exception {
workflowSessionMock = Mockito.mock(WorkflowSession.class);
workflowModelMock = Mockito.mock(WorkflowModel.class);
workItem = Mockito.mock(WorkItem.class);
wfData = Mockito.mock(WorkflowData.class);
wfMetaDataMap = Mockito.mock(MetaDataMap.class);
wfWorkflow = Mockito.mock(Workflow.class);
mockSession = Mockito.mock(Session.class);
}
@Test
void testExecute() throws WorkflowException {
MetaDataMap metaData = new SimpleMetaDataMap();
StringBuilder args = new StringBuilder();
args.append("effectiveDate=meta:absoluteTime");
Mockito.when(workItem.getWorkflow()).thenReturn(wfWorkflow);
Mockito.when(wfWorkflow.getMetaDataMap()).thenReturn(wfMetaDataMap);
context.registerAdapter(WorkflowSession.class, Session.class, mockSession);
Mockito.when(wfData.getPayloadType()).thenReturn("JCR_PATH");
Mockito.when(wfData.getPayload()).thenReturn("/content/dam/page");
Mockito.when(workItem.getWorkflowData()).thenReturn(wfData);
String sbString = args.toString();
String[] ary = sbString.split("=");
metaData.put("PROCESS_ARGS", ary);
process.execute(workItem, workflowSessionMock, metaData);
}
Getting all the required parameters(workItem, workflowSession, metaDataMap) and assigned values in workflow process class, but workflowSession.adaptTo is returning null Session object.
Any thoughts or suggestion please.
AEM SDK Version - aem-sdk-2020.12.4676.20201216T130744Z-201201
Archtype - 23
==
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @NitinL ,
you need to add below statement also in your unit test execute method before calling process.execute
when(workflowSessionMock.adaptTo(Session.class)).thenReturn(session);
and add a Session mock object in the unit class, like below
@Mock
private Session session;
Hi @NitinL ,
you need to add below statement also in your unit test execute method before calling process.execute
when(workflowSessionMock.adaptTo(Session.class)).thenReturn(session);
and add a Session mock object in the unit class, like below
@Mock
private Session session;
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies