Created
June 19, 2018 03:06
-
-
Save ebongzzang/6aa4bbce5fc056db43099e9151f4cf02 to your computer and use it in GitHub Desktop.
DataJpaTest in spock
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
@ContextConfiguration | |
@DataJpaTest | |
class DbunitWithGenesisTest extends Specification { | |
private static Logger log = LoggerFactory.getLogger(DbunitWithGenesisTest.class) | |
def hi = 1L..10L | |
// testEntityManager는 persistence context 테스트 목적으로 사용된다. | |
// 즉, 실제 데이터베이스에 적용할수는 없다 | |
@Autowired | |
TestEntityManager entityManager | |
@Autowired | |
DataSource dataSource | |
@Autowired | |
SchoolRepository schoolRepository | |
@Autowired | |
StudentRepository studentRepository | |
@Shared | |
Sql sqlInstance | |
def setup() { | |
sqlInstance = new Sql(dataSource) | |
} | |
def "when saving child entity, saved parent entity too"() { | |
given: | |
School dummySchool = EnhancedRandom.random(School.class) | |
Student dummyStudent =EnhancedRandom.random(Student.class) | |
when: | |
entityManager.persist(dummyStudent) | |
then: | |
def hi = studentRepository.findAll() | |
def hi2 = schoolRepository.findAll() | |
"" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment