Created
August 23, 2011 14:28
-
-
Save krimple/1165274 to your computer and use it in GitHub Desktop.
A Spock integration test against a Roo entity and the persistence context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.test.context.ContextConfiguration | |
import org.test.spock.model.Course | |
import javax.persistence.PersistenceContext | |
import javax.persistence.EntityManager | |
import org.junit.runner.RunWith | |
import org.spockframework.runtime.SpockRuntime | |
import org.springframework.beans.factory.annotation.Autowired | |
import org.springframework.context.ApplicationContext | |
import org.springframework.test.annotation.Rollback | |
import org.springframework.transaction.annotation.Transactional | |
@ContextConfiguration("classpath:/META-INF/spring/applicationContext.xml") | |
class CourseSpockTest extends spock.lang.Specification { | |
@PersistenceContext | |
private EntityManager em; | |
@Autowired | |
ApplicationContext context; | |
def "should be able to persist" () { | |
given: | |
Course course = new Course() | |
when: | |
expect: | |
assert context != null | |
assert em != null | |
assert course.entityManager() != null | |
} | |
@Transactional | |
@Rollback | |
def "trial persist" () { | |
given: | |
Course course = new Course(); | |
when: | |
course.setName("Big Course") | |
course.setNumDays(5) | |
course.persist() | |
then: | |
course.getId() != null | |
course.entityManager().clear() | |
Course c2 = Course.findCourse(course.getId()) | |
c2.getName().equals(course.getName()) | |
c2.getNumDays() == course.getNumDays() | |
println course | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome. I have this working at this point, and am working on an add-on that will enable this for Roo 1.2 (and perhaps 1.1).