Skip to content

Commit

Permalink
LPD-31485 Migrate segments variation poshit tests to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ealonso authored and brianchandotcom committed Jul 16, 2024
1 parent fbcf7c4 commit fabe5aa
Show file tree
Hide file tree
Showing 2 changed files with 382 additions and 1,276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import com.liferay.asset.list.asset.entry.provider.AssetListAssetEntryProvider;
import com.liferay.asset.list.constants.AssetListEntryTypeConstants;
import com.liferay.asset.list.model.AssetListEntry;
import com.liferay.asset.list.model.AssetListEntrySegmentsEntryRel;
import com.liferay.asset.list.service.AssetListEntryLocalService;
import com.liferay.asset.list.service.AssetListEntrySegmentsEntryRelLocalService;
import com.liferay.asset.list.test.util.AssetListTestUtil;
import com.liferay.asset.publisher.util.AssetQueryRule;
import com.liferay.asset.test.util.AssetTestUtil;
Expand Down Expand Up @@ -961,6 +963,134 @@ public void testGetDynamicAssetEntriesWithMultipleClassNameIds()
3);
}

@Test
public void testGetDynamicAssetEntriesWithSegmentsEntryNotPrioritized()
throws Exception {

AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(
_group.getGroupId());

AssetCategory assetCategory1 = AssetTestUtil.addCategory(
_group.getGroupId(), assetVocabulary.getVocabularyId());

JournalArticle journalArticle = _addJournalArticle(
new long[] {assetCategory1.getCategoryId()});

AssetCategory assetCategory2 = AssetTestUtil.addCategory(
_group.getGroupId(), assetVocabulary.getVocabularyId());

_addJournalArticle(new long[] {assetCategory2.getCategoryId()});

AssetListEntry assetListEntry =
_assetListEntryLocalService.addAssetListEntry(
RandomTestUtil.randomString(), TestPropsValues.getUserId(),
_group.getGroupId(), RandomTestUtil.randomString(),
AssetListEntryTypeConstants.TYPE_DYNAMIC,
_getTypeSettings(
new AssetQueryRule(
true, false, "assetCategories",
new String[] {
String.valueOf(assetCategory1.getCategoryId())
})),
_serviceContext);

User user = TestPropsValues.getUser();

SegmentsEntry segmentsEntry = _addSegmentsEntryByLastName(
_group.getGroupId(), user.getLastName());

AssetListTestUtil.addAssetListEntrySegmentsEntryRel(
_group.getGroupId(), assetListEntry,
segmentsEntry.getSegmentsEntryId(),
_getTypeSettings(
new AssetQueryRule(
true, false, "assetCategories",
new String[] {
String.valueOf(assetCategory2.getCategoryId())
})));

_assertAssetListEntryResults(
_assetListAssetEntryProvider.getAssetEntriesInfoPage(
assetListEntry,
new long[] {
SegmentsEntryConstants.ID_DEFAULT,
segmentsEntry.getSegmentsEntryId()
},
new long[0][], null, StringPool.BLANK,
String.valueOf(TestPropsValues.getUserId()), QueryUtil.ALL_POS,
QueryUtil.ALL_POS),
1, _getAssetEntry(journalArticle));
}

@Test
public void testGetDynamicAssetEntriesWithSegmentsEntryPrioritized()
throws Exception {

AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(
_group.getGroupId());

AssetCategory assetCategory1 = AssetTestUtil.addCategory(
_group.getGroupId(), assetVocabulary.getVocabularyId());

_addJournalArticle(new long[] {assetCategory1.getCategoryId()});

AssetCategory assetCategory2 = AssetTestUtil.addCategory(
_group.getGroupId(), assetVocabulary.getVocabularyId());

JournalArticle journalArticle = _addJournalArticle(
new long[] {assetCategory2.getCategoryId()});

AssetListEntry assetListEntry =
_assetListEntryLocalService.addAssetListEntry(
RandomTestUtil.randomString(), TestPropsValues.getUserId(),
_group.getGroupId(), RandomTestUtil.randomString(),
AssetListEntryTypeConstants.TYPE_DYNAMIC,
_getTypeSettings(
new AssetQueryRule(
true, false, "assetCategories",
new String[] {
String.valueOf(assetCategory1.getCategoryId())
})),
_serviceContext);

User user = TestPropsValues.getUser();

SegmentsEntry segmentsEntry = _addSegmentsEntryByLastName(
_group.getGroupId(), user.getLastName());

AssetListTestUtil.addAssetListEntrySegmentsEntryRel(
_group.getGroupId(), assetListEntry,
segmentsEntry.getSegmentsEntryId(),
_getTypeSettings(
new AssetQueryRule(
true, false, "assetCategories",
new String[] {
String.valueOf(assetCategory2.getCategoryId())
})));

_assetListEntrySegmentsEntryRelLocalService.updateVariationsPriority(
new long[] {
_getAssetListEntrySegmentsEntryRelId(
assetListEntry.getAssetListEntryId(),
segmentsEntry.getSegmentsEntryId()),
_getAssetListEntrySegmentsEntryRelId(
assetListEntry.getAssetListEntryId(),
SegmentsEntryConstants.ID_DEFAULT)
});

_assertAssetListEntryResults(
_assetListAssetEntryProvider.getAssetEntriesInfoPage(
assetListEntry,
new long[] {
SegmentsEntryConstants.ID_DEFAULT,
segmentsEntry.getSegmentsEntryId()
},
new long[0][], null, StringPool.BLANK,
String.valueOf(TestPropsValues.getUserId()), QueryUtil.ALL_POS,
QueryUtil.ALL_POS),
1, _getAssetEntry(journalArticle));
}

@Test
public void testGetManualAssetEntries() throws Exception {
JournalArticle journalArticle1 = JournalTestUtil.addArticle(
Expand Down Expand Up @@ -1300,6 +1430,146 @@ public void testGetManualAssetEntriesNonmatchingAssetCategory()
0);
}

@Test
public void testGetManualAssetEntriesWithSegmentsEntryNotPrioritized()
throws Exception {

JournalArticle journalArticle1 = JournalTestUtil.addArticle(
_group.getGroupId(),
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

AssetListEntry assetListEntry =
_assetListEntryLocalService.addAssetListEntry(
RandomTestUtil.randomString(), TestPropsValues.getUserId(),
_group.getGroupId(), RandomTestUtil.randomString(),
AssetListEntryTypeConstants.TYPE_MANUAL, _serviceContext);

AssetEntry assetEntry1 = _getAssetEntry(journalArticle1);

_assetListEntryLocalService.addAssetEntrySelections(
assetListEntry.getAssetListEntryId(),
new long[] {assetEntry1.getEntryId()},
SegmentsEntryConstants.ID_DEFAULT, _serviceContext);

User user = TestPropsValues.getUser();

SegmentsEntry segmentsEntry = _addSegmentsEntryByLastName(
_group.getGroupId(), user.getLastName());

AssetListTestUtil.addAssetListEntrySegmentsEntryRel(
_group.getGroupId(), assetListEntry,
segmentsEntry.getSegmentsEntryId(), null);

JournalArticle journalArticle2 = JournalTestUtil.addArticle(
_group.getGroupId(),
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

AssetEntry assetEntry2 = _getAssetEntry(journalArticle2);

_assetListEntryLocalService.addAssetEntrySelections(
assetListEntry.getAssetListEntryId(),
new long[] {assetEntry2.getEntryId()},
segmentsEntry.getSegmentsEntryId(), _serviceContext);

_assertAssetListEntryResults(
_assetListAssetEntryProvider.getAssetEntriesInfoPage(
assetListEntry,
new long[] {
SegmentsEntryConstants.ID_DEFAULT,
segmentsEntry.getSegmentsEntryId()
},
new long[0][], null, StringPool.BLANK,
String.valueOf(TestPropsValues.getUserId()), QueryUtil.ALL_POS,
QueryUtil.ALL_POS),
1, assetEntry1);
}

@Test
public void testGetManualAssetEntriesWithSegmentsEntryPrioritized()
throws Exception {

JournalArticle journalArticle1 = JournalTestUtil.addArticle(
_group.getGroupId(),
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

AssetListEntry assetListEntry =
_assetListEntryLocalService.addAssetListEntry(
RandomTestUtil.randomString(), TestPropsValues.getUserId(),
_group.getGroupId(), RandomTestUtil.randomString(),
AssetListEntryTypeConstants.TYPE_MANUAL, _serviceContext);

AssetEntry assetEntry1 = _getAssetEntry(journalArticle1);

_assetListEntryLocalService.addAssetEntrySelections(
assetListEntry.getAssetListEntryId(),
new long[] {assetEntry1.getEntryId()},
SegmentsEntryConstants.ID_DEFAULT, _serviceContext);

User user = TestPropsValues.getUser();

SegmentsEntry segmentsEntry1 = _addSegmentsEntryByLastName(
_group.getGroupId(), user.getLastName());

AssetListTestUtil.addAssetListEntrySegmentsEntryRel(
_group.getGroupId(), assetListEntry,
segmentsEntry1.getSegmentsEntryId(), null);

JournalArticle journalArticle2 = JournalTestUtil.addArticle(
_group.getGroupId(),
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

AssetEntry assetEntry2 = _getAssetEntry(journalArticle2);

_assetListEntryLocalService.addAssetEntrySelections(
assetListEntry.getAssetListEntryId(),
new long[] {assetEntry2.getEntryId()},
segmentsEntry1.getSegmentsEntryId(), _serviceContext);

SegmentsEntry segmentsEntry2 = _addSegmentsEntryByFirstName(
_group.getGroupId(), user.getFirstName());

AssetListTestUtil.addAssetListEntrySegmentsEntryRel(
_group.getGroupId(), assetListEntry,
segmentsEntry2.getSegmentsEntryId(), null);

JournalArticle journalArticle3 = JournalTestUtil.addArticle(
_group.getGroupId(),
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

AssetEntry assetEntry3 = _getAssetEntry(journalArticle3);

_assetListEntryLocalService.addAssetEntrySelections(
assetListEntry.getAssetListEntryId(),
new long[] {assetEntry3.getEntryId()},
segmentsEntry2.getSegmentsEntryId(), _serviceContext);

_assetListEntrySegmentsEntryRelLocalService.updateVariationsPriority(
new long[] {
_getAssetListEntrySegmentsEntryRelId(
assetListEntry.getAssetListEntryId(),
segmentsEntry2.getSegmentsEntryId()),
_getAssetListEntrySegmentsEntryRelId(
assetListEntry.getAssetListEntryId(),
segmentsEntry1.getSegmentsEntryId()),
_getAssetListEntrySegmentsEntryRelId(
assetListEntry.getAssetListEntryId(),
SegmentsEntryConstants.ID_DEFAULT)
});

_assertAssetListEntryResults(
_assetListAssetEntryProvider.getAssetEntriesInfoPage(
assetListEntry,
new long[] {
SegmentsEntryConstants.ID_DEFAULT,
segmentsEntry1.getSegmentsEntryId(),
segmentsEntry2.getSegmentsEntryId()
},
new long[0][], null, StringPool.BLANK,
String.valueOf(TestPropsValues.getUserId()), QueryUtil.ALL_POS,
QueryUtil.ALL_POS),
1, assetEntry3);
}

@Test
public void testNotCombineSegmentsEntriesOfDynamicCollection()
throws Exception {
Expand Down Expand Up @@ -1523,6 +1793,18 @@ private AssetEntry _getAssetEntry(JournalArticle journalArticle)
journalArticle.getResourcePrimKey());
}

private long _getAssetListEntrySegmentsEntryRelId(
long assetListEntryId, long segmentsEntryId) {

AssetListEntrySegmentsEntryRel assetListEntrySegmentsEntryRel =
_assetListEntrySegmentsEntryRelLocalService.
fetchAssetListEntrySegmentsEntryRel(
assetListEntryId, segmentsEntryId);

return assetListEntrySegmentsEntryRel.
getAssetListEntrySegmentsEntryRelId();
}

private String _getTypeSettings(AssetQueryRule... assetQueryRules) {
UnicodeProperties unicodeProperties = UnicodePropertiesBuilder.create(
true
Expand Down Expand Up @@ -1634,6 +1916,10 @@ private void _setCombinedAssetForManualCollections(boolean active)
@Inject
private AssetListEntryLocalService _assetListEntryLocalService;

@Inject
private AssetListEntrySegmentsEntryRelLocalService
_assetListEntrySegmentsEntryRelLocalService;

@Inject
private BlogsEntryLocalService _blogsEntryLocalService;

Expand Down
Loading

0 comments on commit fabe5aa

Please sign in to comment.