/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portlet.documentlibrary.service; import com.liferay.document.library.kernel.exception.NoSuchFolderException; import com.liferay.document.library.kernel.model.DLFolderConstants; import com.liferay.document.library.kernel.service.DLAppServiceUtil; import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.model.ResourceConstants; import com.liferay.portal.kernel.model.RoleConstants; import com.liferay.portal.kernel.repository.model.Folder; import com.liferay.portal.kernel.security.auth.PrincipalThreadLocal; import com.liferay.portal.kernel.security.permission.ActionKeys; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun; import com.liferay.portal.kernel.test.util.GroupTestUtil; import com.liferay.portal.kernel.test.util.RandomTestUtil; import com.liferay.portal.kernel.test.util.RoleTestUtil; import com.liferay.portal.kernel.test.util.ServiceContextTestUtil; import com.liferay.portal.kernel.test.util.TestPropsValues; import com.liferay.portlet.documentlibrary.service.permission.DLPermission; import org.junit.After; import org.junit.Before; /** * @author Alexander Chow */ public abstract class BaseDLAppTestCase { @Before public void setUp() throws Exception { _name = PrincipalThreadLocal.getName(); group = GroupTestUtil.addGroup(); targetGroup = GroupTestUtil.addGroup(); try { DLAppServiceUtil.deleteFolder( group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test Folder"); } catch (NoSuchFolderException nsfe) { } ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext( group.getGroupId(), TestPropsValues.getUserId()); parentFolder = DLAppServiceUtil.addFolder( group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test Folder", RandomTestUtil.randomString(), serviceContext); RoleTestUtil.addResourcePermission( RoleConstants.GUEST, DLPermission.RESOURCE_NAME, ResourceConstants.SCOPE_GROUP, String.valueOf(group.getGroupId()), ActionKeys.VIEW); } @After public void tearDown() throws Exception { PrincipalThreadLocal.setName(_name); RoleTestUtil.removeResourcePermission( RoleConstants.GUEST, DLPermission.RESOURCE_NAME, ResourceConstants.SCOPE_GROUP, String.valueOf(group.getGroupId()), ActionKeys.VIEW); } protected static final String CONTENT = "Content: Enterprise. Open Source. For Life."; @DeleteAfterTestRun protected Group group; protected Folder parentFolder; @DeleteAfterTestRun protected Group targetGroup; private String _name; }