Hi I am having trouble with writing test cases when using java+springboot+temporal stack.
the test class & the workflowimpl class are attached below. if instead of UserModel Object i return a string value it works fine but if i return the userModel object or object of any kind it fails with null value.
It might be a dumb question or a silly mistake on my part but i have tried alot of approaches from my end. if someone can help me that would be great. the full project is here https://github.com/Ranjan-A/temporal-poc/tree/main/temporal-trial-2/temporal
public class UserWorkflowImplTest {
private TestWorkflowEnvironment testEnv;
private Worker worker;
private WorkflowClient client;
@Before
public void setUp(){
testEnv = TestWorkflowEnvironment.newInstance();
worker = testEnv.newWorker("123");
worker.registerWorkflowImplementationTypes(UserWorkflowImpl.class);
client = testEnv.getWorkflowClient();
}
@After
public void tearDown(){
testEnv.close();
}
@Test
public void testMockedflow(){
UserActivity userActivity =
Mockito.mock(UserActivity.class,Mockito.withSettings().withoutAnnotations());
UserModel userModel = new UserModel();
userModel.setId("Ashish");
Mockito.when(userActivity.userGreeting("Ashish")).thenReturn(userModel);
Mockito.when(userActivity.conveyGreeting(userModel)).thenReturn("Hello Ashish");
worker.registerActivitiesImplementations(userActivity);
testEnv.start();
UserWorkflow workflow = client.newWorkflowStub(
UserWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue("123").build()
);
String greeting = workflow.userGreeting("Ashish");
assertEquals("Hello Ashish",greeting);
}
}
@WorkflowImpl(taskQueues = "123")
public class UserWorkflowImpl implements UserWorkflow{
private ActivityOptions options =
ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(30))
.build();
private UserActivity activity = Workflow.newActivityStub(UserActivity.class,options);
@Override
public String userGreeting(String name) {
String greeting="";
//String greeting = activity.greetingActivity(name);
UserModel userModel = activity.userGreeting(name);
System.out.println(userModel.toString());
if(userModel.getId()!=null){
greeting=activity.conveyGreeting(userModel);
}
return greeting;
}
}