diff --git a/modules/apps/asset/asset-list-test/src/testIntegration/java/com/liferay/asset/list/asset/entry/provider/test/AssetListAssetEntryProviderTest.java b/modules/apps/asset/asset-list-test/src/testIntegration/java/com/liferay/asset/list/asset/entry/provider/test/AssetListAssetEntryProviderTest.java index f843377d16680b..3d48d2a49b0309 100644 --- a/modules/apps/asset/asset-list-test/src/testIntegration/java/com/liferay/asset/list/asset/entry/provider/test/AssetListAssetEntryProviderTest.java +++ b/modules/apps/asset/asset-list-test/src/testIntegration/java/com/liferay/asset/list/asset/entry/provider/test/AssetListAssetEntryProviderTest.java @@ -32,7 +32,7 @@ import com.liferay.journal.model.JournalArticle; import com.liferay.journal.test.util.JournalTestUtil; import com.liferay.petra.string.StringPool; -import com.liferay.portal.configuration.test.util.ConfigurationTestUtil; +import com.liferay.portal.configuration.test.util.ConfigurationTemporarySwapper; import com.liferay.portal.kernel.dao.orm.QueryUtil; import com.liferay.portal.kernel.model.Company; import com.liferay.portal.kernel.model.Group; @@ -75,7 +75,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; /** @@ -104,332 +103,379 @@ public void setUp() throws Exception { public void testCombineSegmentsEntriesOfDynamicCollection() throws Exception { - _setCombinedAssetForDynamicCollections(true); - - AssetListEntry assetListEntry = - _assetListEntryLocalService.addAssetListEntry( - RandomTestUtil.randomString(), TestPropsValues.getUserId(), - _group.getGroupId(), RandomTestUtil.randomString(), - AssetListEntryTypeConstants.TYPE_DYNAMIC, null, - _serviceContext); - - User userTest = TestPropsValues.getUser(); - - String userName = "RandomName"; - - User user = UserTestUtil.addUser( - TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), - StringPool.BLANK, userName + "@liferay.com", userName, - LocaleUtil.getDefault(), userName, RandomTestUtil.randomString(), - null, ServiceContextTestUtil.getServiceContext()); - - SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( - _group.getGroupId(), userTest.getFirstName()); - SegmentsEntry segmentsEntry2 = _addSegmentsEntryByFirstName( - _group.getGroupId(), user.getFirstName()); - - JournalArticle journalArticle1 = _addJournalArticle( - new long[0], TestPropsValues.getUserId()); - JournalArticle journalArticle2 = _addJournalArticle( - new long[0], TestPropsValues.getUserId()); - JournalArticle journalArticle3 = _addJournalArticle( - new long[0], user.getUserId()); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry1.getSegmentsEntryId(), - _getTypeSettings(userTest.getFirstName())); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry2.getSegmentsEntryId(), _getTypeSettings(userName)); - - long[] segmentsEntryIds = { - segmentsEntry1.getSegmentsEntryId(), - segmentsEntry2.getSegmentsEntryId() - }; - - _assertAssetListEntryResults( - _assetListAssetEntryProvider.getAssetEntriesInfoPage( - assetListEntry, segmentsEntryIds, null, null, StringPool.BLANK, - StringPool.BLANK, QueryUtil.ALL_POS, QueryUtil.ALL_POS), - 3, _getAssetEntry(journalArticle1), _getAssetEntry(journalArticle2), - _getAssetEntry(journalArticle3)); + try (ConfigurationTemporarySwapper configurationTemporarySwapper = + new ConfigurationTemporarySwapper( + "com.liferay.asset.list.internal.configuration." + + "AssetListConfiguration", + HashMapDictionaryBuilder.put( + "combineAssetsFromAllSegmentsDynamic", true + ).build())) { + + AssetListEntry assetListEntry = + _assetListEntryLocalService.addAssetListEntry( + RandomTestUtil.randomString(), TestPropsValues.getUserId(), + _group.getGroupId(), RandomTestUtil.randomString(), + AssetListEntryTypeConstants.TYPE_DYNAMIC, null, + _serviceContext); + + User userTest = TestPropsValues.getUser(); + + String userName = "RandomName"; + + User user = UserTestUtil.addUser( + TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), + StringPool.BLANK, userName + "@liferay.com", userName, + LocaleUtil.getDefault(), userName, + RandomTestUtil.randomString(), null, + ServiceContextTestUtil.getServiceContext()); + + SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( + _group.getGroupId(), userTest.getFirstName()); + SegmentsEntry segmentsEntry2 = _addSegmentsEntryByFirstName( + _group.getGroupId(), user.getFirstName()); + + JournalArticle journalArticle1 = _addJournalArticle( + new long[0], TestPropsValues.getUserId()); + JournalArticle journalArticle2 = _addJournalArticle( + new long[0], TestPropsValues.getUserId()); + JournalArticle journalArticle3 = _addJournalArticle( + new long[0], user.getUserId()); + + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry1.getSegmentsEntryId(), + _getTypeSettings(userTest.getFirstName())); + + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry2.getSegmentsEntryId(), + _getTypeSettings(userName)); + + long[] segmentsEntryIds = { + segmentsEntry1.getSegmentsEntryId(), + segmentsEntry2.getSegmentsEntryId() + }; + + _assertAssetListEntryResults( + _assetListAssetEntryProvider.getAssetEntriesInfoPage( + assetListEntry, segmentsEntryIds, null, null, + StringPool.BLANK, StringPool.BLANK, QueryUtil.ALL_POS, + QueryUtil.ALL_POS), + 3, _getAssetEntry(journalArticle1), + _getAssetEntry(journalArticle2), + _getAssetEntry(journalArticle3)); + } } @Test public void testCombineSegmentsEntriesOfDynamicCollectionWithCategoryFilter() throws Exception { - _setCombinedAssetForDynamicCollections(true); - - Company company = _companyLocalService.getCompany( - TestPropsValues.getCompanyId()); - - Group globalGroup = company.getGroup(); - - DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure( - globalGroup.getGroupId(), - _portal.getClassNameId(JournalArticle.class), "BASIC-WEB-CONTENT"); - - AssetListEntry assetListEntry = - _assetListEntryLocalService.addAssetListEntry( - RandomTestUtil.randomString(), TestPropsValues.getUserId(), - _group.getGroupId(), RandomTestUtil.randomString(), - AssetListEntryTypeConstants.TYPE_DYNAMIC, - UnicodePropertiesBuilder.create( - true - ).put( - "anyAssetType", - String.valueOf(_portal.getClassNameId(JournalArticle.class)) - ).put( - "anyClassTypeJournalArticleAssetRendererFactory", - ddmStructure.getStructureId() - ).buildString(), - _serviceContext); - - User user = TestPropsValues.getUser(); - - AssetVocabulary globalAssetVocabulary = AssetTestUtil.addVocabulary( - globalGroup.getGroupId()); - - AssetCategory globalAssetCategory = AssetTestUtil.addCategory( - globalGroup.getGroupId(), globalAssetVocabulary.getVocabularyId()); - - long[] assetCategoryIds = {globalAssetCategory.getCategoryId()}; - - _userLocalService.updateAsset( - user.getUserId(), user, assetCategoryIds, null); - - ServiceContext serviceContext = - ServiceContextTestUtil.getServiceContext(); - - serviceContext.setAssetCategoryIds(assetCategoryIds); - - SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( - _group.getGroupId(), user.getFirstName()); - SegmentsEntry segmentsEntry2 = _addSegmentsEntryByCategoryId( - _group.getGroupId(), globalAssetCategory.getCategoryId()); - - JournalArticle journalArticle = _addJournalArticle( - assetCategoryIds, TestPropsValues.getUserId()); - - _addJournalArticle(new long[0], TestPropsValues.getUserId()); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry1.getSegmentsEntryId(), - _getTypeSettings(user.getFirstName())); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry2.getSegmentsEntryId(), - _getTypeSettings(user.getFirstName())); - - long[] segmentsEntryIds = { - segmentsEntry1.getSegmentsEntryId(), - segmentsEntry2.getSegmentsEntryId() - }; - - _assertAssetListEntryResults( - _assetListAssetEntryProvider.getAssetEntriesInfoPage( - assetListEntry, segmentsEntryIds, - new long[][] {{globalAssetCategory.getCategoryId()}}, null, - StringPool.BLANK, StringPool.BLANK, QueryUtil.ALL_POS, - QueryUtil.ALL_POS), - 1, _getAssetEntry(journalArticle)); + try (ConfigurationTemporarySwapper configurationTemporarySwapper = + new ConfigurationTemporarySwapper( + "com.liferay.asset.list.internal.configuration." + + "AssetListConfiguration", + HashMapDictionaryBuilder.put( + "combineAssetsFromAllSegmentsDynamic", true + ).build())) { + + Company company = _companyLocalService.getCompany( + TestPropsValues.getCompanyId()); + + Group globalGroup = company.getGroup(); + + DDMStructure ddmStructure = + _ddmStructureLocalService.fetchStructure( + globalGroup.getGroupId(), + _portal.getClassNameId(JournalArticle.class), + "BASIC-WEB-CONTENT"); + + AssetListEntry assetListEntry = + _assetListEntryLocalService.addAssetListEntry( + RandomTestUtil.randomString(), TestPropsValues.getUserId(), + _group.getGroupId(), RandomTestUtil.randomString(), + AssetListEntryTypeConstants.TYPE_DYNAMIC, + UnicodePropertiesBuilder.create( + true + ).put( + "anyAssetType", + String.valueOf( + _portal.getClassNameId(JournalArticle.class)) + ).put( + "anyClassTypeJournalArticleAssetRendererFactory", + ddmStructure.getStructureId() + ).buildString(), + _serviceContext); + + User user = TestPropsValues.getUser(); + + AssetVocabulary globalAssetVocabulary = AssetTestUtil.addVocabulary( + globalGroup.getGroupId()); + + AssetCategory globalAssetCategory = AssetTestUtil.addCategory( + globalGroup.getGroupId(), + globalAssetVocabulary.getVocabularyId()); + + long[] assetCategoryIds = {globalAssetCategory.getCategoryId()}; + + _userLocalService.updateAsset( + user.getUserId(), user, assetCategoryIds, null); + + ServiceContext serviceContext = + ServiceContextTestUtil.getServiceContext(); + + serviceContext.setAssetCategoryIds(assetCategoryIds); + + SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( + _group.getGroupId(), user.getFirstName()); + SegmentsEntry segmentsEntry2 = _addSegmentsEntryByCategoryId( + _group.getGroupId(), globalAssetCategory.getCategoryId()); + + JournalArticle journalArticle = _addJournalArticle( + assetCategoryIds, TestPropsValues.getUserId()); + + _addJournalArticle(new long[0], TestPropsValues.getUserId()); + + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry1.getSegmentsEntryId(), + _getTypeSettings(user.getFirstName())); + + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry2.getSegmentsEntryId(), + _getTypeSettings(user.getFirstName())); + + long[] segmentsEntryIds = { + segmentsEntry1.getSegmentsEntryId(), + segmentsEntry2.getSegmentsEntryId() + }; + + _assertAssetListEntryResults( + _assetListAssetEntryProvider.getAssetEntriesInfoPage( + assetListEntry, segmentsEntryIds, + new long[][] {{globalAssetCategory.getCategoryId()}}, null, + StringPool.BLANK, StringPool.BLANK, QueryUtil.ALL_POS, + QueryUtil.ALL_POS), + 1, _getAssetEntry(journalArticle)); + } } @Test public void testCombineSegmentsEntriesOfDynamicCollectionWithoutDuplications() throws Exception { - _setCombinedAssetForDynamicCollections(true); - - AssetListEntry assetListEntry = - _assetListEntryLocalService.addAssetListEntry( - RandomTestUtil.randomString(), TestPropsValues.getUserId(), - _group.getGroupId(), RandomTestUtil.randomString(), - AssetListEntryTypeConstants.TYPE_DYNAMIC, null, - _serviceContext); - - User user = TestPropsValues.getUser(); - - SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( - _group.getGroupId(), user.getFirstName()); - SegmentsEntry segmentsEntry2 = _addSegmentsEntryByFirstName( - _group.getGroupId(), user.getFirstName()); - - JournalArticle journalArticle1 = _addJournalArticle( - new long[0], TestPropsValues.getUserId()); - JournalArticle journalArticle2 = _addJournalArticle( - new long[0], TestPropsValues.getUserId()); - JournalArticle journalArticle3 = _addJournalArticle( - new long[0], TestPropsValues.getUserId()); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry1.getSegmentsEntryId(), - _getTypeSettings(user.getFirstName())); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry2.getSegmentsEntryId(), - _getTypeSettings(user.getFirstName())); - - long[] segmentsEntryIds = { - segmentsEntry1.getSegmentsEntryId(), - segmentsEntry2.getSegmentsEntryId() - }; - - _assertAssetListEntryResults( - _assetListAssetEntryProvider.getAssetEntriesInfoPage( - assetListEntry, segmentsEntryIds, null, null, StringPool.BLANK, - StringPool.BLANK, QueryUtil.ALL_POS, QueryUtil.ALL_POS), - 3, _getAssetEntry(journalArticle1), _getAssetEntry(journalArticle2), - _getAssetEntry(journalArticle3)); + try (ConfigurationTemporarySwapper configurationTemporarySwapper = + new ConfigurationTemporarySwapper( + "com.liferay.asset.list.internal.configuration." + + "AssetListConfiguration", + HashMapDictionaryBuilder.put( + "combineAssetsFromAllSegmentsDynamic", true + ).build())) { + + AssetListEntry assetListEntry = + _assetListEntryLocalService.addAssetListEntry( + RandomTestUtil.randomString(), TestPropsValues.getUserId(), + _group.getGroupId(), RandomTestUtil.randomString(), + AssetListEntryTypeConstants.TYPE_DYNAMIC, null, + _serviceContext); + + User user = TestPropsValues.getUser(); + + SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( + _group.getGroupId(), user.getFirstName()); + SegmentsEntry segmentsEntry2 = _addSegmentsEntryByFirstName( + _group.getGroupId(), user.getFirstName()); + + JournalArticle journalArticle1 = _addJournalArticle( + new long[0], TestPropsValues.getUserId()); + JournalArticle journalArticle2 = _addJournalArticle( + new long[0], TestPropsValues.getUserId()); + JournalArticle journalArticle3 = _addJournalArticle( + new long[0], TestPropsValues.getUserId()); + + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry1.getSegmentsEntryId(), + _getTypeSettings(user.getFirstName())); + + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry2.getSegmentsEntryId(), + _getTypeSettings(user.getFirstName())); + + long[] segmentsEntryIds = { + segmentsEntry1.getSegmentsEntryId(), + segmentsEntry2.getSegmentsEntryId() + }; + + _assertAssetListEntryResults( + _assetListAssetEntryProvider.getAssetEntriesInfoPage( + assetListEntry, segmentsEntryIds, null, null, + StringPool.BLANK, StringPool.BLANK, QueryUtil.ALL_POS, + QueryUtil.ALL_POS), + 3, _getAssetEntry(journalArticle1), + _getAssetEntry(journalArticle2), + _getAssetEntry(journalArticle3)); + } } @Test public void testCombineSegmentsEntriesOfManualCollection() throws Exception { - _setCombinedAssetForManualCollections(true); - - AssetListEntry assetListEntry = - _assetListEntryLocalService.addAssetListEntry( - RandomTestUtil.randomString(), TestPropsValues.getUserId(), - _group.getGroupId(), RandomTestUtil.randomString(), - AssetListEntryTypeConstants.TYPE_MANUAL, - ServiceContextTestUtil.getServiceContext(_group.getGroupId())); - - User user = TestPropsValues.getUser(); - - SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( - _group.getGroupId(), user.getFirstName()); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry1.getSegmentsEntryId()); - - JournalArticle journalArticle1 = JournalTestUtil.addArticle( - _group.getGroupId(), - JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); - - AssetEntry assetEntry1 = _getAssetEntry(journalArticle1); + try (ConfigurationTemporarySwapper configurationTemporarySwapper = + new ConfigurationTemporarySwapper( + "com.liferay.asset.list.internal.configuration." + + "AssetListConfiguration", + HashMapDictionaryBuilder.put( + "combineAssetsFromAllSegmentsManual", true + ).build())) { + + AssetListEntry assetListEntry = + _assetListEntryLocalService.addAssetListEntry( + RandomTestUtil.randomString(), TestPropsValues.getUserId(), + _group.getGroupId(), RandomTestUtil.randomString(), + AssetListEntryTypeConstants.TYPE_MANUAL, + ServiceContextTestUtil.getServiceContext( + _group.getGroupId())); + + User user = TestPropsValues.getUser(); + + SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( + _group.getGroupId(), user.getFirstName()); + + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry1.getSegmentsEntryId()); - AssetListTestUtil.addAssetListEntryAssetEntryRel( - _group.getGroupId(), assetEntry1, assetListEntry, - segmentsEntry1.getSegmentsEntryId(), 0); + JournalArticle journalArticle1 = JournalTestUtil.addArticle( + _group.getGroupId(), + JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); - SegmentsEntry segmentsEntry2 = _addSegmentsEntryByLastName( - _group.getGroupId(), user.getLastName()); + AssetEntry assetEntry1 = _getAssetEntry(journalArticle1); - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry2.getSegmentsEntryId()); + AssetListTestUtil.addAssetListEntryAssetEntryRel( + _group.getGroupId(), assetEntry1, assetListEntry, + segmentsEntry1.getSegmentsEntryId(), 0); - JournalArticle journalArticle2 = JournalTestUtil.addArticle( - _group.getGroupId(), - JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); + SegmentsEntry segmentsEntry2 = _addSegmentsEntryByLastName( + _group.getGroupId(), user.getLastName()); - AssetEntry assetEntry2 = _getAssetEntry(journalArticle2); + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry2.getSegmentsEntryId()); - AssetListTestUtil.addAssetListEntryAssetEntryRel( - _group.getGroupId(), assetEntry2, assetListEntry, - segmentsEntry2.getSegmentsEntryId(), 0); + JournalArticle journalArticle2 = JournalTestUtil.addArticle( + _group.getGroupId(), + JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); - JournalArticle journalArticle3 = JournalTestUtil.addArticle( - _group.getGroupId(), - JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); + AssetEntry assetEntry2 = _getAssetEntry(journalArticle2); - AssetEntry assetEntry3 = _getAssetEntry(journalArticle3); + AssetListTestUtil.addAssetListEntryAssetEntryRel( + _group.getGroupId(), assetEntry2, assetListEntry, + segmentsEntry2.getSegmentsEntryId(), 0); - AssetListTestUtil.addAssetListEntryAssetEntryRel( - _group.getGroupId(), assetEntry3, assetListEntry, - segmentsEntry2.getSegmentsEntryId(), 1); + JournalArticle journalArticle3 = JournalTestUtil.addArticle( + _group.getGroupId(), + JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); - InfoPage infoPage = - _assetListAssetEntryProvider.getAssetEntriesInfoPage( - assetListEntry, - new long[] { - segmentsEntry1.getSegmentsEntryId(), - segmentsEntry2.getSegmentsEntryId() - }, - null, null, StringPool.BLANK, StringPool.BLANK, 0, 2); + AssetEntry assetEntry3 = _getAssetEntry(journalArticle3); - Assert.assertEquals(3, infoPage.getTotalCount()); - Assert.assertTrue( - ListUtil.exists( - infoPage.getPageItems(), - assetEntry -> - assetEntry.getEntryId() == assetEntry1.getEntryId())); - Assert.assertTrue( - ListUtil.exists( - infoPage.getPageItems(), - assetEntry -> - assetEntry.getEntryId() == assetEntry2.getEntryId())); - Assert.assertFalse( - ListUtil.exists( - infoPage.getPageItems(), - assetEntry -> - assetEntry.getEntryId() == assetEntry3.getEntryId())); + AssetListTestUtil.addAssetListEntryAssetEntryRel( + _group.getGroupId(), assetEntry3, assetListEntry, + segmentsEntry2.getSegmentsEntryId(), 1); + + InfoPage infoPage = + _assetListAssetEntryProvider.getAssetEntriesInfoPage( + assetListEntry, + new long[] { + segmentsEntry1.getSegmentsEntryId(), + segmentsEntry2.getSegmentsEntryId() + }, + null, null, StringPool.BLANK, StringPool.BLANK, 0, 2); + + Assert.assertEquals(3, infoPage.getTotalCount()); + Assert.assertTrue( + ListUtil.exists( + infoPage.getPageItems(), + assetEntry -> + assetEntry.getEntryId() == assetEntry1.getEntryId())); + Assert.assertTrue( + ListUtil.exists( + infoPage.getPageItems(), + assetEntry -> + assetEntry.getEntryId() == assetEntry2.getEntryId())); + Assert.assertFalse( + ListUtil.exists( + infoPage.getPageItems(), + assetEntry -> + assetEntry.getEntryId() == assetEntry3.getEntryId())); + } } @Test public void testCombineSegmentsEntriesOfManualCollectionWithoutDuplications() throws Exception { - _setCombinedAssetForManualCollections(true); - - AssetListEntry assetListEntry = - _assetListEntryLocalService.addAssetListEntry( - RandomTestUtil.randomString(), TestPropsValues.getUserId(), - _group.getGroupId(), RandomTestUtil.randomString(), - AssetListEntryTypeConstants.TYPE_MANUAL, - ServiceContextTestUtil.getServiceContext(_group.getGroupId())); - - User user = TestPropsValues.getUser(); - - SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( - _group.getGroupId(), user.getFirstName()); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry1.getSegmentsEntryId()); - - SegmentsEntry segmentsEntry2 = _addSegmentsEntryByLastName( - _group.getGroupId(), user.getLastName()); - - AssetListTestUtil.addAssetListEntrySegmentsEntryRel( - _group.getGroupId(), assetListEntry, - segmentsEntry2.getSegmentsEntryId()); - - for (int i = 0; i < 4; i++) { - JournalArticle journalArticle = JournalTestUtil.addArticle( - _group.getGroupId(), - JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); + try (ConfigurationTemporarySwapper configurationTemporarySwapper = + new ConfigurationTemporarySwapper( + "com.liferay.asset.list.internal.configuration." + + "AssetListConfiguration", + HashMapDictionaryBuilder.put( + "combineAssetsFromAllSegmentsManual", true + ).build())) { + + AssetListEntry assetListEntry = + _assetListEntryLocalService.addAssetListEntry( + RandomTestUtil.randomString(), TestPropsValues.getUserId(), + _group.getGroupId(), RandomTestUtil.randomString(), + AssetListEntryTypeConstants.TYPE_MANUAL, + ServiceContextTestUtil.getServiceContext( + _group.getGroupId())); + + User user = TestPropsValues.getUser(); + + SegmentsEntry segmentsEntry1 = _addSegmentsEntryByFirstName( + _group.getGroupId(), user.getFirstName()); + + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, + segmentsEntry1.getSegmentsEntryId()); - AssetEntry assetEntry = _getAssetEntry(journalArticle); + SegmentsEntry segmentsEntry2 = _addSegmentsEntryByLastName( + _group.getGroupId(), user.getLastName()); - AssetListTestUtil.addAssetListEntryAssetEntryRel( - _group.getGroupId(), assetEntry, assetListEntry, - segmentsEntry1.getSegmentsEntryId()); - AssetListTestUtil.addAssetListEntryAssetEntryRel( - _group.getGroupId(), assetEntry, assetListEntry, + AssetListTestUtil.addAssetListEntrySegmentsEntryRel( + _group.getGroupId(), assetListEntry, segmentsEntry2.getSegmentsEntryId()); - } - _assertAssetListEntryResults( - _assetListAssetEntryProvider.getAssetEntriesInfoPage( - assetListEntry, - new long[] { - segmentsEntry1.getSegmentsEntryId(), - segmentsEntry2.getSegmentsEntryId() - }, - null, null, StringPool.BLANK, StringPool.BLANK, - QueryUtil.ALL_POS, QueryUtil.ALL_POS), - 4); + for (int i = 0; i < 4; i++) { + JournalArticle journalArticle = JournalTestUtil.addArticle( + _group.getGroupId(), + JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); + + AssetEntry assetEntry = _getAssetEntry(journalArticle); + + AssetListTestUtil.addAssetListEntryAssetEntryRel( + _group.getGroupId(), assetEntry, assetListEntry, + segmentsEntry1.getSegmentsEntryId()); + AssetListTestUtil.addAssetListEntryAssetEntryRel( + _group.getGroupId(), assetEntry, assetListEntry, + segmentsEntry2.getSegmentsEntryId()); + } + + _assertAssetListEntryResults( + _assetListAssetEntryProvider.getAssetEntriesInfoPage( + assetListEntry, + new long[] { + segmentsEntry1.getSegmentsEntryId(), + segmentsEntry2.getSegmentsEntryId() + }, + null, null, StringPool.BLANK, StringPool.BLANK, + QueryUtil.ALL_POS, QueryUtil.ALL_POS), + 4); + } } @Test @@ -1574,8 +1620,6 @@ public void testGetManualAssetEntriesWithSegmentsEntryPrioritized() public void testNotCombineSegmentsEntriesOfDynamicCollection() throws Exception { - _setCombinedAssetForDynamicCollections(false); - AssetListEntry assetListEntry = _assetListEntryLocalService.addAssetListEntry( RandomTestUtil.randomString(), TestPropsValues.getUserId(), @@ -1631,8 +1675,6 @@ public void testNotCombineSegmentsEntriesOfDynamicCollection() public void testNotCombineSegmentsEntriesOfManualCollection() throws Exception { - _setCombinedAssetForManualCollections(false); - AssetListEntry assetListEntry = _assetListEntryLocalService.addAssetListEntry( RandomTestUtil.randomString(), TestPropsValues.getUserId(), @@ -1873,40 +1915,6 @@ private String _getTypeSettings(String queryValue) { ).buildString(); } - private void _setCombinedAssetForDynamicCollections(boolean active) - throws Exception { - - _assetListAssetEntryConfiguration = - _configurationAdmin.getConfiguration( - "com.liferay.asset.list.internal.configuration." + - "AssetListConfiguration", - StringPool.QUESTION); - - ConfigurationTestUtil.saveConfiguration( - _assetListAssetEntryConfiguration, - HashMapDictionaryBuilder.put( - "combineAssetsFromAllSegmentsDynamic", active - ).build()); - } - - private void _setCombinedAssetForManualCollections(boolean active) - throws Exception { - - _assetListAssetEntryConfiguration = - _configurationAdmin.getConfiguration( - "com.liferay.asset.list.internal.configuration." + - "AssetListConfiguration", - StringPool.QUESTION); - - ConfigurationTestUtil.saveConfiguration( - _assetListAssetEntryConfiguration, - HashMapDictionaryBuilder.put( - "combineAssetsFromAllSegmentsManual", active - ).build()); - } - - private static Configuration _assetListAssetEntryConfiguration; - @Inject private static ConfigurationAdmin _configurationAdmin;