CustomerService { @Transactional(readOnly = true) public long findMyOrderPriceSum(){ Customer customer = (Customer)httpSession.getAttribute("loginUser"); return customerOrderRepository.findAllByCustomer(customer) .mapToLong(co -> sum(co.getProducts())) .sum(); }  @Transactional(readOnly = true) Customer findByName(String name); @Transactional(readOnly = true) long findMyOrderPriceSum(); @Transactional(readOnly = true) void saveMyOrderProductCountInSession(); @Transactional(readOnly = true) String getCustomerJsonString(String requestBody);  }
@Test public void findMyOrderPriceSum_로그인사용자의_주문상품금액합계가_반환된다 () throws Exception { Customer customer = customerRepository.save( Customer.builder() .name("jojoldu") .email("jojoldu@gmail.com") .mobileNumber("01011239877") .build() ); httpSession.setAttribute("loginUser", customer); Product 키보드 = productRepository.save( Product.builder() .name("키보드") .manufactureDate(LocalDate.of(2017,9,19)) .price(10000) .build() ); Product 마우스 = productRepository.save( Product.builder() .name("마우스") .manufactureDate(LocalDate.of(2017,9,19)) .price(15000) .build() ); CustomerOrder customerOrder = customerOrderRepository.save( CustomerOrder.builder() .customer(customer) .address("장은빌딩") .orderDateTime(LocalDateTime.of(2017,9,19,20,0)) .isGiftPackaging(true) .build() ); customerOrder.addProduct(키보드); customerOrder.addProduct(마우스); customerOrderRepository.save(customerOrder); long sum = customerService.findMyOrderPriceSum(); assertThat(sum, is(25000L)); }