Search in sources :

Example 21 with Order

use of dataaccess.ex1.entity.Order 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 22 with Order

use of dataaccess.ex1.entity.Order in project jmix-docs by Haulmont.

the class OrderStatusBean method setStatus.

@Override
public void setStatus(Order order, String status) {
    Order reloadedOrder = dataManager.load(Order.class).id(order.getId()).one();
    reloadedOrder.setStatus(status);
    dataManager.save(reloadedOrder);
}
Also used : Order(bpm.ex1.entity.Order)

Example 23 with Order

use of dataaccess.ex1.entity.Order in project jmix-docs by Haulmont.

the class OrderServiceTest method testCreateOrderWithCustomer.

@Test
void testCreateOrderWithCustomer() {
    Order order = orderService.createOrderWithCustomer();
    assertNotNull(order.getCustomer());
}
Also used : Order(dataaccess.ex1.entity.Order) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with Order

use of dataaccess.ex1.entity.Order in project jmix-docs by Haulmont.

the class OrderServiceTest method testFetchPlan_FetchPlanBuilder_DataManager.

// end::fetch-plan-builder[]
@Test
void testFetchPlan_FetchPlanBuilder_DataManager() {
    // tag::fetch-plan-builder-dm[]
    List<Order> orders = dataManager.load(Order.class).all().fetchPlan(fpb -> fpb.addFetchPlan(FetchPlan.BASE).add("customer")).list();
    // end::fetch-plan-builder-dm[]
    Order o1 = orders.get(0);
    assertEquals(0, o1.getAmount().compareTo(BigDecimal.valueOf(5000)));
    assertEquals("alice@company.com", o1.getCustomer().getEmail());
}
Also used : Order(dataaccess.ex1.entity.Order) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) io.jmix.core(io.jmix.core) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Order(dataaccess.ex1.entity.Order) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) BigDecimal(java.math.BigDecimal) DataSource(javax.sql.DataSource) Logger(org.slf4j.Logger) OrderLine(dataaccess.ex1.entity.OrderLine) PersistenceHints(io.jmix.data.PersistenceHints) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) UUID(java.util.UUID) Product(dataaccess.ex1.entity.Product) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) LocalDate(java.time.LocalDate) Assertions(org.junit.jupiter.api.Assertions) Customer(dataaccess.ex1.entity.Customer) Collections(java.util.Collections) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with Order

use of dataaccess.ex1.entity.Order in project jmix-docs by Haulmont.

the class OrderEventListener method onOrderSaving.

@EventListener
void onOrderSaving(EntitySavingEvent<Order> event) {
    if (event.isNewEntity()) {
        Order order = event.getEntity();
        order.setNumber(generateOrderNumber());
    }
}
Also used : Order(dataaccess.ex1.entity.Order) EventListener(org.springframework.context.event.EventListener)

Aggregations

SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 Test (org.junit.jupiter.api.Test)17 Order (dataaccess.ex1.entity.Order)12 Order (security.ex1.entity.Order)6 OrderLine (dataaccess.ex1.entity.OrderLine)4 Subscribe (io.jmix.ui.screen.Subscribe)4 BigDecimal (java.math.BigDecimal)4 Order (maps.ex1.entity.Order)4 Order (bpm.ex1.entity.Order)3 UUID (java.util.UUID)3 EventListener (org.springframework.context.event.EventListener)3 Order (charts.ex1.entity.Order)2 Item (com.test.toyproject1.entity.Item)2 Member (com.test.toyproject1.entity.Member)2 Order (com.test.toyproject1.entity.Order)2 Customer (dataaccess.ex1.entity.Customer)2 Product (dataaccess.ex1.entity.Product)2 Order (datamodel.ex1.entity.Order)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2