美文网首页
订单主表和详情表 dao测试

订单主表和详情表 dao测试

作者: 张三爱的歌 | 来源:发表于2019-10-11 16:10 被阅读0次

订单表dao测试


package com.example.demo.repository;


import com.example.demo.dataobject.OrderMaster;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.junit4.SpringRunner;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.*;

@RunWith(SpringRunner.class)
@SpringBootTest
public class OrderMasterRepositoryTest {
    @Autowired
    private  OrderMasterRepository repository;

    private  final  String OPENID= "110110";

    //增加数据库字段
    @Test
    public  void  saveTest(){
        OrderMaster orderMaster=new OrderMaster();
        orderMaster.setOrderId("12345678");
        orderMaster.setBuyerName("师兄");
        orderMaster.setBuyerPhone("342424224");
        orderMaster.setBuyerAddress("梨子社区");
        orderMaster.setBuyerOpenid(OPENID);
        orderMaster.setOrderAmount(new BigDecimal(7));
        OrderMaster result=   repository.save(orderMaster);
        Assert.assertNotNull(result);
    }



    //分页查询  订单 order_master表的数据
    @Test
  public   void findByBuyerOpenid() {
        PageRequest pageRequest=new PageRequest(0,1);
       Page<OrderMaster> result= repository.findByBuyerOpenid(OPENID,pageRequest);
        Assert.assertNotEquals(0,result.getTotalElements());
         System.out.println(result.getTotalElements());
    }
}

详情表dao测试

package com.example.demo.repository;


import com.example.demo.dataobject.OrderDetail;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.persistence.Entity;
import java.math.BigDecimal;
import java.util.List;


@RunWith(SpringRunner.class)
@SpringBootTest
public  class OrderDetailRepositoryTest {
   @Autowired
   private  OrderDetailRepository repository;

    @Test
    public void saveTest() {
        OrderDetail orderDetail = new OrderDetail();
        orderDetail.setDetailId("12345678101");
        orderDetail.setOrderId("123");
        orderDetail.setProductIcon("http://xxxx.jpg");
        orderDetail.setProductId("11111111");
        orderDetail.setProductName("黄焖鸡米饭");
        orderDetail.setProductPrice(new BigDecimal(2.2));
        orderDetail.setProductQuantity(4);

        OrderDetail result = repository.save(orderDetail);
        Assert.assertNotNull(result);
    }

    @Test
   public void findByOrderId() {
      List<OrderDetail>  orderDetailList= repository.findByOrderId("11111111");
      Assert.assertNotEquals(0,orderDetailList.size());
    }
}

相关文章

网友评论

      本文标题:订单主表和详情表 dao测试

      本文链接:https://www.haomeiwen.com/subject/ajfxmctx.html