Example usage for com.liferay.portal.kernel.test.util RandomTestUtil randomInt

List of usage examples for com.liferay.portal.kernel.test.util RandomTestUtil randomInt

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.test.util RandomTestUtil randomInt.

Prototype

public static int randomInt(int min, int max) 

Source Link

Usage

From source file:com.liferay.calendar.search.test.CalendarBookingIndexerTest.java

License:Open Source License

protected void addCalendarBooking(LocalizedValuesMap titleMap) {
    try {/*from   w  ww . j ava  2s .c  o m*/
        ServiceContext serviceContext = new ServiceContext();

        CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
                serviceContext);

        Calendar calendar = CalendarLocalServiceUtil.addCalendar(_user.getUserId(), _group.getGroupId(),
                calendarResource.getCalendarResourceId(), RandomTestUtil.randomLocaleStringMap(),
                RandomTestUtil.randomLocaleStringMap(), StringPool.UTC, RandomTestUtil.randomInt(0, 255), false,
                false, false, serviceContext);

        long startTime = DateUtil.newTime() + RandomTestUtil.randomInt();

        long endTime = startTime + Time.HOUR;

        HashMap<Locale, String> hashMap = new HashMap<>();

        CalendarBookingLocalServiceUtil.addCalendarBooking(_user.getUserId(), calendar.getCalendarId(),
                new long[0], CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT, 0,
                titleMap.getValues(), hashMap, null, startTime, endTime, false, null, 0, "email", 0, "email",
                serviceContext);
    } catch (PortalException pe) {
        throw new RuntimeException(pe);
    }
}

From source file:com.liferay.calendar.search.test.CalendarFixture.java

License:Open Source License

public Calendar addCalendar(LocalizedValuesMap nameLocalizedValuesMap,
        LocalizedValuesMap descriptionLocalizedValuesMap, ServiceContext serviceContext)
        throws PortalException {

    CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
            serviceContext);/*  w  ww .  ja v a 2 s . c  o m*/

    Calendar calendar = _calendarLocalService.addCalendar(serviceContext.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), nameLocalizedValuesMap.getValues(),
            descriptionLocalizedValuesMap.getValues(), StringPool.UTC, RandomTestUtil.randomInt(0, 255), false,
            false, false, serviceContext);

    _calendars.add(calendar);

    return calendar;
}

From source file:com.liferay.calendar.search.test.CalendarSearcherTest.java

License:Open Source License

protected void addCalendar(String name, String description) throws PortalException {

    ServiceContext serviceContext = new ServiceContext();

    CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
            serviceContext);//from  ww w.  j a va 2 s.c o  m

    Map<Locale, String> nameMap = new HashMap<>();

    nameMap.put(LocaleUtil.getDefault(), name);

    Map<Locale, String> descriptionMap = new HashMap<>();

    descriptionMap.put(LocaleUtil.getDefault(), description);

    CalendarLocalServiceUtil.addCalendar(_user.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), nameMap, descriptionMap, StringPool.UTC,
            RandomTestUtil.randomInt(0, 255), false, false, false, serviceContext);
}

From source file:com.liferay.calendar.service.test.CalendarLocalServiceTest.java

License:Open Source License

@Test
public void testSearch() throws Exception {
    ServiceContext serviceContext = new ServiceContext();

    CalendarResource calendarResource = CalendarResourceUtil.getGroupCalendarResource(_group.getGroupId(),
            serviceContext);/*from  w w  w  .  j  ava 2 s .co  m*/

    Locale locale = LocaleUtil.getDefault();

    Map<Locale, String> nameMap = RandomTestUtil.randomLocaleStringMap(locale);

    Calendar expectedCalendar = CalendarLocalServiceUtil.addCalendar(_user.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), nameMap, RandomTestUtil.randomLocaleStringMap(),
            StringPool.UTC, RandomTestUtil.randomInt(0, 255), false, false, false, serviceContext);

    CalendarLocalServiceUtil.addCalendar(_user.getUserId(), _group.getGroupId(),
            calendarResource.getCalendarResourceId(), RandomTestUtil.randomLocaleStringMap(),
            RandomTestUtil.randomLocaleStringMap(), StringPool.UTC, RandomTestUtil.randomInt(0, 255), false,
            false, false, serviceContext);

    List<Calendar> actualCalendars = CalendarLocalServiceUtil.search(_group.getCompanyId(),
            new long[] { _group.getGroupId() }, new long[] { calendarResource.getCalendarResourceId() },
            nameMap.get(locale), true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new CalendarNameComparator());

    Assert.assertEquals(actualCalendars.toString(), 1, actualCalendars.size());

    Calendar actualCalendar = actualCalendars.get(0);

    Assert.assertEquals(expectedCalendar.getCalendarId(), actualCalendar.getCalendarId());
    Assert.assertEquals(expectedCalendar.getNameMap(), actualCalendar.getNameMap());
}

From source file:com.liferay.calendar.web.upgrade.v1_1_0.test.UpgradePortalPreferencesTest.java

License:Open Source License

@Test
public void testUpgradeDefaultViewPreferences() throws Exception {
    String[] views = { "day", "month", "week", "agenda" };

    String view = views[RandomTestUtil.randomInt(0, views.length - 1)];

    String preferencesXML = getPreferences(_NAMESPACE_OLD_SESSION_CLICKS, "calendar-portlet-default-view",
            view);//from  w w w .j a va  2  s. c  om

    _portalPreferences.setPreferences(preferencesXML);

    PortalPreferencesLocalServiceUtil.updatePortalPreferences(_portalPreferences);

    _upgradeProcess.upgrade();

    PortalPreferences portalPreferences = reloadPortalPreferences(_portalPreferences);

    String value = getPreference(portalPreferences.getPreferences(), _NAMESPACE_NEW_SESSION_CLICKS,
            "com.liferay.calendar.web_defaultView");

    Assert.assertEquals(view, value);
}

From source file:com.liferay.ratings.verify.test.VerifyRatingsTest.java

License:Open Source License

@Test
public void testVerifyStatsWithEntries() throws Exception {
    int totalEntries = RandomTestUtil.randomInt(1, 10);
    double totalScore = 0.0;

    for (int i = 0; i < totalEntries; i++) {
        totalScore += addVote();//from  w  w w .  j a v  a2  s.  c  o  m
    }

    doVerify();

    RatingsStats ratingStats = RatingsStatsLocalServiceUtil.getStats(_CLASS_NAME, _CLASS_PK);

    Assert.assertEquals(totalEntries, ratingStats.getTotalEntries());
    Assert.assertEquals(totalScore, ratingStats.getTotalScore(), 0.0001);
    Assert.assertEquals(totalScore / totalEntries, ratingStats.getAverageScore(), 0.0001);
}