@Test
public void test51assignPermissionToUser() {

	XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
	XXUserPermissionDao xXUserPermissionDao= Mockito.mock(XXUserPermissionDao.class);
	XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
	VXPortalUser vXPortalUser = userProfile();
	Collection<String> userRoleList = new ArrayList<String>();
	userRoleList.add("ROLE_USER");
	vXPortalUser.setUserRoleList(userRoleList);
	VXUser vxUser = vxUser();
	XXUser xXUser = xxUser(vxUser);
	List<XXModuleDef> xXModuleDefs = xxModuleDefs();
	VXUserPermission userPermission = vxUserPermission();
	List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
	userPermList.add(userPermission);
	List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
	XXUserPermission xUserPermissionObj = xxUserPermission();
	xUserPermissionObj.setModuleId(userPermission.getModuleId());
	xUserPermissionObj.setUserId(userPermission.getUserId());
	xUserPermissionsList.add(xUserPermissionObj);
	Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
	Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
	Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
	Mockito.when(xXUserPermissionDao.findByModuleIdAndPortalUserId(vXPortalUser.getId(),xXModuleDefs.get(0).getId())).thenReturn(xUserPermissionObj);
	Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
	Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
	UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
	Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
	userSessions.add(userSession);
	Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
	Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
	Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
	Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
	xUserMgr.assignPermissionToUser(vXPortalUser,true);
	userRoleList.clear();
	userRoleList.add("ROLE_SYS_ADMIN");
	vXPortalUser.setUserRoleList(userRoleList);
	xUserMgr.assignPermissionToUser(vXPortalUser,true);
	userRoleList.clear();
	userRoleList.add("ROLE_KEY_ADMIN");
	vXPortalUser.setUserRoleList(userRoleList);
	xUserMgr.assignPermissionToUser(vXPortalUser,true);
	userRoleList.clear();
	userRoleList.add("ROLE_KEY_ADMIN_AUDITOR");
	vXPortalUser.setUserRoleList(userRoleList);
	xUserMgr.assignPermissionToUser(vXPortalUser,true);
	userRoleList.clear();
	userRoleList.add("ROLE_ADMIN_AUDITOR");
	vXPortalUser.setUserRoleList(userRoleList);
	xUserMgr.assignPermissionToUser(vXPortalUser,true);
	Assert.assertNotNull(xXModuleDefs);
}