|
|
@@ -2,6 +2,7 @@ package cn.iselab.mooctest.site.web.logic.impl;
|
|
|
|
|
|
import cn.iselab.mooctest.site.Application;
|
|
|
import cn.iselab.mooctest.site.models.Task;
|
|
|
+import cn.iselab.mooctest.site.service.ExamService;
|
|
|
import cn.iselab.mooctest.site.service.TaskService;
|
|
|
import cn.iselab.mooctest.site.web.data.ExamVO;
|
|
|
import cn.iselab.mooctest.site.web.data.wrapper.ExamVOWrapper;
|
|
|
@@ -14,6 +15,10 @@ import org.mockito.Mock;
|
|
|
import org.mockito.MockitoAnnotations;
|
|
|
import org.mockito.runners.MockitoJUnitRunner;
|
|
|
import org.springframework.boot.test.SpringApplicationConfiguration;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.test.context.web.WebAppConfiguration;
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
@@ -33,22 +38,19 @@ public class ExamLogicImplTest {
|
|
|
private ExamLogicImpl examLogic = new ExamLogicImpl();
|
|
|
|
|
|
@Mock
|
|
|
- private TaskService taskService;
|
|
|
+ private ExamService examService;
|
|
|
|
|
|
@Mock
|
|
|
private ExamVOWrapper examVOWrapper;
|
|
|
|
|
|
+ List<Task> taskList = new ArrayList<>();
|
|
|
+ List<ExamVO> voList = new ArrayList<>();
|
|
|
+ Page<ExamVO> examVOPage;
|
|
|
+ Page<Task> taskPage;
|
|
|
@Before
|
|
|
public void setUp() {
|
|
|
- MockitoAnnotations.initMocks(this);
|
|
|
- }
|
|
|
|
|
|
- @Test
|
|
|
- public void should_returnTheParticipantExamList_when_givenParticipantId() {
|
|
|
- //arrange
|
|
|
- long participantId = 12L;
|
|
|
-
|
|
|
- List<Task> taskList = new ArrayList<>();
|
|
|
+ MockitoAnnotations.initMocks(this);
|
|
|
Task task = new Task();
|
|
|
task.setId(497L);
|
|
|
task.setBeginTime(new Timestamp(1495443120000L));
|
|
|
@@ -59,8 +61,8 @@ public class ExamLogicImplTest {
|
|
|
task.setName("shi juan 1");
|
|
|
task.setSubsiteId(2L);
|
|
|
taskList.add(task);
|
|
|
+ taskPage = new PageImpl(taskList);
|
|
|
|
|
|
- List<ExamVO> expect = new ArrayList<>();
|
|
|
ExamVO examVO = new ExamVO();
|
|
|
examVO.setId(497L);
|
|
|
examVO.setBeginTime(1495443120000L);
|
|
|
@@ -70,60 +72,54 @@ public class ExamLogicImplTest {
|
|
|
examVO.setManagerId(17L);
|
|
|
examVO.setName("shi juan 1");
|
|
|
examVO.setSubsiteId(2L);
|
|
|
- expect.add(examVO);
|
|
|
- when(taskService.getTaskListByWorkerId(participantId)).thenReturn(taskList);
|
|
|
- when(examVOWrapper.wrapParticipantExamList(taskList, participantId)).thenReturn(expect);
|
|
|
+ voList.add(examVO);
|
|
|
+
|
|
|
+ examVOPage = new PageImpl(voList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_returnTheParticipantExamPageData_when_givenParticipantId() {
|
|
|
+ //arrange
|
|
|
+ long participantId = 12L;
|
|
|
+
|
|
|
+ Integer activePage = 1;
|
|
|
+ Integer rowsOnPage = 10;
|
|
|
+ Pageable pageable = new PageRequest(activePage - 1, rowsOnPage);
|
|
|
+
|
|
|
+ when(examService.getExamsByParticipantId(participantId, pageable)).thenReturn(taskPage);
|
|
|
+ when(examVOWrapper.wrapParticipantExam(taskList.get(0), participantId)).thenReturn(voList.get(0));
|
|
|
|
|
|
//action
|
|
|
- List<ExamVO> result = examLogic.getParticipantExamList(participantId);
|
|
|
+ Page<ExamVO> result = examLogic.getParticipantExamList(participantId, pageable);
|
|
|
|
|
|
//assert
|
|
|
- ExamVO expectExam = expect.get(0);
|
|
|
- ExamVO resultExam = result.get(0);
|
|
|
+ ExamVO expectExam = examVOPage.getContent().get(0);
|
|
|
+ ExamVO resultExam = result.getContent().get(0);
|
|
|
Assert.assertEquals(expectExam.getId(), resultExam.getId());
|
|
|
Assert.assertEquals(expectExam.getManagerId(), resultExam.getManagerId());
|
|
|
|
|
|
}
|
|
|
|
|
|
-// @Test
|
|
|
-// public void should_returnTheOrganizerExamList_when_givenParticipantId() {
|
|
|
-// //arrange
|
|
|
-// long organizerId = 12L;
|
|
|
-//
|
|
|
-// List<Task> taskList = new ArrayList<>();
|
|
|
-// Task task = new Task();
|
|
|
-// task.setId(497L);
|
|
|
-// task.setBeginTime(new Timestamp(1495443120000L));
|
|
|
-// task.setEndTime(new Timestamp(1495999990000L));
|
|
|
-// task.setDuration(1);
|
|
|
-// task.setInformation("lalaland");
|
|
|
-// task.setManagerId(17L);
|
|
|
-// task.setName("shi juan 1");
|
|
|
-// task.setSubsiteId(2L);
|
|
|
-// taskList.add(task);
|
|
|
-//
|
|
|
-// List<ExamVO> expect = new ArrayList<>();
|
|
|
-// ExamVO examVO = new ExamVO();
|
|
|
-// examVO.setId(497L);
|
|
|
-// examVO.setBeginTime(1495443120000L);
|
|
|
-// examVO.setEndTime(1495999990000L);
|
|
|
-// examVO.setDuration(1);
|
|
|
-// examVO.setInfo("lalaland");
|
|
|
-// examVO.setManagerId(17L);
|
|
|
-// examVO.setName("shi juan 1");
|
|
|
-// examVO.setSubsiteId(2L);
|
|
|
-// expect.add(examVO);
|
|
|
-// when(taskService.getTaskList(organizerId)).thenReturn(taskList);
|
|
|
-// when(examVOWrapper.wrapOrganizerExamList(taskList, organizerId)).thenReturn(expect);
|
|
|
-//
|
|
|
-// //action
|
|
|
-// List<ExamVO> result = examLogic.getOrganizerExamList(organizerId);
|
|
|
-//
|
|
|
-// //assert
|
|
|
-// ExamVO expectExam = expect.get(0);
|
|
|
-// ExamVO resultExam = result.get(0);
|
|
|
-// Assert.assertEquals(expectExam.getId(), resultExam.getId());
|
|
|
-// Assert.assertEquals(expectExam.getManagerId(), resultExam.getManagerId());
|
|
|
-//
|
|
|
-// }
|
|
|
+ @Test
|
|
|
+ public void should_returnTheOrganizerExamPageData_when_givenOrganizerId() {
|
|
|
+ //arrange
|
|
|
+ long organizerId = 12L;
|
|
|
+
|
|
|
+ Integer activePage = 1;
|
|
|
+ Integer rowsOnPage = 10;
|
|
|
+ Pageable pageable = new PageRequest(activePage - 1, rowsOnPage);
|
|
|
+
|
|
|
+ when(examService.getExamsByOrganizerId(organizerId, pageable)).thenReturn(taskPage);
|
|
|
+ when(examVOWrapper.wrapOrganizerExam(taskList.get(0), organizerId)).thenReturn(voList.get(0));
|
|
|
+
|
|
|
+ //action
|
|
|
+ Page<ExamVO> result = examLogic.getOrganizerExamList(organizerId, pageable);
|
|
|
+
|
|
|
+ //assert
|
|
|
+ ExamVO expectExam = examVOPage.getContent().get(0);
|
|
|
+ ExamVO resultExam = result.getContent().get(0);
|
|
|
+ Assert.assertEquals(expectExam.getId(), resultExam.getId());
|
|
|
+ Assert.assertEquals(expectExam.getManagerId(), resultExam.getManagerId());
|
|
|
+
|
|
|
+ }
|
|
|
}
|