Search in sources :

Example 1 with Member

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

the class MemberServiceTest method 회원가입.

@Test
public void 회원가입() throws Exception {
    // given
    Member member = new Member("영롱");
    // when
    Long saveId = memberService.join(member);
    // then
    Assertions.assertThat(member).isEqualTo(memberRepository.findOne(saveId));
}
Also used : Member(com.test.toyproject1.entity.Member) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Member

use of com.test.toyproject1.entity.Member 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 3 with Member

use of com.test.toyproject1.entity.Member 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 4 with Member

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

the class MemberServiceTest method 중복회원예외.

@Test
public void 중복회원예외() throws Exception {
    // given
    Member member1 = new Member("영롱");
    Member member2 = new Member("영롱");
    // when
    memberService.join(member1);
    // then
    // 예외발생
    assertThrows(IllegalAccessException.class, () -> memberService.join(member2));
}
Also used : Member(com.test.toyproject1.entity.Member) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Member

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

the class OrderServiceTest method createMember.

private Member createMember() {
    Member member = new Member("회원1");
    member.setAddress(new Address("서울", "송파", "문정로 11길"));
    em.persist(member);
    return member;
}
Also used : Address(com.test.toyproject1.entity.valueType.Address) Member(com.test.toyproject1.entity.Member)

Aggregations

Member (com.test.toyproject1.entity.Member)7 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Item (com.test.toyproject1.entity.Item)4 Order (com.test.toyproject1.entity.Order)2 ItemBook (com.test.toyproject1.entity.ItemBook)1 Address (com.test.toyproject1.entity.valueType.Address)1 PostConstruct (javax.annotation.PostConstruct)1