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.lar.test;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun;
019    import com.liferay.portal.kernel.test.util.GroupTestUtil;
020    import com.liferay.portal.kernel.util.FileUtil;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.model.Layout;
023    import com.liferay.portal.model.StagedModel;
024    import com.liferay.portal.service.LayoutLocalServiceUtil;
025    import com.liferay.portal.service.ServiceContext;
026    import com.liferay.portal.util.test.LayoutTestUtil;
027    import com.liferay.portlet.exportimport.lar.PortletDataHandlerBoolean;
028    import com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys;
029    
030    import java.io.File;
031    
032    import java.util.Date;
033    import java.util.LinkedHashMap;
034    import java.util.Map;
035    
036    import org.junit.After;
037    import org.junit.Before;
038    
039    /**
040     * @author Eduardo Garcia
041     */
042    public class BaseExportImportTestCase {
043    
044            @Before
045            public void setUp() throws Exception {
046                    group = GroupTestUtil.addGroup();
047                    importedGroup = GroupTestUtil.addGroup();
048    
049                    layout = LayoutTestUtil.addLayout(group);
050    
051                    // Delete and readd to ensure a different layout ID (not ID or UUID).
052                    // See LPS-32132.
053    
054                    LayoutLocalServiceUtil.deleteLayout(layout, true, new ServiceContext());
055    
056                    layout = LayoutTestUtil.addLayout(group);
057            }
058    
059            @After
060            public void tearDown() throws Exception {
061                    if ((larFile != null) && larFile.exists()) {
062                            FileUtil.delete(larFile);
063                    }
064            }
065    
066            protected void addParameter(
067                    Map<String, String[]> parameterMap, String name, String value) {
068    
069                    parameterMap.put(name, new String[] {value});
070            }
071    
072            protected void addParameter(
073                    Map<String, String[]> parameterMap, String namespace, String name,
074                    boolean value) {
075    
076                    PortletDataHandlerBoolean portletDataHandlerBoolean =
077                            new PortletDataHandlerBoolean(namespace, name);
078    
079                    addParameter(
080                            parameterMap, portletDataHandlerBoolean.getNamespacedControlName(),
081                            String.valueOf(value));
082            }
083    
084            protected StagedModel addStagedModel(long groupId) throws Exception {
085                    return null;
086            }
087    
088            protected StagedModel addStagedModel(long groupId, Date createdDate)
089                    throws Exception {
090    
091                    return null;
092            }
093    
094            protected void deleteStagedModel(StagedModel stagedModel) throws Exception {
095            }
096    
097            protected Map<String, String[]> getExportParameterMap() throws Exception {
098                    Map<String, String[]> parameterMap = new LinkedHashMap<>();
099    
100                    parameterMap.put(
101                            PortletDataHandlerKeys.PORTLET_CONFIGURATION,
102                            new String[] {Boolean.TRUE.toString()});
103                    parameterMap.put(
104                            PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL,
105                            new String[] {Boolean.TRUE.toString()});
106                    parameterMap.put(
107                            PortletDataHandlerKeys.PORTLET_DATA,
108                            new String[] {Boolean.TRUE.toString()});
109                    parameterMap.put(
110                            PortletDataHandlerKeys.PORTLET_DATA_ALL,
111                            new String[] {Boolean.TRUE.toString()});
112                    parameterMap.put(
113                            PortletDataHandlerKeys.PORTLET_SETUP_ALL,
114                            new String[] {Boolean.TRUE.toString()});
115    
116                    return parameterMap;
117            }
118    
119            protected Map<String, String[]> getImportParameterMap() throws Exception {
120                    Map<String, String[]> parameterMap = new LinkedHashMap<>();
121    
122                    parameterMap.put(
123                            PortletDataHandlerKeys.DATA_STRATEGY,
124                            new String[] {
125                                    PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE
126                            });
127                    parameterMap.put(
128                            PortletDataHandlerKeys.PORTLET_CONFIGURATION,
129                            new String[] {Boolean.TRUE.toString()});
130                    parameterMap.put(
131                            PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL,
132                            new String[] {Boolean.TRUE.toString()});
133                    parameterMap.put(
134                            PortletDataHandlerKeys.PORTLET_DATA,
135                            new String[] {Boolean.TRUE.toString()});
136                    parameterMap.put(
137                            PortletDataHandlerKeys.PORTLET_DATA_ALL,
138                            new String[] {Boolean.TRUE.toString()});
139                    parameterMap.put(
140                            PortletDataHandlerKeys.PORTLET_SETUP_ALL,
141                            new String[] {Boolean.TRUE.toString()});
142    
143                    return parameterMap;
144            }
145    
146            @SuppressWarnings("unused")
147            protected StagedModel getStagedModel(String uuid, long groupId)
148                    throws PortalException {
149    
150                    return null;
151            }
152    
153            @SuppressWarnings("unused")
154            protected String getStagedModelUuid(StagedModel stagedModel)
155                    throws PortalException {
156    
157                    return stagedModel.getUuid();
158            }
159    
160            @DeleteAfterTestRun
161            protected Group group;
162    
163            @DeleteAfterTestRun
164            protected Group importedGroup;
165    
166            protected Layout importedLayout;
167            protected File larFile;
168            protected Layout layout;
169    
170    }