/**
* 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.asset.kernel.model.AssetEntry;
import com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil;
import com.liferay.document.library.kernel.model.DLFolder;
import com.liferay.document.library.kernel.model.DLFolderConstants;
import com.liferay.document.library.kernel.service.DLAppServiceUtil;
import com.liferay.document.library.kernel.service.DLFolderLocalServiceUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.test.rule.AggregateTestRule;
import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun;
import com.liferay.portal.kernel.test.rule.Sync;
import com.liferay.portal.kernel.test.rule.SynchronousDestinationTestRule;
import com.liferay.portal.kernel.test.util.GroupTestUtil;
import com.liferay.portal.kernel.test.util.RandomTestUtil;
import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
import com.liferay.portal.kernel.test.util.TestPropsValues;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
/**
* @author Michael C. Han
*/
@Sync
public class DLFolderLocalServiceTest {
@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
new AggregateTestRule(
new LiferayIntegrationTestRule(),
SynchronousDestinationTestRule.INSTANCE);
@Before
public void setUp() throws Exception {
_group = GroupTestUtil.addGroup();
}
@Test
public void testGetNoAssetEntries() throws Exception {
ServiceContext serviceContext =
ServiceContextTestUtil.getServiceContext(
_group.getGroupId(), TestPropsValues.getUserId());
Folder folder = DLAppServiceUtil.addFolder(
_group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
RandomTestUtil.randomString(), RandomTestUtil.randomString(),
serviceContext);
DLFolder dlFolder = DLFolderLocalServiceUtil.getDLFolder(
folder.getFolderId());
AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
DLFolder.class.getName(), dlFolder.getFolderId());
Assert.assertNotNull(assetEntry);
List<DLFolder> noAssetDLFolders =
DLFolderLocalServiceUtil.getNoAssetFolders();
AssetEntryLocalServiceUtil.deleteAssetEntry(assetEntry);
List<DLFolder> dlFolders = new ArrayList<>(
DLFolderLocalServiceUtil.getNoAssetFolders());
dlFolders.removeAll(noAssetDLFolders);
Assert.assertEquals(dlFolders.toString(), 1, dlFolders.size());
Assert.assertEquals(dlFolder, dlFolders.get(0));
}
@DeleteAfterTestRun
private Group _group;
}