11package org.javaee7.jpa.extended.pc
2-
32import org.jboss.arquillian.container.test.api.Deployment
43import org.jboss.arquillian.spock.ArquillianSputnik
54import org.jboss.shrinkwrap.api.ShrinkWrap
65import org.jboss.shrinkwrap.api.spec.WebArchive
76import org.junit.runner.RunWith
87import spock.lang.Specification
98
10- import javax.inject.Inject
9+ import javax.ejb.EJB
1110import javax.persistence.EntityManager
1211import javax.persistence.PersistenceContext
13-
1412/**
1513 * @author Kuba Marchwicki
1614 */
@@ -20,8 +18,8 @@ class ExtendedPersistenceContextSpecification extends Specification {
2018 @PersistenceContext
2119 EntityManager em;
2220
23- @Inject
24- BigBangTheoryService service ;
21+ @EJB
22+ CharactersBean bean ;
2523
2624 @Deployment
2725 def static WebArchive deploy () {
@@ -30,12 +28,19 @@ class ExtendedPersistenceContextSpecification extends Specification {
3028 .addAsResource(" META-INF/persistence.xml" )
3129 .addAsResource(" META-INF/create.sql" )
3230 .addAsResource(" META-INF/drop.sql" )
33- .addAsResource(" META-INF/load.sql" );
31+ .addAsResource(" META-INF/load.sql" )
3432 }
3533
3634 def setup () {
37- service. addWilWheaton();
38- service. updateRaj();
35+ Character wil = new Character (8 , " Wil Wheaton" )
36+ bean. save(wil)
37+
38+ for (Character c : bean. get()) {
39+ if (" Raj" . equals(c. getName())) {
40+ c. setName(" Rajesh Ramayan" )
41+ bean. save(c)
42+ }
43+ }
3944 }
4045
4146 def " should not persist changes without transaction flush" () {
@@ -46,7 +51,7 @@ class ExtendedPersistenceContextSpecification extends Specification {
4651
4752 def " should update characters after transaction flush" () {
4853 when :
49- service . proceed();
54+ bean . commitChanges()
5055
5156 then :
5257 8 == em. createNamedQuery(Character . FIND_ALL , Character . class). getResultList(). size();
0 commit comments