forked from grails/gorm-hibernate5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProxySpec.groovy
40 lines (33 loc) · 1013 Bytes
/
ProxySpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package example
import org.hibernate.Hibernate
import grails.gorm.transactions.Rollback
import grails.test.hibernate.HibernateSpec
/**
* Tests Proxy with hibernate-groovy-proxy
*/
class ProxySpec extends HibernateSpec {
@Rollback
void "Test Proxy"() {
when:
new Customer(1, "Bob").save(failOnError: true, flush: true)
hibernateDatastore.currentSession.clear()
def proxy
Customer.withNewSession {
proxy = Customer.load(1)
}
then:
//without ByteBuddyGroovyInterceptor this would normally cause the proxy to init
proxy
proxy.metaClass
proxy.getMetaClass()
!Hibernate.isInitialized(proxy)
//id calls
proxy.id == 1
proxy.getId() == 1
proxy["id"] == 1
!Hibernate.isInitialized(proxy)
// gorms trait implements in the class so no way to tell
// proxy.toString() == "Customer : 1 (proxy)"
// !Hibernate.isInitialized(proxy)
}
}