List of usage examples for com.liferay.portal.kernel.test.util ServiceContextTestUtil getServiceContext
public static ServiceContext getServiceContext() throws PortalException
From source file:com.liferay.adaptive.media.journal.internal.exportimport.data.handler.test.AMJournalArticleStagedModelDataHandlerTest.java
License:Open Source License
private JournalArticle _addJournalArticle(String content, ServiceContext serviceContext) throws Exception { DDMForm ddmForm = DDMStructureTestUtil.getSampleDDMForm("content", "string", "text", true, "text_area", new Locale[] { LocaleUtil.getSiteDefault() }, LocaleUtil.getSiteDefault()); DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(stagingGroup.getGroupId(), JournalArticle.class.getName(), "0", ddmForm, LocaleUtil.getSiteDefault(), ServiceContextTestUtil.getServiceContext()); DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(stagingGroup.getGroupId(), PortalUtil.getClassNameId(com.liferay.dynamic.data.mapping.model.DDMStructure.class), ddmStructure.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class)); JournalFolder journalFolder = _journalFolderLocalService.addFolder(serviceContext.getUserId(), serviceContext.getScopeGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(), "This is a test folder.", serviceContext); Map<Locale, String> titleMap = new HashMap<>(); titleMap.put(LocaleUtil.getSiteDefault(), "Test Article"); return _journalArticleLocalService.addArticle(serviceContext.getUserId(), serviceContext.getScopeGroupId(), journalFolder.getFolderId(), JournalArticleConstants.CLASSNAME_ID_DEFAULT, 0, StringPool.BLANK, true, 0, titleMap, null, content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), null, 1, 1, 1965, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false, null, null, null, null, serviceContext);//from www .j av a 2 s . c o m }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testDynamicExportImportAssetCategoryFiltering() throws Exception { AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(group.getGroupId()); AssetCategory assetCategory = AssetTestUtil.addCategory(group.getGroupId(), assetVocabulary.getVocabularyId()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); serviceContext.setAssetCategoryIds(new long[] { assetCategory.getCategoryId() }); List<AssetEntry> expectedAssetEntries = addAssetEntries(group, 2, new ArrayList<AssetEntry>(), serviceContext);/*w ww .j a v a 2s .c om*/ Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("queryContains0", new String[] { "true" }); preferenceMap.put("queryName0", new String[] { "assetCategories" }); preferenceMap.put("queryValues0", new String[] { String.valueOf(assetCategory.getCategoryId()) }); testDynamicExportImport(preferenceMap, expectedAssetEntries, true); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testDynamicExportImportAssetTagFiltering() throws Exception { AssetTag assetTag = AssetTestUtil.addTag(group.getGroupId()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); serviceContext.setAssetTagNames(new String[] { assetTag.getName() }); List<AssetEntry> expectedAssetEntries = addAssetEntries(group, 2, new ArrayList<AssetEntry>(), serviceContext);/* w w w .ja v a2s.c o m*/ Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("queryContains0", new String[] { Boolean.TRUE.toString() }); preferenceMap.put("queryValues0", new String[] { assetTag.getName() }); testDynamicExportImport(preferenceMap, expectedAssetEntries, true); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testDynamicExportImportAssetVocabularyFiltering() throws Exception { AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(group.getGroupId()); AssetCategory assetCategory1 = AssetTestUtil.addCategory(group.getGroupId(), assetVocabulary.getVocabularyId()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); serviceContext.setAssetCategoryIds(new long[] { assetCategory1.getCategoryId() }); List<AssetEntry> expectedAssetEntries = addAssetEntries(group, 1, new ArrayList<AssetEntry>(), serviceContext);//from w w w. j ava 2 s .c o m AssetCategory assetCategory2 = AssetTestUtil.addCategory(group.getGroupId(), assetVocabulary.getVocabularyId()); serviceContext.setAssetCategoryIds(new long[] { assetCategory2.getCategoryId() }); expectedAssetEntries = addAssetEntries(group, 1, expectedAssetEntries, serviceContext); Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("assetVocabularyId", new String[] { String.valueOf(assetVocabulary.getVocabularyId()) }); testDynamicExportImport(preferenceMap, expectedAssetEntries, true); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testDynamicExportImportClassTypeFiltering() throws Exception { List<AssetEntry> expectedAssetEntries = new ArrayList<>(); JournalArticle journalArticle = JournalTestUtil.addArticle(group.getGroupId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(100), ServiceContextTestUtil.getServiceContext()); expectedAssetEntries.add(getAssetEntry(journalArticle)); Map<String, String[]> preferenceMap = new HashMap<>(); long journalArticleClassNameId = PortalUtil.getClassNameId(JournalArticle.class); preferenceMap.put("anyAssetType", new String[] { String.valueOf(journalArticleClassNameId) }); DDMStructure ddmStructure = journalArticle.getDDMStructure(); preferenceMap.put("classTypeIds", new String[] { String.valueOf(ddmStructure.getStructureId()) }); testDynamicExportImport(preferenceMap, expectedAssetEntries, true); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testDynamicExportImportLayoutFiltering() throws Exception { List<AssetEntry> expectedAssetEntries = new ArrayList<>(); Map<Locale, String> titleMap = new HashMap<>(); titleMap.put(LocaleUtil.getDefault(), RandomTestUtil.randomString()); Map<Locale, String> contentMap = new HashMap<>(); contentMap.put(LocaleUtil.getDefault(), RandomTestUtil.randomString(100)); JournalArticle journalArticle = JournalTestUtil.addArticle(group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, JournalArticleConstants.CLASSNAME_ID_DEFAULT, titleMap, titleMap, contentMap, layout.getUuid(), LocaleUtil.getDefault(), null, false, false, ServiceContextTestUtil.getServiceContext()); expectedAssetEntries.add(getAssetEntry(journalArticle)); Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("showOnlyLayoutAssets", new String[] { Boolean.TRUE.toString() }); testDynamicExportImport(preferenceMap, expectedAssetEntries, true); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testDynamicExportImportWithNoFiltering() throws Exception { List<AssetEntry> expectedAssetEntries = addAssetEntries(group, 2, new ArrayList<AssetEntry>(), ServiceContextTestUtil.getServiceContext()); testDynamicExportImport(new HashMap<String, String[]>(), expectedAssetEntries, false); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testOneJournalStructure() throws Exception { DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(group.getGroupId(), JournalArticle.class.getName()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); serviceContext.setUuid(ddmStructure.getUuid()); DDMStructure importedDDMStructure = DDMStructureTestUtil.addStructure(importedGroup.getGroupId(), JournalArticle.class.getName(), 0, ddmStructure.getDDMForm(), LocaleUtil.getDefault(), serviceContext);//from w w w .jav a 2 s . c o m Map<String, String[]> preferenceMap = new HashMap<>(); long journalArticleClassNameId = PortalUtil.getClassNameId(JournalArticle.class); preferenceMap.put("anyAssetType", new String[] { String.valueOf(journalArticleClassNameId) }); preferenceMap.put("anyClassTypeJournalArticleAssetRendererFactory", new String[] { String.valueOf(ddmStructure.getStructureId()) }); preferenceMap.put("classTypeIds", new String[] { String.valueOf(ddmStructure.getStructureId()) }); PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap); long anyClassTypeJournalArticleAssetRendererFactory = GetterUtil .getLong(portletPreferences.getValue("anyClassTypeJournalArticleAssetRendererFactory", null)); Assert.assertEquals(anyClassTypeJournalArticleAssetRendererFactory, importedDDMStructure.getStructureId()); long anyAssetType = GetterUtil.getLong(portletPreferences.getValue("anyAssetType", null)); Assert.assertEquals(journalArticleClassNameId, anyAssetType); long classTypeIds = GetterUtil.getLong(portletPreferences.getValue("classTypeIds", null)); Assert.assertEquals(importedDDMStructure.getStructureId(), classTypeIds); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testSeveralJournalStructures() throws Exception { DDMStructure ddmStructure1 = DDMStructureTestUtil.addStructure(group.getGroupId(), JournalArticle.class.getName()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); serviceContext.setUuid(ddmStructure1.getUuid()); DDMStructure importedDDMStructure1 = DDMStructureTestUtil.addStructure(importedGroup.getGroupId(), JournalArticle.class.getName(), 0, ddmStructure1.getDDMForm(), LocaleUtil.getDefault(), serviceContext);//from w ww . j a v a2s . c om DDMStructure ddmStructure2 = DDMStructureTestUtil.addStructure(group.getGroupId(), JournalArticle.class.getName()); serviceContext.setUuid(ddmStructure2.getUuid()); DDMStructure importedDDMStructure2 = DDMStructureTestUtil.addStructure(importedGroup.getGroupId(), JournalArticle.class.getName(), 0, ddmStructure1.getDDMForm(), LocaleUtil.getDefault(), serviceContext); Map<String, String[]> preferenceMap = new HashMap<>(); long journalArticleClassNameId = PortalUtil.getClassNameId(JournalArticle.class); preferenceMap.put("anyAssetType", new String[] { String.valueOf(journalArticleClassNameId) }); preferenceMap.put("anyClassTypeJournalArticleAssetRendererFactory", new String[] { String.valueOf(Boolean.FALSE) }); preferenceMap.put("classTypeIdsJournalArticleAssetRendererFactory", new String[] { String.valueOf(ddmStructure1.getStructureId()), String.valueOf(ddmStructure2.getStructureId()) }); PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap); Assert.assertEquals( importedDDMStructure1.getStructureId() + StringPool.COMMA + importedDDMStructure2.getStructureId(), StringUtil.merge( portletPreferences.getValues("classTypeIdsJournalArticleAssetRendererFactory", null))); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
protected void testDynamicExportImport(Map<String, String[]> preferenceMap, List<AssetEntry> expectedAssetEntries, boolean filtering) throws Exception { if (filtering) { // Creating entries to validate filtering addAssetEntries(group, 2, new ArrayList<AssetEntry>(), ServiceContextTestUtil.getServiceContext()); }//from w ww . ja v a2s . c om String scopeId = _assetPublisherHelper.getScopeId(group, group.getGroupId()); preferenceMap.put("scopeIds", new String[] { scopeId }); preferenceMap.put("selectionStyle", new String[] { "dynamic" }); PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap); Company company = CompanyLocalServiceUtil.getCompany(TestPropsValues.getCompanyId()); AssetEntryQuery assetEntryQuery = _assetPublisherHelper.getAssetEntryQuery(portletPreferences, importedGroup.getGroupId(), layout, null, null); SearchContainer<AssetEntry> searchContainer = new SearchContainer<>(); searchContainer.setTotal(10); List<AssetEntryResult> actualAssetEntryResults = _assetPublisherHelper.getAssetEntryResults(searchContainer, assetEntryQuery, layout, portletPreferences, StringPool.BLANK, null, null, company.getCompanyId(), importedGroup.getGroupId(), TestPropsValues.getUserId(), assetEntryQuery.getClassNameIds(), null); List<AssetEntry> actualAssetEntries = new ArrayList<>(); for (AssetEntryResult assetEntryResult : actualAssetEntryResults) { actualAssetEntries.addAll(assetEntryResult.getAssetEntries()); } assertAssetEntries(expectedAssetEntries, actualAssetEntries); }