package org.xmx0632.deliciousfruit.api.v1;
import java.math.BigDecimal;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestTemplate;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.OrderItem;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.OrderRequestReceiver;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment.CashCouponPay;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment.DeliveryPeriod;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment.ECouponPay;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment.GiftCardPay;
import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse;
import org.xmx0632.deliciousfruit.functional.BaseControllerTestCase;
public class OrderApiControllerProcessTest extends BaseControllerTestCase {
private final RestTemplate restTemplate = new RestTemplate();
private static String url;
@BeforeClass
public static void initUrl() {
url = baseUrl + "/order/process";
}
@Test
public void testProcessSuccess() throws Exception {
HttpHeaders requestHeaders = createHttpHeader("user1", "password");
OrderRequest orderRequest = new OrderRequest();
DeliveryPeriod deliveryPeriod = new DeliveryPeriod();
deliveryPeriod.setDatePeriod("周一至周五");
deliveryPeriod.setTimePeriod("上午8点到下午5点");
orderRequest.setDeliveryPeriod(deliveryPeriod);
OrderItem orderItem1 = new OrderItem();
orderItem1.setProductId("110110");
orderItem1.setQuantity(2);
OrderItem orderItem2 = new OrderItem();
orderItem2.setProductId("110112");
orderItem2.setQuantity(1);
orderRequest.getOrderList().add(orderItem1);
orderRequest.getOrderList().add(orderItem2);
Payment payment = new Payment();
CashCouponPay cashCouponPay = new CashCouponPay();
cashCouponPay.setId("1234567dddddd");
cashCouponPay.setPayAmount(BigDecimal.valueOf(25.00));
CashCouponPay cashCouponPay2 = new CashCouponPay();
cashCouponPay2.setId("666666ddddd");
cashCouponPay2.setPayAmount(BigDecimal.valueOf(25.00));
payment.getCashCoupons().add(cashCouponPay);
payment.getCashCoupons().add(cashCouponPay2);
GiftCardPay giftCardPay = new GiftCardPay();
giftCardPay.setId("CARD1000001");
giftCardPay.setPassword("FDSFDSKFJDKSFJ");
giftCardPay.setPayAmount(BigDecimal.valueOf(10.00));
GiftCardPay giftCardPay2 = new GiftCardPay();
giftCardPay2.setId("CARD1000002");
giftCardPay2.setPassword("HIHIHOHOO");
giftCardPay2.setPayAmount(BigDecimal.valueOf(20.00));
payment.getGiftCards().add(giftCardPay);
payment.getGiftCards().add(giftCardPay2);
payment.geteCoupon().add(
new ECouponPay("eCoupon1", BigDecimal.valueOf(3.0)));
payment.setPayAmountFromAccount(BigDecimal.valueOf(50.00));
payment.setPayAmountFromPonit(BigDecimal.valueOf(50.00));
payment.setPaymentMethod("10");
payment.setPayPonit(500);
orderRequest.setPayment(payment);
OrderRequestReceiver receiverInfo = new OrderRequestReceiver();
receiverInfo.setAddress("云桥路133");
receiverInfo.setCity("浦东");
receiverInfo.setDistrict("金桥");
receiverInfo.setName("张三");
receiverInfo.setPhoneNumber("13811118888");
receiverInfo.setProvince("上海");
// receiverInfo.setId(Long.valueOf(2));
orderRequest.setReceiverInfo(receiverInfo);
orderRequest.setTransactionID("ABCD10000001");
HttpEntity<OrderRequest> entity = new HttpEntity<OrderRequest>(
orderRequest, requestHeaders);
OrderResponse response = restTemplate.postForObject(url, entity,
OrderResponse.class);
formatHttpInfoPrint(HttpMethod.POST, url, requestHeaders, "测试订购, 成功",
jsonMapper.toJson(orderRequest), jsonMapper.toJson(response));
}
}