How do you get sessionFactory in a Grails Geb / Spock test case?

It seems to me that I need to clear the sleep mode session in the GebSpec test, and therefore I want to get sessionFactory.

It seems like it should be introduced, but when I do something like this: -

class MySpec extends GebSpec {
def sessionFactory
...
def "test session"(){
....do some setup
then: 
  assert sessionFactory != null
}

it does not work if sessionFactory is null.

+3
source share
1 answer

A short answer to my question: why are you doing this, is a functional test, and it can be removed from JVM applications.

, , , -. , , Remote-Control Grails (https://github.com/alkemist/grails-remote-control), . ,

 assert remote {
  MyDomainOb.findByName('fred') != null
 }

, , , . .

, - , , - , . , hibernate , JVM? : -

Session currentSession

    def setup() {
        ApplicationContext context = (ApplicationContext) ServletContextHolder.getServletContext().getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT);
        SessionFactory sf = context.getBean('sessionFactory')
        currentSession = sf.getCurrentSession()
    }

GebSpec, currentSession.clear() currentSession.flush()

, currentsession.clear() .

. , , remote.

+5

All Articles