package com.itheima.shop;
import com.itheima.shop.pojo.TradeOrder;
import org.junit.Test;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal;
/**
* @author shkstart
* @create 2023-07-14 20:09
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ShopOrderWebApplication.class)
public class OrderWebTest {
@Autowired
private RestTemplate restTemplate;
@Value("${shop.order.baseURI}")
private String baseURI;
@Value("${shop.order.confirm}")
private String confirmOrderPath;
@Test
public void confirmOrder() {
Long couponId = 345988230098857984L;
Long goodsId = 345959443973935104L;
Long userId = 345963634385633280L;
TradeOrder order = new TradeOrder();
order.setGoodsId(goodsId);
order.setUserId(userId);
order.setCouponId(couponId);
order.setAddress("北京");
order.setGoodsNumber(1);
order.setGoodsPrice(new BigDecimal(1000));
order.setShippingFee(BigDecimal.ZERO);
order.setOrderAmount(new BigDecimal(1000));
order.setMoneyPaid(new BigDecimal(100));
Result result = restTemplate.postForEntity(baseURI+ confirmOrderPath,order, Result.class).getBody();
System.out.println(result);
}
}
package com.itheima.shop.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.shop.api.IOrderService;
import com.itheima.shop.entity.Result;
import com.itheima.shop.pojo.TradeOrder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author shkstart
* @create 2023-07-09 18:09
*/
@RestController
@RequestMapping("/order")
public class OrderController {
@Reference
private IOrderService orderService;
@RequestMapping("/confirm")
public Result confirmOrder(@RequestBody TradeOrder order) {
return orderService.confirOrder(order);
}
}