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.portlet.layoutsadmin.util.test;
016    
017    import com.liferay.portal.kernel.lar.exportimportconfiguration.ExportImportConfigurationSettingsMapFactory;
018    import com.liferay.portal.model.ExportImportConfiguration;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.service.ExportImportConfigurationLocalServiceUtil;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.service.UserLocalServiceUtil;
023    import com.liferay.portal.util.test.RandomTestUtil;
024    import com.liferay.portal.util.test.ServiceContextTestUtil;
025    import com.liferay.portal.util.test.TestPropsValues;
026    
027    import java.io.Serializable;
028    
029    import java.util.Date;
030    import java.util.Map;
031    
032    /**
033     * @author Daniel Kocsis
034     */
035    public class ExportImportConfigurationTestUtil {
036    
037            public static ExportImportConfiguration addExportImportConfiguration(
038                            long groupId, int type)
039                    throws Exception {
040    
041                    Map<String, Serializable> settingsMap = getDefaultSettingsMap(
042                            TestPropsValues.getUserId(), groupId);
043    
044                    return addExportImportConfiguration(groupId, type, settingsMap);
045            }
046    
047            public static ExportImportConfiguration addExportImportConfiguration(
048                            long groupId, int type, Map<String, Serializable> settingsMap)
049                    throws Exception {
050    
051                    ServiceContext serviceContext =
052                            ServiceContextTestUtil.getServiceContext(groupId);
053    
054                    return ExportImportConfigurationLocalServiceUtil.
055                            addExportImportConfiguration(
056                                    TestPropsValues.getUserId(), groupId,
057                                    RandomTestUtil.randomString(), RandomTestUtil.randomString(),
058                                    type, settingsMap, serviceContext);
059            }
060    
061            public static Map<String, Serializable> getDefaultSettingsMap(
062                            long userId, long groupId)
063                    throws Exception {
064    
065                    User user = UserLocalServiceUtil.getUser(userId);
066    
067                    Date startDate = new Date();
068    
069                    Date endDate = startDate;
070    
071                    return ExportImportConfigurationSettingsMapFactory.buildSettingsMap(
072                            userId, groupId, groupId, false, null, null, startDate, endDate,
073                            user.getLocale(), user.getTimeZone());
074            }
075    
076    }