1818import org .mockito .InjectMocks ;
1919import org .mockito .Mock ;
2020import org .mockito .MockitoAnnotations ;
21+ import org .springframework .data .domain .Page ;
22+ import org .springframework .data .domain .PageImpl ;
23+ import org .springframework .data .domain .Pageable ;
2124import org .springframework .messaging .simp .SimpMessagingTemplate ;
2225import org .springframework .test .context .junit4 .SpringRunner ;
2326
3033import edu .tamu .app .model .repo .IdeaRepo ;
3134import edu .tamu .app .model .repo .ServiceRepo ;
3235import edu .tamu .app .model .repo .UserRepo ;
36+ import edu .tamu .app .model .repo .specification .ServiceSpecification ;
3337import edu .tamu .app .model .request .AbstractRequest ;
38+ import edu .tamu .app .model .request .FilteredPageRequest ;
3439import edu .tamu .app .model .request .IssueRequest ;
3540import edu .tamu .app .model .request .ServiceRequest ;
3641import edu .tamu .app .service .ProjectService ;
@@ -57,6 +62,7 @@ public class ServiceControllerTest {
5762 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 , "" , "" );
5863 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 , "" , "" );
5964 private static final List <Service > mockServiceList = new ArrayList <Service >(Arrays .asList (new Service [] { TEST_SERVICE1 , TEST_SERVICE2 , TEST_SERVICE3 }));
65+ private static final Page <Service > mockPageableServiceList = new PageImpl <Service >(Arrays .asList (new Service [] { TEST_SERVICE1 , TEST_SERVICE2 , TEST_SERVICE3 }));
6066 private static final List <Service > mockPublicServiceList = new ArrayList <Service >(Arrays .asList (new Service [] { TEST_SERVICE1 , TEST_SERVICE3 }));
6167
6268 private static final User TEST_SERVICE = new User ("123456789" );
@@ -90,11 +96,14 @@ public class ServiceControllerTest {
9096 private ServiceController serviceController ;
9197
9298 @ Before
99+ @ SuppressWarnings ("unchecked" )
93100 public void setup () throws UserNotFoundException {
94101 MockitoAnnotations .initMocks (this );
95102 when (credentials .getUin ()).thenReturn ("123456789" );
96103 when (userRepo .findByUsername (any (String .class ))).thenReturn (Optional .of (TEST_SERVICE ));
97104 when (systemMonitorService .getOverallStatus ()).thenReturn (new OverallStatus (edu .tamu .app .enums .OverallMessageType .SUCCESS , "Success" ));
105+ when (serviceRepo .findAll ()).thenReturn (mockServiceList );
106+ when (serviceRepo .findAll (any (ServiceSpecification .class ), any (Pageable .class ))).thenReturn (mockPageableServiceList );
98107 when (serviceRepo .findAllByOrderByStatusDescNameAsc ()).thenReturn (mockServiceList );
99108 when (serviceRepo .findByIsPublicOrderByStatusDescNameAsc (true )).thenReturn (mockPublicServiceList );
100109 when (serviceRepo .findOne (any (Long .class ))).thenReturn (TEST_SERVICE1 );
@@ -133,6 +142,17 @@ private int countPublicServices(List<Service> list) {
133142 return count ;
134143 }
135144
145+ @ Test
146+ @ SuppressWarnings ("unchecked" )
147+ public void testPage () {
148+ FilteredPageRequest mockFilter = new FilteredPageRequest ();
149+ response = serviceController .page (mockFilter );
150+ assertEquals ("Not successful at getting paged Services" , SUCCESS , response .getMeta ().getStatus ());
151+
152+ Page <Service > page = (Page <Service >) response .getPayload ().get ("PageImpl" );
153+ assertEquals ("The paged list of Services is the wrong length" , mockPageableServiceList .getSize (), page .getSize ());
154+ }
155+
136156 @ Test
137157 public void testService () {
138158 response = serviceController .getService (TEST_SERVICE1 .getId ());
0 commit comments