001
014
015 package com.liferay.portal.kernel.test.util;
016
017 import com.liferay.portal.kernel.exception.LoggedExceptionInInitializerError;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.PropsKeys;
021 import com.liferay.portal.kernel.util.PropsUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portal.model.Company;
024 import com.liferay.portal.model.Group;
025 import com.liferay.portal.model.GroupConstants;
026 import com.liferay.portal.model.User;
027 import com.liferay.portal.service.CompanyLocalServiceUtil;
028 import com.liferay.portal.service.GroupLocalServiceUtil;
029 import com.liferay.portal.service.LayoutLocalServiceUtil;
030
031
038 public class TestPropsValues {
039
040 public static final boolean ASSERT_LOGS = GetterUtil.getBoolean(
041 TestPropsUtil.get("assert.logs"));
042
043 public static final String COMPANY_WEB_ID;
044
045 public static final boolean DL_FILE_ENTRY_PROCESSORS_TRIGGER_SYNCHRONOUSLY =
046 GetterUtil.getBoolean(
047 TestPropsUtil.get(
048 "dl.file.entry.processors.trigger.synchronously"));
049
050 public static final int JUNIT_DELAY_FACTOR = GetterUtil.getInteger(
051 TestPropsUtil.get("junit.delay.factor"));
052
053 public static final String PORTAL_URL = TestPropsUtil.get("portal.url");
054
055 public static final String USER_PASSWORD = TestPropsUtil.get(
056 "user.password");
057
058 static {
059 String companyWebId = TestPropsUtil.get("company.web.id");
060
061 try {
062 if (Validator.isNull(companyWebId)) {
063 companyWebId = GetterUtil.getString(
064 PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
065
066 TestPropsUtil.set("company.web.id", companyWebId);
067 }
068 }
069 catch (Exception e) {
070 throw new LoggedExceptionInInitializerError(e);
071 }
072
073 TestPropsUtil.printProperties();
074
075 COMPANY_WEB_ID = companyWebId;
076 }
077
078 public static long getCompanyId() throws PortalException {
079 if (_companyId > 0) {
080 return _companyId;
081 }
082
083 Company company = CompanyLocalServiceUtil.getCompanyByWebId(
084 TestPropsValues.COMPANY_WEB_ID);
085
086 _companyId = company.getCompanyId();
087
088 return _companyId;
089 }
090
091 public static long getGroupId() throws PortalException {
092 if (_groupId > 0) {
093 return _groupId;
094 }
095
096 Group group = GroupLocalServiceUtil.getGroup(
097 getCompanyId(), GroupConstants.GUEST);
098
099 _groupId = group.getGroupId();
100
101 return _groupId;
102 }
103
104 public static long getPlid() throws PortalException {
105 return getPlid(getGroupId());
106 }
107
108 public static long getPlid(long groupId) {
109 if (_plid > 0) {
110 return _plid;
111 }
112
113 _plid = LayoutLocalServiceUtil.getDefaultPlid(groupId);
114
115 return _plid;
116 }
117
118 public static User getUser() throws PortalException {
119 if (_user == null) {
120 _user = UserTestUtil.getAdminUser(getCompanyId());
121 }
122
123 return _user;
124 }
125
126 public static long getUserId() throws PortalException {
127 if (_userId == 0) {
128 User user = getUser();
129
130 if (user != null) {
131 _userId = user.getUserId();
132 }
133 }
134
135 return _userId;
136 }
137
138 private static long _companyId;
139 private static long _groupId;
140 private static long _plid;
141 private static User _user;
142 private static long _userId;
143
144 }