|
@@ -3,10 +3,12 @@ package cn.iselab.mooctest.site.web.logic.impl;
|
|
|
import cn.iselab.mooctest.site.AbstractShiroTest;
|
|
|
import cn.iselab.mooctest.site.data.UserDTOForMT;
|
|
|
import cn.iselab.mooctest.site.models.Group;
|
|
|
+import cn.iselab.mooctest.site.models.ManagerProperty;
|
|
|
import cn.iselab.mooctest.site.models.User;
|
|
|
import cn.iselab.mooctest.site.models.instancePermission.GroupPermission;
|
|
|
import cn.iselab.mooctest.site.service.ExamService;
|
|
|
import cn.iselab.mooctest.site.service.GroupService;
|
|
|
+import cn.iselab.mooctest.site.service.ManagerPropertyService;
|
|
|
import cn.iselab.mooctest.site.service.UserService;
|
|
|
import cn.iselab.mooctest.site.service.instancePermission.GroupPermissionService;
|
|
|
import cn.iselab.mooctest.site.web.data.GroupVO;
|
|
@@ -33,6 +35,7 @@ import java.util.List;
|
|
|
import static org.junit.Assert.*;
|
|
|
import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Matchers.anyList;
|
|
|
+import static org.mockito.Matchers.anyListOf;
|
|
|
import static org.mockito.Mockito.doNothing;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.when;
|
|
@@ -52,7 +55,7 @@ public class GroupLogicImplTest extends AbstractShiroTest{
|
|
|
@Mock
|
|
|
private GroupPermissionService groupPermissionService;
|
|
|
@Mock
|
|
|
- private GroupVOWrapper getGroupVOWrapper;
|
|
|
+ private ManagerPropertyService managerPropertyService;
|
|
|
|
|
|
private Pageable pageable;
|
|
|
|
|
@@ -245,5 +248,87 @@ public class GroupLogicImplTest extends AbstractShiroTest{
|
|
|
Assert.assertEquals(group.getId(),result.getId());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ @Test
|
|
|
+ public void should_returnUserVO_when_addUserIntoGroup(){
|
|
|
+ //arrange
|
|
|
+ User user = new User();
|
|
|
+ user.setId(1796L);
|
|
|
+ UserDTOForMT userDTOForMT = new UserDTOForMT();
|
|
|
+ userDTOForMT.setId(1796L);
|
|
|
+ when(groupService.getGroup(1L)).thenReturn(group);
|
|
|
+ when(groupService.checkManagerGroupSize(7L)).thenReturn(true);
|
|
|
+ when(groupService.checkUserExist(1796L, 1L)).thenReturn(false);
|
|
|
+ when(userService.findByUsername("123")).thenReturn(userDTOForMT);
|
|
|
+ when(groupService.addUserIntoGroup(1796L, 1L)).thenReturn(user);
|
|
|
+ //action
|
|
|
+ UserVO result = groupLogic.addUserIntoGroup("123",1L);
|
|
|
+ //assert
|
|
|
+ Assert.assertEquals(user.getId(),result.getId());
|
|
|
+ Assert.assertEquals("",result.getPassword());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_returnUserVO_when_deleteUserFromGroup(){
|
|
|
+ //arrange
|
|
|
+ User user = new User();
|
|
|
+ user.setId(1796L);
|
|
|
+ UserDTOForMT userDTOForMT = new UserDTOForMT();
|
|
|
+ userDTOForMT.setId(1796L);
|
|
|
+ when(groupService.getGroup(1L)).thenReturn(group);
|
|
|
+ when(userService.findByUserId(1796L)).thenReturn(userDTOForMT);
|
|
|
+ when(groupService.checkUserExist(1796L, 1L)).thenReturn(true);
|
|
|
+ when(groupService.deleteUserFromGroup(1796L, 1L)).thenReturn(user);
|
|
|
+ when(groupPermissionService.deleteWorkerPermission(1796L,1L)).thenReturn(anyListOf(GroupPermission.class));
|
|
|
+ //action
|
|
|
+ UserVO result = groupLogic.deleteUserFromGroup(1796L,1L);
|
|
|
+ //assert
|
|
|
+ Assert.assertEquals(user.getId(),result.getId());
|
|
|
+ Assert.assertEquals("",result.getPassword());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_returnGroupVO_when_updateGroupAllowJoin(){
|
|
|
+ //arrange
|
|
|
+ group.setAllowJoin(false);
|
|
|
+ when(groupService.getGroup(1L)).thenReturn(group);
|
|
|
+ when(groupService.save(group)).thenReturn(group);
|
|
|
+ //action
|
|
|
+ GroupVO result = groupLogic.updateAllowJoin(1L);
|
|
|
+ //assert
|
|
|
+ Assert.assertEquals(true,result.getAllowJoin());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_returnGroupVO_when_updateGroupActive(){
|
|
|
+ //arrange
|
|
|
+ group.setIsActive(false);
|
|
|
+ when(groupService.getGroup(1L)).thenReturn(group);
|
|
|
+ when(groupService.save(group)).thenReturn(group);
|
|
|
+ //action
|
|
|
+ GroupVO result = groupLogic.updateGroupActive(1L);
|
|
|
+ //assert
|
|
|
+ Assert.assertEquals(false,result.getIsActive());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_returnUserTotalCount_when_givenManagerId(){
|
|
|
+ //arrange
|
|
|
+ when(groupService.getUserTotalCount(7L)).thenReturn(12);
|
|
|
+ //action
|
|
|
+ int result = groupLogic.getUserTotalCount(7L);
|
|
|
+ //assert
|
|
|
+ Assert.assertEquals(12,result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_returnManagerGroupSize_when_givenManagerId(){
|
|
|
+ //arrange
|
|
|
+ ManagerProperty managerProperty = new ManagerProperty();
|
|
|
+ managerProperty.setGroupSize(12);
|
|
|
+ when(managerPropertyService.getManagerPropertyByUserId(7L)).thenReturn(managerProperty);
|
|
|
+ //action
|
|
|
+ int result = groupLogic.getManagerGroupSize(7L);
|
|
|
+ //assert
|
|
|
+ Assert.assertEquals(12,result);
|
|
|
+ }
|
|
|
}
|