|
18 | 18 | import org.mockito.InjectMocks; |
19 | 19 | import org.mockito.Mock; |
20 | 20 | import org.mockito.MockitoAnnotations; |
| 21 | +import org.springframework.data.domain.Page; |
| 22 | +import org.springframework.data.domain.PageImpl; |
| 23 | +import org.springframework.data.domain.Pageable; |
21 | 24 | import org.springframework.messaging.simp.SimpMessagingTemplate; |
22 | 25 | import org.springframework.test.context.ActiveProfiles; |
23 | 26 | import org.springframework.test.context.junit4.SpringRunner; |
|
31 | 34 | import edu.tamu.app.model.repo.IdeaRepo; |
32 | 35 | import edu.tamu.app.model.repo.ServiceRepo; |
33 | 36 | import edu.tamu.app.model.repo.UserRepo; |
| 37 | +import edu.tamu.app.model.repo.specification.ServiceSpecification; |
34 | 38 | import edu.tamu.app.model.request.AbstractRequest; |
| 39 | +import edu.tamu.app.model.request.FilteredPageRequest; |
35 | 40 | import edu.tamu.app.model.request.IssueRequest; |
36 | 41 | import edu.tamu.app.model.request.ServiceRequest; |
37 | 42 | import edu.tamu.app.service.ProjectService; |
@@ -59,6 +64,7 @@ public class ServiceControllerTest { |
59 | 64 | private static final Service TEST_SERVICE3 = new Service(TEST_SERVICE3_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_NOT_ON_SHORT_LIST, "", ""); |
60 | 65 | private static final Service TEST_MODIFIED_SERVICE1 = new Service(TEST_SERVICE1_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_NOT_PUBLIC, TEST_NOT_ON_SHORT_LIST, "", ""); |
61 | 66 | private static final List<Service> mockServiceList = new ArrayList<Service>(Arrays.asList(new Service[] { TEST_SERVICE1, TEST_SERVICE2, TEST_SERVICE3 })); |
| 67 | + private static final Page<Service> mockPageableServiceList = new PageImpl<Service>(Arrays.asList(new Service[] { TEST_SERVICE1, TEST_SERVICE2, TEST_SERVICE3 })); |
62 | 68 | private static final List<Service> mockPublicServiceList = new ArrayList<Service>(Arrays.asList(new Service[] { TEST_SERVICE1, TEST_SERVICE3 })); |
63 | 69 |
|
64 | 70 | private static final User TEST_SERVICE = new User("123456789"); |
@@ -92,11 +98,14 @@ public class ServiceControllerTest { |
92 | 98 | private ServiceController serviceController; |
93 | 99 |
|
94 | 100 | @Before |
| 101 | + @SuppressWarnings("unchecked") |
95 | 102 | public void setup() throws UserNotFoundException { |
96 | 103 | MockitoAnnotations.initMocks(this); |
97 | 104 | when(credentials.getUin()).thenReturn("123456789"); |
98 | 105 | when(userRepo.findByUsername(any(String.class))).thenReturn(Optional.of(TEST_SERVICE)); |
99 | 106 | when(systemMonitorService.getOverallStatus()).thenReturn(new OverallStatus(edu.tamu.app.enums.OverallMessageType.SUCCESS, "Success")); |
| 107 | + when(serviceRepo.findAll()).thenReturn(mockServiceList); |
| 108 | + when(serviceRepo.findAll(any(ServiceSpecification.class), any(Pageable.class))).thenReturn(mockPageableServiceList); |
100 | 109 | when(serviceRepo.findAllByOrderByStatusDescNameAsc()).thenReturn(mockServiceList); |
101 | 110 | when(serviceRepo.findByIsPublicOrderByStatusDescNameAsc(true)).thenReturn(mockPublicServiceList); |
102 | 111 | when(serviceRepo.findOne(any(Long.class))).thenReturn(TEST_SERVICE1); |
@@ -135,6 +144,17 @@ private int countPublicServices(List<Service> list) { |
135 | 144 | return count; |
136 | 145 | } |
137 | 146 |
|
| 147 | + @Test |
| 148 | + @SuppressWarnings("unchecked") |
| 149 | + public void testPage() { |
| 150 | + FilteredPageRequest mockFilter = new FilteredPageRequest(); |
| 151 | + response = serviceController.page(mockFilter); |
| 152 | + assertEquals("Not successful at getting paged Services", SUCCESS, response.getMeta().getStatus()); |
| 153 | + |
| 154 | + Page<Service> page = (Page<Service>) response.getPayload().get("PageImpl"); |
| 155 | + assertEquals("The paged list of Services is the wrong length", mockPageableServiceList.getSize(), page.getSize()); |
| 156 | + } |
| 157 | + |
138 | 158 | @Test |
139 | 159 | public void testService() { |
140 | 160 | response = serviceController.getService(TEST_SERVICE1.getId()); |
|
0 commit comments