001
014
015 package com.liferay.portlet.ratings.util.test;
016
017 import com.liferay.counter.service.CounterLocalServiceUtil;
018 import com.liferay.portal.kernel.test.util.RandomTestUtil;
019 import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
020 import com.liferay.portal.kernel.test.util.TestPropsValues;
021 import com.liferay.portlet.ratings.model.RatingsEntry;
022 import com.liferay.portlet.ratings.model.RatingsStats;
023 import com.liferay.portlet.ratings.service.RatingsEntryLocalServiceUtil;
024 import com.liferay.portlet.ratings.service.RatingsStatsLocalServiceUtil;
025
026
029 public class RatingsTestUtil {
030
031 public static RatingsEntry addEntry(String className, long classPK)
032 throws Exception {
033
034 return addEntry(className, classPK, 1.0d, TestPropsValues.getUserId());
035 }
036
037 public static RatingsEntry addEntry(
038 String className, long classPK, double score, long userId)
039 throws Exception {
040
041 return RatingsEntryLocalServiceUtil.updateEntry(
042 userId, className, classPK, score,
043 ServiceContextTestUtil.getServiceContext());
044 }
045
046 public static RatingsStats addStats(String className, long classPK)
047 throws Exception {
048
049 return addStats(className, classPK, RandomTestUtil.randomInt());
050 }
051
052 public static RatingsStats addStats(
053 String className, long classPK, double averageScore)
054 throws Exception {
055
056 long statsId = CounterLocalServiceUtil.increment();
057
058 RatingsStats ratingsStats =
059 RatingsStatsLocalServiceUtil.createRatingsStats(statsId);
060
061 ratingsStats.setClassName(className);
062 ratingsStats.setClassPK(classPK);
063 ratingsStats.setTotalEntries(RandomTestUtil.randomInt());
064 ratingsStats.setTotalScore(RandomTestUtil.randomInt());
065 ratingsStats.setAverageScore(averageScore);
066
067 return RatingsStatsLocalServiceUtil.updateRatingsStats(ratingsStats);
068 }
069
070 }