List of usage examples for com.liferay.portal.kernel.test.util RandomTestUtil randomInt
public static int randomInt()
From source file:com.liferay.asset.service.test.AssetEntryQueryTest.java
License:Open Source License
@Test public void testOrderByViewCountsAsc() throws Exception { int[] viewCounts = new int[10]; int[] orderedViewCounts = new int[10]; for (int i = 0; i < viewCounts.length; i++) { int randomInt = RandomTestUtil.randomInt(); viewCounts[i] = randomInt;/*from w ww . java2s . c om*/ orderedViewCounts[i] = randomInt; } Arrays.sort(orderedViewCounts); testOrderByViewCount(viewCounts, orderedViewCounts, "ASC"); }
From source file:com.liferay.asset.service.test.AssetEntryQueryTest.java
License:Open Source License
@Test public void testOrderByViewCountsDesc() throws Exception { int[] viewCounts = new int[10]; int[] orderedViewCounts = new int[10]; for (int i = 0; i < viewCounts.length; i++) { int randomInt = RandomTestUtil.randomInt(); viewCounts[i] = randomInt;/*from w w w.ja v a 2 s . c om*/ orderedViewCounts[i] = randomInt; } Arrays.sort(orderedViewCounts); ArrayUtil.reverse(orderedViewCounts); testOrderByViewCount(viewCounts, orderedViewCounts, "DESC"); }
From source file:com.liferay.calendar.search.test.CalendarFixture.java
License:Open Source License
public CalendarBooking addCalendarBooking(LocalizedValuesMap titleLocalizedValuesMap, Calendar calendar, ServiceContext serviceContext) throws PortalException { long startTime = DateUtil.newTime() + RandomTestUtil.randomInt(); long endTime = startTime + Time.HOUR; CalendarBooking calendarBooking = _calendarBookingLocalService.addCalendarBooking( serviceContext.getUserId(), calendar.getCalendarId(), new long[0], CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT, 0, titleLocalizedValuesMap.getValues(), Collections.emptyMap(), null, startTime, endTime, false, null, 0, "email", 0, "email", serviceContext);/* w w w . j a va2 s.co m*/ _calendarBookings.add(calendarBooking); return calendarBooking; }
From source file:com.liferay.calendar.service.CalendarBookingLocalServiceTest.java
License:Open Source License
@Test public void testUpdateCalendarBookingWorkflowActionPublish() throws PortalException { ServiceContext serviceContext = createServiceContext(); CalendarResource calendarResource = CalendarResourceUtil.getUserCalendarResource(_user.getUserId(), serviceContext);//from ww w .j av a2 s . c o m Calendar calendar = calendarResource.getDefaultCalendar(); long startTime = DateUtil.newTime(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); CalendarBooking calendarBooking = CalendarBookingLocalServiceUtil.addCalendarBooking(_user.getUserId(), calendar.getCalendarId(), new long[0], CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT, RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomString(), startTime, startTime + (Time.HOUR * 10), false, null, 0, null, 0, null, serviceContext); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); calendarBooking = CalendarBookingLocalServiceUtil.updateCalendarBooking(_user.getUserId(), calendarBooking.getCalendarBookingId(), calendar.getCalendarId(), new long[0], RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomString(), startTime, startTime + (Time.HOUR * 10), false, null, 0, null, 0, null, RandomTestUtil.randomInt(), serviceContext); Assert.assertEquals(WorkflowConstants.STATUS_APPROVED, calendarBooking.getStatus()); }
From source file:com.liferay.calendar.service.CalendarBookingLocalServiceTest.java
License:Open Source License
@Test public void testUpdateCalendarBookingWorkflowActionSaveDraft() throws PortalException { ServiceContext serviceContext = createServiceContext(); CalendarResource calendarResource = CalendarResourceUtil.getUserCalendarResource(_user.getUserId(), serviceContext);//from ww w . j a v a 2 s. co m Calendar calendar = calendarResource.getDefaultCalendar(); long startTime = DateUtil.newTime(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); CalendarBooking calendarBooking = CalendarBookingLocalServiceUtil.addCalendarBooking(_user.getUserId(), calendar.getCalendarId(), new long[0], CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT, RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomString(), startTime, startTime + (Time.HOUR * 10), false, null, 0, null, 0, null, serviceContext); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); calendarBooking = CalendarBookingLocalServiceUtil.updateCalendarBooking(_user.getUserId(), calendarBooking.getCalendarBookingId(), calendar.getCalendarId(), new long[0], RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomString(), startTime, startTime + (Time.HOUR * 10), false, null, 0, null, 0, null, RandomTestUtil.randomInt(), serviceContext); Assert.assertEquals(WorkflowConstants.STATUS_DRAFT, calendarBooking.getStatus()); }
From source file:com.liferay.calendar.service.test.CalendarBookingLocalServiceTest.java
License:Open Source License
@Test public void testUpdateCalendarBookingPreservesChildReminders() throws Exception { ServiceContext serviceContext = createServiceContext(); Calendar calendar = CalendarTestUtil.addCalendar(_user, serviceContext); Calendar invitedCalendar = CalendarTestUtil.addCalendar(calendar.getCalendarResource(), serviceContext); long startTime = System.currentTimeMillis(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); CalendarBooking calendarBooking = CalendarBookingTestUtil.addCalendarBooking(_user, calendar, new long[] { invitedCalendar.getCalendarId() }, RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(), startTime, startTime + (Time.HOUR * 10), null, RandomTestUtil.randomInt(), NotificationType.EMAIL, RandomTestUtil.randomInt(), NotificationType.EMAIL, serviceContext); CalendarBooking childCalendarBooking = getChildCalendarBooking(calendarBooking); childCalendarBooking = CalendarBookingLocalServiceUtil.updateStatus(_user.getUserId(), childCalendarBooking, CalendarBookingWorkflowConstants.STATUS_MAYBE, serviceContext); int firstReminder = RandomTestUtil.randomInt(); int secondReminder = RandomTestUtil.randomInt(1, firstReminder); childCalendarBooking = CalendarBookingLocalServiceUtil.updateCalendarBooking(_user.getUserId(), childCalendarBooking.getCalendarBookingId(), childCalendarBooking.getCalendarId(), new long[0], childCalendarBooking.getTitleMap(), childCalendarBooking.getDescriptionMap(), childCalendarBooking.getLocation(), startTime, startTime + (Time.HOUR * 10), childCalendarBooking.getAllDay(), childCalendarBooking.getRecurrence(), firstReminder, NotificationType.EMAIL.getValue(), secondReminder, NotificationType.EMAIL.getValue(), serviceContext);//www . j av a 2s . c o m calendarBooking = CalendarBookingLocalServiceUtil.updateCalendarBooking(_user.getUserId(), calendarBooking.getCalendarBookingId(), calendarBooking.getCalendarId(), new long[] { invitedCalendar.getCalendarId() }, calendarBooking.getTitleMap(), calendarBooking.getDescriptionMap(), calendarBooking.getLocation(), startTime, startTime + (Time.HOUR * 11), calendarBooking.getAllDay(), calendarBooking.getRecurrence(), RandomTestUtil.randomInt(), calendarBooking.getFirstReminderType(), RandomTestUtil.randomInt(), calendarBooking.getSecondReminderType(), serviceContext); childCalendarBooking = getChildCalendarBooking(calendarBooking); Assert.assertNotEquals(calendarBooking.getFirstReminder(), childCalendarBooking.getFirstReminder()); Assert.assertNotEquals(calendarBooking.getSecondReminder(), childCalendarBooking.getSecondReminder()); Assert.assertEquals(firstReminder, childCalendarBooking.getFirstReminder()); Assert.assertEquals(secondReminder, childCalendarBooking.getSecondReminder()); }
From source file:com.liferay.calendar.test.util.CalendarTestUtil.java
License:Open Source License
public static Calendar addCalendar(CalendarResource calendarResource, ServiceContext serviceContext) throws PortalException { return CalendarLocalServiceUtil.addCalendar(calendarResource.getUserId(), calendarResource.getGroupId(), calendarResource.getCalendarResourceId(), RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(), calendarResource.getTimeZoneId(), RandomTestUtil.randomInt(), false, false, false, serviceContext); }
From source file:com.liferay.dynamic.data.mapping.form.evaluator.impl.internal.functions.GetPropertyFunctionTest.java
License:Open Source License
@Test public void testGetValue() { int randomInt = RandomTestUtil.randomInt(); DDMFormFieldEvaluationResult ddmFormFieldEvaluationResult = createDDMFormFieldEvaluationResult("Field", "value", randomInt); Map<String, List<DDMFormFieldEvaluationResult>> ddmFormFieldEvaluationResultsMap = createDDMFormFieldEvaluationResultsMap( ddmFormFieldEvaluationResult); GetPropertyFunction getPropertyFunction = new GetPropertyFunction(ddmFormFieldEvaluationResultsMap, "value"); int propertyValue = evaluateGetPropertyFunction(getPropertyFunction, "Field"); Assert.assertEquals(randomInt, propertyValue); }
From source file:com.liferay.dynamic.data.mapping.form.evaluator.impl.internal.functions.SetPropertyFunctionTest.java
License:Open Source License
@Test public void testSetValue() { DDMFormFieldEvaluationResult ddmFormFieldEvaluationResult1 = createDDMFormFieldEvaluationResult("Field1", "value", RandomTestUtil.randomInt()); int field2Value = RandomTestUtil.randomInt(); DDMFormFieldEvaluationResult ddmFormFieldEvaluationResult2 = createDDMFormFieldEvaluationResult("Field2", "value", field2Value); Map<String, List<DDMFormFieldEvaluationResult>> ddmFormFieldEvaluationResultsMap = createDDMFormFieldEvaluationResultsMap( ddmFormFieldEvaluationResult1, ddmFormFieldEvaluationResult2); SetPropertyFunction setPropertyFunction = new SetPropertyFunction(ddmFormFieldEvaluationResultsMap, "value"); int field1NewValue = RandomTestUtil.randomInt(); setPropertyFunction.evaluate("Field1", field1NewValue); assertValue(field1NewValue, ddmFormFieldEvaluationResult1); assertValue(field2Value, ddmFormFieldEvaluationResult2); }
From source file:com.liferay.message.boards.comment.internal.MBCommentManagerImplTest.java
License:Open Source License
@Test public void testGetCommentsCount() throws Exception { long classPK = RandomTestUtil.randomLong(); long classNameId = RandomTestUtil.randomLong(); int commentsCount = RandomTestUtil.randomInt(); Mockito.when(_mbMessageLocalService.getDiscussionMessagesCount(classNameId, classPK, WorkflowConstants.STATUS_APPROVED)).thenReturn(commentsCount); Mockito.when(_portal.getClassNameId(_CLASS_NAME)).thenReturn(classNameId); Assert.assertEquals(commentsCount, _mbCommentManagerImpl.getCommentsCount(_CLASS_NAME, classPK)); }