2323
2424import edu .tamu .app .controller .ServiceController ;
2525import edu .tamu .app .enums .Status ;
26+ import edu .tamu .app .model .AppUser ;
27+ import edu .tamu .app .model .OverallStatus ;
2628import edu .tamu .app .model .Service ;
29+ import edu .tamu .app .model .repo .AppUserRepo ;
2730import edu .tamu .app .model .repo .ServiceRepo ;
31+ import edu .tamu .app .service .SystemMonitorService ;
2832import edu .tamu .framework .model .ApiResponse ;
33+ import edu .tamu .framework .model .Credentials ;
2934
3035@ ActiveProfiles ("test" )
3136@ RunWith (SpringRunner .class )
@@ -50,6 +55,8 @@ public class ServiceControllerTest {
5055
5156 protected static ApiResponse response ;
5257
58+ protected static AppUser user = new AppUser ("123456789" );
59+
5360 @ Mock
5461 protected ServiceRepo serviceRepo ;
5562
@@ -59,9 +66,21 @@ public class ServiceControllerTest {
5966 @ InjectMocks
6067 protected ServiceController serviceController ;
6168
69+ @ Mock
70+ protected static Credentials credentials ;
71+
72+ @ Mock
73+ protected AppUserRepo userRepo ;
74+
75+ @ Mock
76+ protected SystemMonitorService systemMonitorService ;
77+
6278 @ Before
6379 public void setUp () {
6480 MockitoAnnotations .initMocks (this );
81+ when (credentials .getUin ()).thenReturn ("123456789" );
82+ when (userRepo .findByUin (any (String .class ))).thenReturn (user );
83+ when (systemMonitorService .getOverallStatus ()).thenReturn (new OverallStatus (edu .tamu .app .enums .OverallMessageType .SUCCESS , "Success" ));
6584 when (serviceRepo .findAll ()).thenReturn (mockServiceList );
6685 when (serviceRepo .findByIsPublic (true )).thenReturn (mockPublicServiceList );
6786 when (serviceRepo .findOne (any (Long .class ))).thenReturn (TEST_SERVICE1 );
@@ -109,15 +128,15 @@ public void testService() {
109128
110129 @ Test
111130 public void testCreate () {
112- response = serviceController .createService (TEST_SERVICE1 );
131+ response = serviceController .createService (TEST_SERVICE1 , credentials );
113132 assertEquals ("Not sucessful at creating Service" , SUCCESS , response .getMeta ().getType ());
114133 Service service = (Service ) response .getPayload ().get ("Service" );
115134 assertEquals ("Incorrect service returned" , TEST_SERVICE1 .getName (), service .getName ());
116135 }
117136
118137 @ Test
119138 public void testUpdate () {
120- response = serviceController .updateService (TEST_MODIFIED_SERVICE1 );
139+ response = serviceController .updateService (TEST_MODIFIED_SERVICE1 , credentials );
121140 assertEquals ("Not successful at updating service" , SUCCESS , response .getMeta ().getType ());
122141 Service service = (Service ) response .getPayload ().get ("Service" );
123142 assertEquals ("Service name was not properly updated" , TEST_MODIFIED_SERVICE1 .getName (), service .getName ());
0 commit comments