Example usage for com.liferay.portal.kernel.test.util RoleTestUtil addRole

List of usage examples for com.liferay.portal.kernel.test.util RoleTestUtil addRole

Introduction

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

Prototype

public static Role addRole(String roleName, int roleType, String resourceName, int scope, String primKey,
            String actionId) throws Exception 

Source Link

Usage

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  . jav a  2  s  . co m
        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 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 {// w  ww . ja v a2  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());
    }
}

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

License:Open Source License

@Test(expected = FileEntryLockException.MustOwnLock.class)
public void testUpdateWithPermissionOverrideCheckout() 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);

    RoleTestUtil.addResourcePermission(role, DLFileEntryConstants.getClassName(),
            ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID),
            ActionKeys.UPDATE);/*from   ww w . j av a 2  s .c  o m*/

    try {
        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)) {

            updateFileEntry(fileEntry.getFileEntryId());
        }
    } finally {
        RoleLocalServiceUtil.deleteRole(role.getRoleId());
    }
}

From source file:com.liferay.site.service.persistence.test.GroupServicePermissionTest.java

License:Open Source License

protected void givePermissionToManageSubsites(Group group) throws Exception {

    Role role = RoleTestUtil.addRole("Subsites Admin", RoleConstants.TYPE_SITE, Group.class.getName(),
            ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID),
            ActionKeys.MANAGE_SUBGROUPS);

    long[] roleIds = { role.getRoleId() };

    UserGroupRoleLocalServiceUtil.addUserGroupRoles(_user.getUserId(), group.getGroupId(), roleIds);
}

From source file:com.liferay.trash.service.webserver.test.WebServerTrashTest.java

License:Open Source License

@Override
public void setUp() throws Exception {
    super.setUp();

    _user = UserTestUtil.addUser(null, group.getGroupId());

    String portletId = PortletProviderUtil.getPortletId(TrashEntry.class.getName(),
            PortletProvider.Action.VIEW);

    _role = RoleTestUtil.addRole("Trash Admin", RoleConstants.TYPE_REGULAR, portletId,
            ResourceConstants.SCOPE_COMPANY, String.valueOf(TestPropsValues.getCompanyId()),
            ActionKeys.ACCESS_IN_CONTROL_PANEL);

    RoleTestUtil.addResourcePermission(RoleConstants.GUEST, DLPermission.RESOURCE_NAME,
            ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID),
            ActionKeys.VIEW);/*from   w w  w  .ja  v  a 2  s  .  c  om*/
}