001
014
015 package com.liferay.portal.kernel.test.util;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.model.Group;
019 import com.liferay.portal.model.User;
020 import com.liferay.portal.service.GroupLocalServiceUtil;
021 import com.liferay.portal.service.ServiceContext;
022
023
026 public class ServiceContextTestUtil {
027
028 public static ServiceContext getServiceContext() throws PortalException {
029 return getServiceContext(TestPropsValues.getGroupId());
030 }
031
032 public static ServiceContext getServiceContext(Group group, long userId) {
033 return getServiceContext(
034 group.getCompanyId(), group.getGroupId(), userId);
035 }
036
037 public static ServiceContext getServiceContext(long groupId)
038 throws PortalException {
039
040 if (groupId == TestPropsValues.getGroupId()) {
041 return getServiceContext(groupId, TestPropsValues.getUserId());
042 }
043 else {
044 Group group = GroupLocalServiceUtil.getGroup(groupId);
045
046 User user = UserTestUtil.getAdminUser(group.getCompanyId());
047
048 return getServiceContext(group, user.getUserId());
049 }
050 }
051
052 public static ServiceContext getServiceContext(long groupId, long userId)
053 throws PortalException {
054
055 if (groupId == TestPropsValues.getGroupId()) {
056 return getServiceContext(
057 TestPropsValues.getCompanyId(), groupId, userId);
058 }
059 else {
060 Group group = GroupLocalServiceUtil.getGroup(groupId);
061
062 return getServiceContext(
063 group.getCompanyId(), group.getGroupId(), userId);
064 }
065 }
066
067 public static ServiceContext getServiceContext(
068 long companyId, long groupId, long userId) {
069
070 ServiceContext serviceContext = new ServiceContext();
071
072 serviceContext.setAddGroupPermissions(true);
073 serviceContext.setAddGuestPermissions(true);
074 serviceContext.setCompanyId(companyId);
075 serviceContext.setScopeGroupId(groupId);
076 serviceContext.setUserId(userId);
077
078 return serviceContext;
079 }
080
081 }