AdItemService { @Transactional public void createAdBond3 (LocalDate startDate, LocalDate endDate, List<String> orderTypes) { List<AdBondDto> adBondDtos = queryRepository.createAdBondDto(startDate, endDate, orderTypes); List<AdBond> adBonds = adBondDtos.stream() .map(adBondDto -> AdBond.builder() .amount(adBondDto.getAmount()) .txDate(adBondDto.getTxDate()) .orderType(adBondDto.getOrderType()) .customer(new Customer(adBondDto.getCustomerId())) .build()) .collect(Collectors.toList()); adBondRepository.saveAll(adBonds); }  @Transactional void createAdBond1(LocalDate startDate, LocalDate endDate, List<String> orderTypes); @Transactional void createAdBond2(LocalDate startDate, LocalDate endDate, List<String> orderTypes); @Transactional void createAdBond3(LocalDate startDate, LocalDate endDate, List<String> orderTypes); @Transactional void createAdBond4(LocalDate startDate, LocalDate endDate, List<String> orderTypes);  }
@Test void test_createAdBond2() throws Exception { Shop shop = shopRepository.save(new Shop("no", "name")); String expectedNo = "no"; Customer customer = customerRepository.save(new Customer(expectedNo, "name", "bizNo", "ceo", shop)); LocalDate startDate = LocalDate.of(2020,8,11); LocalDate endDate = LocalDate.of(2020,8,12); String orderType1 = "a"; String orderType2 = "b"; adItemRepository.save(new AdItem(orderType1, startDate, "1", 1000L, customer)); adItemRepository.save(new AdItem(orderType2, endDate, "2", 2000L, customer)); adItemService.createAdBond3(startDate, endDate, Arrays.asList(orderType1, orderType2)); List<AdBond> adBonds = adBondRepository.findAll(); assertThat(adBonds).hasSize(2); assertThat(adBonds.get(0).getCustomer().getCustomerNo()).isEqualTo(expectedNo); assertThat(adBonds.get(1).getCustomer().getCustomerNo()).isEqualTo(expectedNo); }
@Test void test_createAdBond3() throws Exception { String expectedNo = "no"; Customer customer = customerRepository.save(new Customer(expectedNo, "name", "bizNo", "ceo")); shopRepository.save(new Shop(expectedNo, "name", customer)); LocalDate startDate = LocalDate.of(2020,8,11); LocalDate endDate = LocalDate.of(2020,8,12); String orderType1 = "a"; String orderType2 = "b"; adItemRepository.save(new AdItem(orderType1, startDate, "1", 1000L, customer)); adItemRepository.save(new AdItem(orderType2, endDate, "2", 2000L, customer)); adItemService.createAdBond3(startDate, endDate, Arrays.asList(orderType1, orderType2)); List<AdBond> adBonds = adBondRepository.findAll(); AdBond adBond1 = adBonds.get(0); AdBond adBond2 = adBonds.get(1); assertThat(adBonds).hasSize(2); assertThat(adBond1.getCustomer().getCustomerNo()).isEqualTo(expectedNo); assertThat(adBond2.getCustomer().getCustomerNo()).isEqualTo(expectedNo); assertThat(adBond1.getCustomer().getShop().getShopNo()).isEqualTo(expectedNo); assertThat(adBond2.getCustomer().getShop().getShopNo()).isEqualTo(expectedNo); }