|
| 1 | +package com.example.kotlin |
| 2 | + |
| 3 | +import com.example.kotlin.onetoone.domain.Market |
| 4 | +import com.example.kotlin.onetoone.domain.Owner |
| 5 | +import com.example.kotlin.onetoone.repository.MarketRepository |
| 6 | +import com.example.kotlin.onetoone.repository.OwnerRepository |
| 7 | +import org.junit.Before |
| 8 | +import org.junit.Test |
| 9 | +import org.junit.runner.RunWith |
| 10 | +import org.springframework.beans.factory.annotation.Autowired |
| 11 | +import org.springframework.boot.test.context.SpringBootTest |
| 12 | +import org.springframework.test.context.junit4.SpringRunner |
| 13 | +import org.springframework.transaction.annotation.Transactional |
| 14 | + |
| 15 | +@RunWith(SpringRunner::class) |
| 16 | +@SpringBootTest |
| 17 | +@Transactional |
| 18 | +open class OneToOneTests { |
| 19 | + |
| 20 | + @Autowired |
| 21 | + lateinit var marketRepository: MarketRepository |
| 22 | + |
| 23 | + @Autowired |
| 24 | + lateinit var ownerRepository: OwnerRepository |
| 25 | + |
| 26 | + @Before |
| 27 | + fun before_init() { |
| 28 | + marketRepository.save(Market(name = "원철 중화 반점", location = "서울 구로구")) |
| 29 | + marketRepository.save(Market(name = "나은 중화 반점", location = "서울 구로구")) |
| 30 | + marketRepository.save(Market(name = "구글 중화 반점", location = "서울 구로구")) |
| 31 | + |
| 32 | + ownerRepository.save(Owner(name = "원철")) |
| 33 | + ownerRepository.save(Owner(name = "나은")) |
| 34 | + ownerRepository.save(Owner(name = "구글")) |
| 35 | + |
| 36 | + marketRepository.findAll().forEach { println(it) } |
| 37 | + ownerRepository.findAll().forEach { println(it) } |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + fun test_findOne() { |
| 42 | + println(marketRepository.findById(1L).orElse(null)) |
| 43 | + println(ownerRepository.findById(1L).orElse(null)) |
| 44 | + } |
| 45 | +} |
0 commit comments