|
| 1 | +package com.example.java; |
| 2 | + |
| 3 | +import com.example.java.onetoone.domain.Market; |
| 4 | +import com.example.java.onetoone.domain.Owner; |
| 5 | +import com.example.java.onetoone.repository.MarketRepository; |
| 6 | +import com.example.java.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(classes = SpringBootJpaApplication.class) |
| 17 | +@Transactional |
| 18 | +public class OneToOneTests { |
| 19 | + |
| 20 | + @Autowired |
| 21 | + MarketRepository marketRepository; |
| 22 | + |
| 23 | + @Autowired |
| 24 | + OwnerRepository ownerRepository; |
| 25 | + |
| 26 | + @Before |
| 27 | + public void before_init() { |
| 28 | + Market wonchulMarket = marketRepository.save(new Market("원철 중화 반점", "서울 구로구")); |
| 29 | + Market naeunMarket = marketRepository.save(new Market("나은 중화 반점", "서울 구로구")); |
| 30 | + Market googleMarket = marketRepository.save(new Market("구글 중화 반점", "서울 구로구")); |
| 31 | + |
| 32 | + Owner wonchul = ownerRepository.save(new Owner("원철")); |
| 33 | + wonchul.setMarket(wonchulMarket); |
| 34 | + wonchulMarket.setOwner(wonchul); |
| 35 | + |
| 36 | + Owner naeun = ownerRepository.save(new Owner("나은")); |
| 37 | + naeun.setMarket(naeunMarket); |
| 38 | + naeunMarket.setOwner(naeun); |
| 39 | + |
| 40 | + Owner google = ownerRepository.save(new Owner("구글")); |
| 41 | + google.setMarket(googleMarket); |
| 42 | + googleMarket.setOwner(google); |
| 43 | + |
| 44 | + marketRepository.findAll().forEach(System.out::println); |
| 45 | + ownerRepository.findAll().forEach(System.out::println); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void test_findOne() { |
| 50 | + System.out.println(marketRepository.findById(1L).orElse(null)); |
| 51 | + System.out.println(ownerRepository.findById(1L).orElse(null)); |
| 52 | + } |
| 53 | +} |
0 commit comments