Search in sources :

Example 1 with Item

use of com.test.toyproject1.entity.Item in project Today-I-Learn by kha0213.

the class OrderServiceTest method 상품주문_재고수량초과.

@Test
public void 상품주문_재고수량초과() throws Exception {
    // given
    Member member = createMember();
    Item book = createBook("JPA입문", 15000, 5);
    // 5개 재고에 10개 주문
    int orderCount = 10;
    // when
    assertThrows(NotEnoughStockException.class, () -> orderService.order(member.getId(), book.getId(), orderCount));
}
Also used : Item(com.test.toyproject1.entity.Item) Member(com.test.toyproject1.entity.Member) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Item

use of com.test.toyproject1.entity.Item in project Today-I-Learn by kha0213.

the class OrderServiceTest method 상품주문성공.

@Test
public void 상품주문성공() throws Exception {
    // given
    Member member = createMember();
    Item book = createBook("JPA입문", 15000, 5);
    int orderCount = 2;
    // when
    Long orderId = orderService.order(member.getId(), book.getId(), orderCount);
    // then
    Order getOrder = orderRepository.findOne(orderId);
    // 상품주문시 상태 ORDER
    assertEquals(OrderStatus.ORDER, getOrder.getStatus());
    // 주문 상품 2개
    assertEquals(orderCount, getOrder.getOrderItems().get(0).getCount());
    // 주문 가격은 가격 * 수량
    assertEquals(book.getPrice() * orderCount, getOrder.getTotalPrice());
    // 주문 수량만큼 재고 마이너스
    assertEquals(5 - orderCount, book.getStockQuantity());
}
Also used : Order(com.test.toyproject1.entity.Order) Item(com.test.toyproject1.entity.Item) Member(com.test.toyproject1.entity.Member) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Item

use of com.test.toyproject1.entity.Item in project Today-I-Learn by kha0213.

the class ItemController method updateItemForm.

/**
 * 아이템 수정화면 이동
 * @param itemId
 * @param model
 * @return
 */
@RequestMapping(value = "/items/{itemId}/edit", method = GET)
public String updateItemForm(@PathVariable("itemId") Long itemId, Model model) {
    logger.info("updateItemForm start!!");
    Item item = itemService.findOne(itemId);
    model.addAttribute("item", item);
    return "items/updateItemForm";
}
Also used : Item(com.test.toyproject1.entity.Item) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Item

use of com.test.toyproject1.entity.Item in project Today-I-Learn by kha0213.

the class OrderServiceTest method 주문취소.

@Test
public void 주문취소() throws Exception {
    // given
    Member member = createMember();
    Item book = createBook("JPA입문", 15000, 5);
    int orderCount = 2;
    // when
    Long orderId = orderService.order(member.getId(), book.getId(), orderCount);
    orderService.cancelOrder(orderId);
    // then
    Order getOrder = orderRepository.findOne(orderId);
    // 주문 취소 상태 검증
    assertEquals(OrderStatus.CANCEL, getOrder.getStatus());
    // 재고 원복 검증
    assertEquals(5, book.getStockQuantity());
}
Also used : Order(com.test.toyproject1.entity.Order) Item(com.test.toyproject1.entity.Item) Member(com.test.toyproject1.entity.Member) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Item

use of com.test.toyproject1.entity.Item in project Today-I-Learn by kha0213.

the class PostConstructExample method init.

@PostConstruct
public void init() throws IllegalAccessException {
    Member member1 = new Member("young1");
    memberService.join(member1);
    Member member2 = new Member("young2");
    memberService.join(member2);
    Member member3 = new Member("young3");
    memberService.join(member3);
    Member member4 = new Member("young4");
    memberService.join(member4);
    Item item1 = new ItemBook("JPA", 12000, 10);
    itemService.saveItem(item1);
    Item item2 = new ItemBook("JAVA", 1000, 1);
    itemService.saveItem(item2);
    Item item3 = new ItemBook("SPRING", 30000, 5);
    itemService.saveItem(item3);
}
Also used : Item(com.test.toyproject1.entity.Item) Member(com.test.toyproject1.entity.Member) ItemBook(com.test.toyproject1.entity.ItemBook) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Item (com.test.toyproject1.entity.Item)5 Member (com.test.toyproject1.entity.Member)4 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Order (com.test.toyproject1.entity.Order)2 ItemBook (com.test.toyproject1.entity.ItemBook)1 PostConstruct (javax.annotation.PostConstruct)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1