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    
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                    return;
096            }
097    
098            protected Map<String, String[]> getExportParameterMap() throws Exception {
099                    Map<String, String[]> parameterMap =
100                            new LinkedHashMap<String, String[]>();
101    
102                    parameterMap.put(
103                            PortletDataHandlerKeys.PORTLET_CONFIGURATION,
104                            new String[] {Boolean.TRUE.toString()});
105                    parameterMap.put(
106                            PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL,
107                            new String[] {Boolean.TRUE.toString()});
108                    parameterMap.put(
109                            PortletDataHandlerKeys.PORTLET_DATA,
110                            new String[] {Boolean.TRUE.toString()});
111                    parameterMap.put(
112                            PortletDataHandlerKeys.PORTLET_DATA_ALL,
113                            new String[] {Boolean.TRUE.toString()});
114                    parameterMap.put(
115                            PortletDataHandlerKeys.PORTLET_SETUP_ALL,
116                            new String[] {Boolean.TRUE.toString()});
117    
118                    return parameterMap;
119            }
120    
121            protected Map<String, String[]> getImportParameterMap() throws Exception {
122                    Map<String, String[]> parameterMap =
123                            new LinkedHashMap<String, String[]>();
124    
125                    parameterMap.put(
126                            PortletDataHandlerKeys.DATA_STRATEGY,
127                            new String[] {
128                                    PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE});
129                    parameterMap.put(
130                            PortletDataHandlerKeys.PORTLET_CONFIGURATION,
131                            new String[] {Boolean.TRUE.toString()});
132                    parameterMap.put(
133                            PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL,
134                            new String[] {Boolean.TRUE.toString()});
135                    parameterMap.put(
136                            PortletDataHandlerKeys.PORTLET_DATA,
137                            new String[] {Boolean.TRUE.toString()});
138                    parameterMap.put(
139                            PortletDataHandlerKeys.PORTLET_DATA_ALL,
140                            new String[] {Boolean.TRUE.toString()});
141                    parameterMap.put(
142                            PortletDataHandlerKeys.PORTLET_SETUP_ALL,
143                            new String[] {Boolean.TRUE.toString()});
144    
145                    return parameterMap;
146            }
147    
148            @SuppressWarnings("unused")
149            protected StagedModel getStagedModel(String uuid, long groupId)
150                    throws PortalException {
151    
152                    return null;
153            }
154    
155            @SuppressWarnings("unused")
156            protected String getStagedModelUuid(StagedModel stagedModel)
157                    throws PortalException {
158    
159                    return stagedModel.getUuid();
160            }
161    
162            @DeleteAfterTestRun
163            protected Group group;
164    
165            @DeleteAfterTestRun
166            protected Group importedGroup;
167    
168            protected Layout importedLayout;
169            protected File larFile;
170            protected Layout layout;
171    
172    }