package com.sckw.example;


import com.sckw.example.model.Student;
import com.sckw.example.service.StudentService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date;
import java.util.List;

@SpringBootTest
public class StudentDaoTest {

    @Autowired
    private StudentService studentDao;

    @Test
    void addOneStudent(){
//        插入10行
        Long begtime = System.currentTimeMillis();
        for (Long count = 0L; count < 1000000; count++) {
            Student student = new Student();
            student.setStudentId(count);
            student.setStudentName("Echo"+count);
            student.setStudentAge(0);
            student.setStudentScore(98.5-count);
            student.setStudentBirthday(new Date());
            studentDao.addOne(student);
        }
        Long enttime = System.currentTimeMillis();
        System.out.println("------------------"+(enttime - begtime));
    }

    @Test
    void deleteOneStudentByStudentId(){
//        删除id为study_0的学生
        studentDao.deleteOneById("study_0");
    }

    @Test
    void updateOneStudent(){
//        修改id为study_1的Student年龄为21
        Student student = studentDao.findOneById("study_1");
        student.setStudentAge(21);
        studentDao.updateOne(student);

    }

    @Test
    void getOneStudentByStudentId(){
        System.out.println(studentDao.findOneById("study_1"));
    }

    @Test
    void getAllStudent(){
        List<Student> studentList = studentDao.findAll();
        studentList.forEach(System.out::println);
    }
}

