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.dynamicdatamapping.util.test;
016    
017    import com.liferay.portal.kernel.template.TemplateConstants;
018    import com.liferay.portal.kernel.test.util.TestPropsValues;
019    import com.liferay.portal.kernel.util.LocaleUtil;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.dynamicdatamapping.DDMTemplate;
022    import com.liferay.portlet.dynamicdatamapping.DDMTemplateManager;
023    import com.liferay.portlet.dynamicdatamapping.DDMTemplateManagerUtil;
024    
025    import java.util.HashMap;
026    import java.util.Locale;
027    import java.util.Map;
028    
029    /**
030     * @author Eudaldo Alonso
031     * @author Rafael Praxedes
032     */
033    public class DDMTemplateTestUtil {
034    
035            public static DDMTemplate addTemplate(
036                            long groupId, long classNameId, long classPK,
037                            long resourceClassNameId)
038                    throws Exception {
039    
040                    return addTemplate(
041                            groupId, classNameId, classPK, resourceClassNameId,
042                            TemplateConstants.LANG_TYPE_VM, getSampleTemplateXSL(),
043                            LocaleUtil.getSiteDefault());
044            }
045    
046            public static DDMTemplate addTemplate(
047                            long groupId, long classNameId, long classPK,
048                            long resourceClassNameId, String language, String script,
049                            Locale defaultLocale)
050                    throws Exception {
051    
052                    Map<Locale, String> nameMap = new HashMap<>();
053    
054                    nameMap.put(defaultLocale, "Test Template");
055    
056                    ServiceContext serviceContext = new ServiceContext();
057    
058                    serviceContext.setAddGroupPermissions(true);
059                    serviceContext.setAddGuestPermissions(true);
060    
061                    return DDMTemplateManagerUtil.addTemplate(
062                            TestPropsValues.getUserId(), groupId, classNameId, classPK,
063                            resourceClassNameId, null, nameMap, null,
064                            DDMTemplateManager.TEMPLATE_TYPE_DISPLAY, null, language, script,
065                            false, false, null, null, serviceContext);
066            }
067    
068            public static String getSampleTemplateXSL() {
069                    return "$name.getData()";
070            }
071    
072    }