Skip to content

Commit

Permalink
LPS-112495 Test most viewed assets info list provider
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-savinov authored and david-gutierrez-mesa committed Apr 29, 2020
1 parent 3263bfc commit ff39562
Showing 1 changed file with 83 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.asset.kernel.model.AssetEntry;
import com.liferay.asset.kernel.service.AssetEntryLocalService;
import com.liferay.info.list.provider.DefaultInfoListProviderContext;
import com.liferay.info.list.provider.InfoListProvider;
import com.liferay.info.list.provider.InfoListProviderContext;
Expand Down Expand Up @@ -51,26 +52,6 @@
@RunWith(Arquillian.class)
public class AssetInfoListProviderTest {

public static final Accessor<AssetEntry, Long> CLASS_PK_ACCESSOR =
new Accessor<AssetEntry, Long>() {

@Override
public Long get(AssetEntry assetEntry) {
return assetEntry.getClassPK();
}

@Override
public Class<Long> getAttributeClass() {
return Long.class;
}

@Override
public Class<AssetEntry> getTypeClass() {
return AssetEntry.class;
}

};

@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
Expand All @@ -90,7 +71,7 @@ public void setUp() throws Exception {
public void testHighestRatedAssetsInfoListProvider() throws Exception {
InfoListProvider<AssetEntry> infoListProvider =
_infoListProviderTracker.getInfoListProvider(
_HIGHEST_RATES_ASSETS_INFO_LIST_PROVIDER_KEY);
_HIGHEST_RATED_ASSETS_INFO_LIST_PROVIDER_KEY);

JournalArticle article1 = JournalTestUtil.addArticle(
_group.getGroupId(),
Expand All @@ -117,11 +98,11 @@ public void testHighestRatedAssetsInfoListProvider() throws Exception {

Assert.assertEquals(
Long.valueOf(article2.getResourcePrimKey()),
CLASS_PK_ACCESSOR.get(assetEntries.get(0)));
_CLASS_PK_ACCESSOR.get(assetEntries.get(0)));

Assert.assertEquals(
Long.valueOf(article1.getResourcePrimKey()),
CLASS_PK_ACCESSOR.get(assetEntries.get(1)));
_CLASS_PK_ACCESSOR.get(assetEntries.get(1)));

_ratingsEntryLocalService.deleteEntry(
TestPropsValues.getUserId(), JournalArticle.class.getName(),
Expand All @@ -135,17 +116,93 @@ public void testHighestRatedAssetsInfoListProvider() throws Exception {

Assert.assertEquals(
Long.valueOf(article1.getResourcePrimKey()),
CLASS_PK_ACCESSOR.get(assetEntries.get(0)));
_CLASS_PK_ACCESSOR.get(assetEntries.get(0)));

Assert.assertEquals(
Long.valueOf(article2.getResourcePrimKey()),
CLASS_PK_ACCESSOR.get(assetEntries.get(1)));
_CLASS_PK_ACCESSOR.get(assetEntries.get(1)));
}

private static final String _HIGHEST_RATES_ASSETS_INFO_LIST_PROVIDER_KEY =
@Test
public void testMostViewedAssetsInfoListProvider() throws Exception {
InfoListProvider<AssetEntry> infoListProvider =
_infoListProviderTracker.getInfoListProvider(
_MOST_VIEWED_ASSETS_INFO_LIST_PROVIDER_KEY);

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

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

_assetEntryLocalService.incrementViewCounter(
_group.getCompanyId(), TestPropsValues.getUserId(),
JournalArticle.class.getName(), article2.getResourcePrimKey());

List<AssetEntry> assetEntries = infoListProvider.getInfoList(
_infoListProviderContext);

int assetEntriesCount = infoListProvider.getInfoListCount(
_infoListProviderContext);

Assert.assertEquals(2, assetEntriesCount);

Assert.assertEquals(
Long.valueOf(article2.getResourcePrimKey()),
_CLASS_PK_ACCESSOR.get(assetEntries.get(0)));

Assert.assertEquals(
Long.valueOf(article1.getResourcePrimKey()),
_CLASS_PK_ACCESSOR.get(assetEntries.get(1)));

_assetEntryLocalService.incrementViewCounter(
_group.getCompanyId(), TestPropsValues.getUserId(),
JournalArticle.class.getName(), article1.getResourcePrimKey(), 2);

assetEntries = infoListProvider.getInfoList(_infoListProviderContext);

Assert.assertEquals(
Long.valueOf(article1.getResourcePrimKey()),
_CLASS_PK_ACCESSOR.get(assetEntries.get(0)));

Assert.assertEquals(
Long.valueOf(article2.getResourcePrimKey()),
_CLASS_PK_ACCESSOR.get(assetEntries.get(1)));
}

private static final Accessor<AssetEntry, Long> _CLASS_PK_ACCESSOR =
new Accessor<AssetEntry, Long>() {

@Override
public Long get(AssetEntry assetEntry) {
return assetEntry.getClassPK();
}

@Override
public Class<Long> getAttributeClass() {
return Long.class;
}

@Override
public Class<AssetEntry> getTypeClass() {
return AssetEntry.class;
}

};

private static final String _HIGHEST_RATED_ASSETS_INFO_LIST_PROVIDER_KEY =
"com.liferay.asset.internal.info.list.provider." +
"HighestRatedAssetsInfoListProvider";

private static final String _MOST_VIEWED_ASSETS_INFO_LIST_PROVIDER_KEY =
"com.liferay.asset.internal.info.list.provider." +
"MostViewedAssetsInfoListProvider";

@Inject
private AssetEntryLocalService _assetEntryLocalService;

@DeleteAfterTestRun
private Group _group;

Expand Down

0 comments on commit ff39562

Please sign in to comment.