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