Questions tagged [grails-services]

53 questions
3
votes
1 answer

How to run test for Grails service

When I run grails test-app MessageServiceSpec or grails test-app mypackage.MessageServiceSpec I always get an error No tests found for given includes: [MessageServiceSpec] What is wrong here? UPDATE: run command is grails test-app -unit…
Alex Shwarc
  • 822
  • 10
  • 20
3
votes
2 answers

Grails 2.3 integration test behaving badly - ServletContext must not null

I've seen a few posts about issues with Grails 2.3.x and integration testing, but nothing has helped my situation yet, so here goes: I want to test my Grails services against a real live database (Oracle) and so I wrote some integration tests in…
3
votes
1 answer

How to set formula in grails domain class?

I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', …
2
votes
3 answers

Grails 3 - get asset path in service

I need to get the path of a static resource located in assets/schemas/resource.json in a Grails 3 service. At the moment it is defined as private final String SCHEMA = 'grails-app/assets/schemas/resource.json', which is fine for development…
ilPittiz
  • 734
  • 1
  • 10
  • 23
2
votes
2 answers

Spock - mocking external service

I'm very new in spock framework testing and I didn't find any example where I can find needed information. Therefore, I think the best way is to show an example what I need to have. e.g. test class in spock: def "getData" (){ // this is test of…
user3506652
  • 43
  • 1
  • 2
  • 8
2
votes
0 answers

Using abstract Services in Grails

I am adding features to a Grails 2.2.3 application, and I have the following two Services: abstract class AbstractProcessService { def grailsApplication ConfigObject getConfig() { return grailsApplication.config.processes …
grantmcconnaughey
  • 10,130
  • 10
  • 37
  • 66
2
votes
2 answers

How to use g.formatNumber in grails Service class

I want to use g.formatNumber in service, I have tried a below method, Which i got online. This is not working, its giving me the error "Cannot invoke method formatNumber() on null object", The code is below import…
n92
  • 7,424
  • 27
  • 93
  • 129
2
votes
1 answer

Issue Injecting dataSource into Grails Service

I am running into an issue when trying the following in my Serivce: class SendingMailService { def dataSource // the Spring-Bean "dataSource" is auto-injected def sendXLSMail() { def db = new Sql(dataSource) //additional code such as query,…
Dennis
  • 401
  • 5
  • 17
2
votes
3 answers

Is it possible for a service to return a 404 response?

Is there an exception or something else that can be raised from a service (or other non-Controller method) that will interrupt the current response handling and return a 404 to the user? In the Django world, there is get_object_or_404 which raises a…
smacintyre
  • 43
  • 1
  • 4
1
vote
1 answer

Grails: Register job from external library

I need to separate a grails service into a dedicated lilbrary in order to use this service across many applications. This works fine for the service itself as I am able to register the service bean in the resources.groovy (see…
Erando
  • 811
  • 3
  • 13
  • 27
1
vote
2 answers

How to wrap all Grails service methods with a Groovy closure?

Grails 2.4.x here. I have a requirement that all the methods of all my Grails services, generated by grails create-service , be "wrapped"/intercepted with the following logic: try { executeTheMethod() } catch(MyAppException maExc) { …
smeeb
  • 27,777
  • 57
  • 250
  • 447
1
vote
1 answer

Include Service with Session Scope in Grails Controller?

Using Grails 2.4.5 I have the following service: class CartService { static scope = 'session' static proxy = true def items = [] def getItemCount() { items.size() } } I want to use this service in a controller:…
Michael
  • 32,527
  • 49
  • 210
  • 370
1
vote
1 answer

Inject bean map into Grails Service

A spring bean can be injected in a Grails application using resources.groovy. However, I would like to inject a map of beans. Key would be String, Value would an actual bean. Idea is I am trying to do a strategy style pattern where there would…
More Than Five
  • 9,959
  • 21
  • 77
  • 127
1
vote
1 answer

MissingPropertyException in grails

I have a problem when I try to show the view of one of my domains. I built a method to sum some quantities, but I have this error and I don't know how to fix it. I understand that the variable awards does not exist, but I have this value in my…
1
vote
1 answer

Grails create instance of inner class of service

In Grails, services are singletons by default. Can I keep it that way and still create an instance of an inner class of that service from a controller? //by default grails makes MyTestService a singlton class MyTestService{ public class…
user2782001
  • 3,380
  • 3
  • 22
  • 41
1
2 3 4