Skip to content

Commit 8ddf949

Browse files
committed
Fix coverage, add simple test for page method of ServiceController
1 parent ad0b5aa commit 8ddf949

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/test/java/edu/tamu/app/controller/ServiceControllerTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import org.mockito.InjectMocks;
1919
import org.mockito.Mock;
2020
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;
2124
import org.springframework.messaging.simp.SimpMessagingTemplate;
2225
import org.springframework.test.context.ActiveProfiles;
2326
import org.springframework.test.context.junit4.SpringRunner;
@@ -31,7 +34,9 @@
3134
import edu.tamu.app.model.repo.IdeaRepo;
3235
import edu.tamu.app.model.repo.ServiceRepo;
3336
import edu.tamu.app.model.repo.UserRepo;
37+
import edu.tamu.app.model.repo.specification.ServiceSpecification;
3438
import edu.tamu.app.model.request.AbstractRequest;
39+
import edu.tamu.app.model.request.FilteredPageRequest;
3540
import edu.tamu.app.model.request.IssueRequest;
3641
import edu.tamu.app.model.request.ServiceRequest;
3742
import edu.tamu.app.service.ProjectService;
@@ -59,6 +64,7 @@ public class ServiceControllerTest {
5964
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, "", "");
6065
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, "", "");
6166
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 }));
6268
private static final List<Service> mockPublicServiceList = new ArrayList<Service>(Arrays.asList(new Service[] { TEST_SERVICE1, TEST_SERVICE3 }));
6369

6470
private static final User TEST_SERVICE = new User("123456789");
@@ -92,11 +98,14 @@ public class ServiceControllerTest {
9298
private ServiceController serviceController;
9399

94100
@Before
101+
@SuppressWarnings("unchecked")
95102
public void setup() throws UserNotFoundException {
96103
MockitoAnnotations.initMocks(this);
97104
when(credentials.getUin()).thenReturn("123456789");
98105
when(userRepo.findByUsername(any(String.class))).thenReturn(Optional.of(TEST_SERVICE));
99106
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);
100109
when(serviceRepo.findAllByOrderByStatusDescNameAsc()).thenReturn(mockServiceList);
101110
when(serviceRepo.findByIsPublicOrderByStatusDescNameAsc(true)).thenReturn(mockPublicServiceList);
102111
when(serviceRepo.findOne(any(Long.class))).thenReturn(TEST_SERVICE1);
@@ -135,6 +144,17 @@ private int countPublicServices(List<Service> list) {
135144
return count;
136145
}
137146

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+
138158
@Test
139159
public void testService() {
140160
response = serviceController.getService(TEST_SERVICE1.getId());

0 commit comments

Comments
 (0)