Skip to main content



      Home
Home » Eclipse Projects » Eclipse Scout » Waiting for a job in a unit test?
Waiting for a job in a unit test? [message #1446846] Fri, 17 October 2014 07:48 Go to next message
Eclipse UserFriend
In our project we use a Job to refresh the whole form during execChangedValue(). We have a Junit test with a Scout Context where the Server is mocked.

Since the introduction of the Job (to solve loop detection problems), we have the problem that the Unit no longer works. Here some code:
// install the mocked services with TestingUtility.registerServices(..)

// The process service defined the behavior for: load() and calculate()
// * loadFormData for OtherField contains LOADED_VALUE
// * calcFormData for OtherField contains CALCULATED_VALUE

when(service.load(any(MyFormData.class))).thenReturn(loadFormData);
when(service.calculate(any(MyFormData.class))).thenReturn(calcFormData);

Form f = new Form();
f.startNew();
assertEquals(LOADED_VALUE, f.getOtherField().getValue());

f.getMyField().setValue(NEW_VALUE); //<= this triggers a calculate job

// TODO: how to tell the test he should wait on the calculate_job?

assertEquals(CALCULATED_VALUE, f.getOtherField().getValue());

verify(service, times(1)).calculate(any(MyFormData.class));


The assertion for the calculated value is not working.
When I debug, I see that I have a job/threading problem.

Thank you in advance.

.
Re: Waiting for a job in a unit test? [message #1446884 is a reply to message #1446846] Fri, 17 October 2014 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Without having tested it, just as an idea: Have you tried to join the job family?

e.g. the following snippet if you are using ClientSyncJobs:

Job.getJobManager().join(ClientSyncJob.class, null);



regards
matthias
Re: Waiting for a job in a unit test? [message #1447378 is a reply to message #1446884] Sat, 18 October 2014 02:54 Go to previous message
Eclipse UserFriend
Thanks for your proposition.

My first tests show that it produces a dead-lock.

I have also tried to make another job family (CalculateClientSyncJob extends ClientSyncJob).
Previous Topic:How integrate image in a JasperReport
Next Topic:Mockito Spy and inner classes
Goto Forum:
  


Current Time: Fri Jul 04 15:13:18 EDT 2025

Powered by FUDForum. Page generated in 0.04489 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top