Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
At https://markmail.org/message/bdf4ntvwwdl4hxtx mthl suggested:
In order to avoid repetitive code a nice first helper method would be
for example one for retrieving the default userLogin like what is done
in 'QuoteTests.groovy'// Retrieves a particular login record. GenericValue getUserLogin(String userLoginId) { GenericValue userLogin = EntityQuery.use(delegator) .from('UserLogin').where(userLoginId: userLoginId).queryOne() assert userLogin return userLogin }We could even add a default login user.
// Retrieves the default login record. GenericValue getUserLogin() { return getUserLogin('system'); }I guess we should add such method directly in the 'OFBizTestCase' class
to be able to reuse it in all test cases and avoid having to pass the
'delegator' and 'dispatcher' as method arguments.The creation of the service input map of your example would look like
this:void testSendOrderChangeNotification() { Map serviceCtx = [ orderId: 'TEST_DEMO10090', sendTo: 'test_email@example.com', userLogin: getUserLogin() ] Map serviceResult = dispatcher.runSync('sendOrderChangeNotification', serviceCtx) assert ServiceUtil.isSuccess(serviceResult) assert serviceResult.emailType.equals("PRDS_ODR_CHANGE") }In any case I think that finding the generic and reusable helper methods
can be done incrementally.
We can start with above Mathieu's proposition