001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.test.util;
016    
017    import com.liferay.counter.service.CounterLocalServiceUtil;
018    import com.liferay.portal.model.ResourceBlock;
019    import com.liferay.portal.service.ResourceBlockLocalServiceUtil;
020    
021    /**
022     * @author Alberto Chaparro
023     */
024    public class ResourceBlockTestUtil {
025    
026            public static ResourceBlock addResourceBlock(long groupId, String name)
027                    throws Exception {
028    
029                    long resourceBlockId = CounterLocalServiceUtil.increment(
030                            ResourceBlock.class.getName());
031    
032                    ResourceBlock resourceBlock =
033                            ResourceBlockLocalServiceUtil.createResourceBlock(resourceBlockId);
034    
035                    resourceBlock.setCompanyId(TestPropsValues.getCompanyId());
036                    resourceBlock.setGroupId(groupId);
037                    resourceBlock.setName(name);
038                    resourceBlock.setPermissionsHash(RandomTestUtil.randomString());
039                    resourceBlock.setReferenceCount(0);
040    
041                    return ResourceBlockLocalServiceUtil.addResourceBlock(resourceBlock);
042            }
043    
044            public static ResourceBlock addResourceBlock(String name) throws Exception {
045                    return addResourceBlock(RandomTestUtil.nextLong(), name);
046            }
047    
048    }