|
@@ -0,0 +1,78 @@
|
|
|
+package cn.com.qmth.examcloud.service.examwork;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.entity.Exam;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.enums.ExamType;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.service.ExamService;
|
|
|
+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.Example;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.Month;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Unit test for simple App.
|
|
|
+ */
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest
|
|
|
+public class AppTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamRepo examRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamService examService;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testExam() throws ParseException {
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Exam exam1 = new Exam();
|
|
|
+ exam1.setBeginTime(simpleDateFormat.parse("2016-12-01"));
|
|
|
+ exam1.setEndTime(simpleDateFormat.parse("2016-12-31"));
|
|
|
+ exam1.setCreateTime(new Date());
|
|
|
+ exam1.setDuration(90);
|
|
|
+ exam1.setFreezeTime(30);
|
|
|
+ exam1.setExamType(ExamType.ONLINE);
|
|
|
+ exam1.setName("2016年12月华科考试");
|
|
|
+ exam1.setStatus("未考试");
|
|
|
+
|
|
|
+ Exam exam2 = new Exam();
|
|
|
+ exam2.setBeginTime(simpleDateFormat.parse("2016-11-01"));
|
|
|
+ exam2.setEndTime(simpleDateFormat.parse("2016-11-30"));
|
|
|
+ exam2.setCreateTime(new Date());
|
|
|
+ exam2.setDuration(90);
|
|
|
+ exam2.setFreezeTime(30);
|
|
|
+ exam2.setExamType(ExamType.ONLINE);
|
|
|
+ exam2.setName("2016年11月华科考试");
|
|
|
+ exam2.setStatus("未考试");
|
|
|
+
|
|
|
+ examRepo.deleteAll();
|
|
|
+ examRepo.save(exam1);
|
|
|
+ examRepo.save(exam2);
|
|
|
+
|
|
|
+ Assert.assertEquals(2,examRepo.count());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testExamAll(){
|
|
|
+// List<Exam> examList = (List)examService.getAllExam(new Exam()).getBody();
|
|
|
+// Assert.assertEquals(3,examList.size());
|
|
|
+ Exam exam = new Exam();
|
|
|
+ exam.setName("2016年11月华科考试");
|
|
|
+ Example<Exam> examExample = Example.of(exam);
|
|
|
+ Assert.assertEquals(3,examRepo.findAll(examExample).size());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|