I am trying to write integration tests for my Eclipse Scout application.
My tests method looks like this:
AForm form = new AForm();
form.setPersonId(3L);
form.startNew();
form.doOk();
//assertions on the form.
My problem is that the code in AForm.ModifyHandler#execStore()
the ModifyHandler is not executed. To ensure this I have modified the implementation: I throw an IllegalStateException:
public class ModifyHandler extends AbstractFormHandler {
@Override
protected void execLoad() throws ProcessingException {
IAService service = SERVICES.getService(IAService.class);
AFormData formData = new AFormData();
exportFormData(formData);
formData = service.load(formData);
importFormData(formData);
setEnabledPermission(new UpdateAPermission());
}
@Override
protected void execStore() throws ProcessingException {
throw new IllegalStateException("Exception for Unit Test: execStore()");
// IAService service = SERVICES.getService(IAService.class);
// AFormData formData = new AFormData();
// exportFormData(formData);
// formData = service.store(formData);
}
}
Why is execStore()
not called?
You have a Form Lifecycle Problem.
Eclipse Scout executes execStore()
only if at least a value has changed in the form.
To be precise:
AbstractFormHandler#execLoad()
are considered as initial valuesAbstractFormHandler#execPostLoad()
are considered as modified values.When the user interacts with the form, he is after PostLoad
event.
To mark the form as modified you can use IForm#touch()
.
You can change your Unit Test to something like this:
AForm form = new AForm();
form.setPersonId(3L);
form.startNew();
Assert.assertEquals("isSaveNeeded [1]", false, form.isSaveNeeded());
form.touch(); // or form.getXyField().setValue(..);
Assert.assertEquals("isSaveNeeded [2]", true, form.isSaveNeeded());
form.doOk();
//assertions on the form.
The assertions "is save needed" are not necessary. They are only here to illustrate the case.
If IForm#isSaveNeeded()
returns true, your execStore()
implementation will be executed.