订单主表和详情表 dao测试

订单表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());
    }
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容