Example usage for com.liferay.portal.kernel.test.context ContextUserReplace ContextUserReplace

List of usage examples for com.liferay.portal.kernel.test.context ContextUserReplace ContextUserReplace

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.test.context ContextUserReplace ContextUserReplace.

Prototype

public ContextUserReplace(User user) throws Exception 

Source Link

Usage

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

License:Open Source License

@Test
public void testGetUnapprovedCalendarBookingsForOmniadmin() throws Exception {

    ServiceContext serviceContext = createServiceContext();

    Calendar calendar = CalendarTestUtil.addCalendar(_user1, serviceContext);

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addRegularCalendarBooking(_user1, calendar,
            serviceContext);//from ww  w.  ja  v a2s.c  om

    calendarBooking.setStatus(WorkflowConstants.STATUS_PENDING);

    CalendarBookingLocalServiceUtil.updateCalendarBooking(calendarBooking);

    int[] statuses = { WorkflowConstants.STATUS_PENDING };

    List<CalendarBooking> calendarBookings = Collections.emptyList();

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_omnidminUser)) {

        calendarBookings = CalendarBookingServiceUtil.getCalendarBookings(calendar.getCalendarId(), statuses);
    }

    Assert.assertTrue(!calendarBookings.isEmpty());
}

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

License:Open Source License

@Test
public void testGetUnapprovedCalendarBookingsForRegularUser() throws Exception {

    ServiceContext serviceContext = createServiceContext();

    Calendar calendar = CalendarTestUtil.addCalendar(_user1, serviceContext);

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addRegularCalendarBooking(_user1, calendar,
            serviceContext);/*from   w  w  w . ja  va 2s  .  c  o m*/

    calendarBooking.setStatus(WorkflowConstants.STATUS_PENDING);

    CalendarBookingLocalServiceUtil.updateCalendarBooking(calendarBooking);

    int[] statuses = { WorkflowConstants.STATUS_PENDING };

    List<CalendarBooking> calendarBookings = Collections.emptyList();

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_user1)) {

        calendarBookings = CalendarBookingServiceUtil.getCalendarBookings(calendar.getCalendarId(), statuses);
    }

    Assert.assertTrue(!calendarBookings.isEmpty());

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_user2)) {

        calendarBookings = CalendarBookingServiceUtil.getCalendarBookings(calendar.getCalendarId(), statuses);
    }

    Assert.assertTrue(calendarBookings.toString(), calendarBookings.isEmpty());
}

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

License:Open Source License

@Sync
@Test/*  www .j av  a 2  s .  c om*/
public void testIsManageableFromGroup() throws Exception {
    Group liveGroup = GroupTestUtil.addGroup();

    GroupTestUtil.enableLocalStaging(liveGroup);

    Group notStagedGroup = GroupTestUtil.addGroup();

    Group stagingGroup = liveGroup.getStagingGroup();

    User adminUser = UserTestUtil.addOmniAdminUser();

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(adminUser)) {

        Calendar notStagedCalendar = getGroupCalendar(notStagedGroup);

        Assert.assertTrue(CalendarServiceUtil.isManageableFromGroup(notStagedCalendar.getCalendarId(),
                notStagedGroup.getGroupId()));
        Assert.assertTrue(CalendarServiceUtil.isManageableFromGroup(notStagedCalendar.getCalendarId(),
                liveGroup.getGroupId()));
        Assert.assertTrue(CalendarServiceUtil.isManageableFromGroup(notStagedCalendar.getCalendarId(),
                stagingGroup.getGroupId()));

        Calendar liveCalendar = getGroupCalendar(liveGroup);

        Assert.assertFalse(CalendarServiceUtil.isManageableFromGroup(liveCalendar.getCalendarId(),
                notStagedGroup.getGroupId()));
        Assert.assertFalse(CalendarServiceUtil.isManageableFromGroup(liveCalendar.getCalendarId(),
                liveGroup.getGroupId()));
        Assert.assertFalse(CalendarServiceUtil.isManageableFromGroup(liveCalendar.getCalendarId(),
                stagingGroup.getGroupId()));

        Calendar stagingCalendar = getGroupCalendar(stagingGroup);

        Assert.assertFalse(CalendarServiceUtil.isManageableFromGroup(stagingCalendar.getCalendarId(),
                notStagedGroup.getGroupId()));
        Assert.assertFalse(CalendarServiceUtil.isManageableFromGroup(stagingCalendar.getCalendarId(),
                liveGroup.getGroupId()));
        Assert.assertTrue(CalendarServiceUtil.isManageableFromGroup(stagingCalendar.getCalendarId(),
                stagingGroup.getGroupId()));
    } finally {
        GroupLocalServiceUtil.deleteGroup(liveGroup);
        GroupLocalServiceUtil.deleteGroup(notStagedGroup);
        UserLocalServiceUtil.deleteUser(adminUser);
    }
}

From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java

License:Open Source License

@Test
public void testAdminCancelCheckout() throws Exception {
    FileEntry fileEntry = null;/*from   w  w w.j  av  a2  s  . c om*/

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_authorUser)) {

        fileEntry = createFileEntry(StringUtil.randomString());

        DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext);
    }

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(TestPropsValues.getUser())) {

        DLAppServiceUtil.cancelCheckOut(fileEntry.getFileEntryId());

        fileEntry = DLAppServiceUtil.getFileEntry(fileEntry.getFileEntryId());

        Assert.assertFalse(fileEntry.isCheckedOut());
    }
}

From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java

License:Open Source License

@Test(expected = FileEntryLockException.MustOwnLock.class)
public void testAdminOverrideCheckout() throws Exception {
    FileEntry fileEntry = null;/* w  w w  . ja v  a 2  s  . co m*/

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_authorUser)) {

        fileEntry = createFileEntry(StringUtil.randomString());

        DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext);
    }

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(TestPropsValues.getUser())) {

        DLAppServiceUtil.checkInFileEntry(fileEntry.getFileEntryId(), false, StringPool.NULL, _serviceContext);
    }
}

From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java

License:Open Source License

@Test(expected = FileEntryLockException.MustOwnLock.class)
public void testAdminUpdateCheckedOutFile() throws Exception {
    FileEntry fileEntry = null;/*from  ww w  . j  a v a2s  .  com*/

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_authorUser)) {

        fileEntry = createFileEntry(StringUtil.randomString());

        DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext);
    }

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(TestPropsValues.getUser())) {

        updateFileEntry(fileEntry.getFileEntryId());
    }
}

From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java

License:Open Source License

@Test(expected = PrincipalException.MustHavePermission.class)
public void testCancelCheckOutWithoutPermissionOverrideCheckout() throws Exception {

    FileEntry fileEntry = null;/* w w  w .  ja va 2 s . c o m*/

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_authorUser)) {

        fileEntry = createFileEntry(StringUtil.randomString());

        DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext);
    }

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_overriderUser)) {

        DLAppServiceUtil.cancelCheckOut(fileEntry.getFileEntryId());
    }
}

From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java

License:Open Source License

@Test
public void testCancelCheckoutWithPermissionOverrideCheckout() throws Exception {

    Role role = RoleTestUtil.addRole("Overrider", RoleConstants.TYPE_REGULAR,
            DLFileEntryConstants.getClassName(), ResourceConstants.SCOPE_GROUP_TEMPLATE,
            String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), ActionKeys.OVERRIDE_CHECKOUT);

    try {//from   w w w. j a  v a  2s  .  c om
        UserLocalServiceUtil.setRoleUsers(role.getRoleId(), new long[] { _overriderUser.getUserId() });

        FileEntry fileEntry = null;

        try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_authorUser)) {

            fileEntry = createFileEntry(StringUtil.randomString());

            DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext);
        }

        try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_overriderUser)) {

            DLAppServiceUtil.cancelCheckOut(fileEntry.getFileEntryId());

            fileEntry = DLAppServiceUtil.getFileEntry(fileEntry.getFileEntryId());

            Assert.assertFalse(fileEntry.isCheckedOut());
        }
    } finally {
        RoleLocalServiceUtil.deleteRole(role.getRoleId());
    }
}

From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java

License:Open Source License

@Test(expected = FileEntryLockException.MustOwnLock.class)
public void testCheckInWithoutPermissionOverrideCheckout() throws Exception {

    FileEntry fileEntry = null;/*from   ww w.  java2 s  .c om*/

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_authorUser)) {

        fileEntry = createFileEntry(StringUtil.randomString());

        DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext);
    }

    try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_overriderUser)) {

        DLAppServiceUtil.checkInFileEntry(fileEntry.getFileEntryId(), false, StringUtil.randomString(),
                _serviceContext);
    }
}

From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java

License:Open Source License

@Test(expected = FileEntryLockException.MustOwnLock.class)
public void testCheckInWithPermissionOverrideCheckout() throws Exception {
    Role role = RoleTestUtil.addRole("Overrider", RoleConstants.TYPE_REGULAR,
            DLFileEntryConstants.getClassName(), ResourceConstants.SCOPE_GROUP_TEMPLATE,
            String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), ActionKeys.OVERRIDE_CHECKOUT);

    try {//from   www.  jav  a  2 s .  c om
        UserLocalServiceUtil.setRoleUsers(role.getRoleId(), new long[] { _overriderUser.getUserId() });

        FileEntry fileEntry = null;

        try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_authorUser)) {

            fileEntry = createFileEntry(StringUtil.randomString());

            DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext);
        }

        try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_overriderUser)) {

            DLAppServiceUtil.checkInFileEntry(fileEntry.getFileEntryId(), false, StringPool.NULL,
                    _serviceContext);
        }
    } finally {
        RoleLocalServiceUtil.deleteRole(role.getRoleId());
    }
}