Hi Mathieu
I forgot to mention that I put this method in GroovyUtil.java.
It was hastily done because doing so I rapidly thought that "Anyway it would not add
much, just a cover function"
It works with a complete/correct version:
public static Map testGroovy(Delegator delegator, LocalDispatcher dispatcher,
Map<String, Object> serviceCtx,
String serviceName) throws GenericEntityException,
GenericServiceException {
GenericValue userLogin = EntityQuery.use(delegator)
.from("UserLogin")
.where("userLoginId", "system")
.cache()
.queryOne();
serviceCtx.put("userLogin", userLogin);
return dispatcher.runSync(serviceName, serviceCtx);
}
I still wonder if it of much use, ie compare:
void testSendOrderChangeNotification() {
Map serviceCtx = [
orderId: 'TEST_DEMO10090',
sendTo: 'test_em...@example.com',
]
Map serviceResult = GroovyUtil.testGroovy(delegator, dispatcher,
serviceCtx, 'sendOrderChangeNotification');
assert ServiceUtil.isSuccess(serviceResult)
assert serviceResult.emailType.equals("PRDS_ODR_CHANGE")
}
with
void testSendOrderChangeNotification() {
Map serviceCtx = [
orderId: 'TEST_DEMO10090',
sendTo: 'test_em...@example.com',
userLogin:
EntityQuery.use(delegator).from('UserLogin').where('userLoginId',
'system').cache().queryOne()
]
Map serviceResult = dispatcher.runSync('sendOrderChangeNotification',
serviceCtx)
assert ServiceUtil.isSuccess(serviceResult)
assert serviceResult.emailType.equals("PRDS_ODR_CHANGE")
}
It's shorter and can be used for most Groovy tests. But you have to pass the delegator, dispatcher and serviceCtx which are else transparent. Not sure
it's of better use.
What do you think?
Jacques
Le 07/10/2019 à 13:49, Mathieu Lirzin a écrit :
Hello Jacques,
Jacques Le Roux <jacques.le.r...@les7arts.com> writes:
I had a look at this idea but I finally gave up. I thought about creating
public static Map testGroovy(Map<String, String> paramNames, String
serviceName) {
userLogin =
EntityQuery.use(delegator).from('UserLogin').where('userLoginId',
'system').cache().queryOne()
Map serviceCtx = paramNames.put("userLogin",
EntityQuery.use(delegator).from('UserLogin').where('userLoginId',
'system').cache().queryOne())
Map result = dispatcher.runSync(serviceName, serviceCtx)
}
And only pass params and service name, but EntityQuery is not yet available in
base component when compiling.
What do you mean by “EntityQuery is not yet available in base component
when compiling”?
Can you provide a patch and the command you run to get to this failing
scenario?
Anyway it would add much, just a cover function
Le 03/10/2019 à 14:29, Jacques Le Roux a écrit :
BTW looking at OrderTests.groovy it seems we can refactor Groovy tests, a lot
of is common...
--
Jacques Le Roux
400E Chemin de la Mouline
34560 Poussan
04 67 51 19 38
06 11 79 50 28