001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.Time;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portal.model.Company;
025    import com.liferay.portal.model.Group;
026    import com.liferay.portal.model.GroupConstants;
027    import com.liferay.portal.model.User;
028    import com.liferay.portal.service.CompanyLocalServiceUtil;
029    import com.liferay.portal.service.GroupLocalServiceUtil;
030    import com.liferay.portal.service.LayoutLocalServiceUtil;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     * @author Alexander Chow
035     * @author Raymond Aug??
036     * @author Manuel de la Pe??a
037     * @author Sampsa Sohlman
038     */
039    public class TestPropsValues {
040    
041            public static final boolean ASSERT_LOGS = GetterUtil.getBoolean(
042                    TestPropsUtil.get("assert.logs"));
043    
044            public static final long CI_TEST_TIMEOUT_TIME = GetterUtil.getLong(
045                    TestPropsUtil.get("ci.test.timeout.time"), 40 * Time.MINUTE);
046    
047            public static final String COMPANY_WEB_ID;
048    
049            public static final boolean DL_FILE_ENTRY_PROCESSORS_TRIGGER_SYNCHRONOUSLY =
050                    GetterUtil.getBoolean(
051                            TestPropsUtil.get(
052                                    "dl.file.entry.processors.trigger.synchronously"));
053    
054            public static final int JUNIT_DELAY_FACTOR = GetterUtil.getInteger(
055                    TestPropsUtil.get("junit.delay.factor"));
056    
057            public static final String PORTAL_URL = TestPropsUtil.get("portal.url");
058    
059            public static final String USER_PASSWORD = TestPropsUtil.get(
060                    "user.password");
061    
062            static {
063                    String companyWebId = TestPropsUtil.get("company.web.id");
064    
065                    try {
066                            if (Validator.isNull(companyWebId)) {
067                                    companyWebId = GetterUtil.getString(
068                                            PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
069    
070                                    TestPropsUtil.set("company.web.id", companyWebId);
071                            }
072                    }
073                    catch (Exception e) {
074                            throw new LoggedExceptionInInitializerError(e);
075                    }
076    
077                    TestPropsUtil.printProperties();
078    
079                    COMPANY_WEB_ID = companyWebId;
080            }
081    
082            public static long getCompanyId() throws PortalException {
083                    if (_companyId > 0) {
084                            return _companyId;
085                    }
086    
087                    Company company = CompanyLocalServiceUtil.getCompanyByWebId(
088                            TestPropsValues.COMPANY_WEB_ID);
089    
090                    _companyId = company.getCompanyId();
091    
092                    return _companyId;
093            }
094    
095            public static long getGroupId() throws PortalException {
096                    if (_groupId > 0) {
097                            return _groupId;
098                    }
099    
100                    Group group = GroupLocalServiceUtil.getGroup(
101                            getCompanyId(), GroupConstants.GUEST);
102    
103                    _groupId = group.getGroupId();
104    
105                    return _groupId;
106            }
107    
108            public static long getPlid() throws PortalException {
109                    return getPlid(getGroupId());
110            }
111    
112            public static long getPlid(long groupId) {
113                    if (_plid > 0) {
114                            return _plid;
115                    }
116    
117                    _plid = LayoutLocalServiceUtil.getDefaultPlid(groupId);
118    
119                    return _plid;
120            }
121    
122            public static User getUser() throws PortalException {
123                    if (_user == null) {
124                            _user = UserTestUtil.getAdminUser(getCompanyId());
125                    }
126    
127                    return _user;
128            }
129    
130            public static long getUserId() throws PortalException {
131                    if (_userId == 0) {
132                            User user = getUser();
133    
134                            if (user != null) {
135                                    _userId = user.getUserId();
136                            }
137                    }
138    
139                    return _userId;
140            }
141    
142            private static long _companyId;
143            private static long _groupId;
144            private static long _plid;
145            private static User _user;
146            private static long _userId;
147    
148    }