/**
* 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.asset.service.test;
import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.asset.kernel.model.AssetCategory;
import com.liferay.asset.kernel.model.AssetVocabulary;
import com.liferay.asset.kernel.service.AssetCategoryLocalServiceUtil;
import com.liferay.asset.kernel.service.AssetVocabularyLocalServiceUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.ListTypeConstants;
import com.liferay.portal.kernel.model.Organization;
import com.liferay.portal.kernel.model.OrganizationConstants;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.IndexerRegistryUtil;
import com.liferay.portal.kernel.service.OrganizationLocalServiceUtil;
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.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.kernel.util.LocaleUtil;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Michael C. Han
*/
@RunWith(Arquillian.class)
@Sync
public class AssetCategoryLocalServiceTest {
@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
new LiferayIntegrationTestRule();
@Before
public void setUp() throws Exception {
_group = GroupTestUtil.addGroup();
_organizationIndexer = IndexerRegistryUtil.getIndexer(
Organization.class);
}
@After
public void tearDown() throws Exception {
if (_organizationIndexer != null) {
IndexerRegistryUtil.register(_organizationIndexer);
}
}
@Test
public void testDeleteCategory() throws Exception {
Map<Locale, String> titleMap = new HashMap<>();
titleMap.put(LocaleUtil.US, RandomTestUtil.randomString());
ServiceContext serviceContext =
ServiceContextTestUtil.getServiceContext(
_group.getGroupId(), TestPropsValues.getUserId());
AssetVocabulary assetVocabulary =
AssetVocabularyLocalServiceUtil.addVocabulary(
TestPropsValues.getUserId(), _group.getGroupId(),
RandomTestUtil.randomString(), titleMap, null, null,
serviceContext);
AssetCategory assetCategory = AssetCategoryLocalServiceUtil.addCategory(
TestPropsValues.getUserId(), _group.getGroupId(),
RandomTestUtil.randomString(), assetVocabulary.getVocabularyId(),
serviceContext);
serviceContext.setAssetCategoryIds(
new long[] {assetCategory.getCategoryId()});
_organization = OrganizationLocalServiceUtil.addOrganization(
TestPropsValues.getUserId(),
OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID,
RandomTestUtil.randomString(),
OrganizationConstants.TYPE_ORGANIZATION, 0, 0,
ListTypeConstants.ORGANIZATION_STATUS_DEFAULT,
RandomTestUtil.randomString(), true, serviceContext);
TestAssetIndexer testAssetIndexer = new TestAssetIndexer();
testAssetIndexer.setExpectedValues(
Organization.class.getName(), _organization.getOrganizationId());
if (_organizationIndexer == null) {
_organizationIndexer = IndexerRegistryUtil.getIndexer(
Organization.class);
}
IndexerRegistryUtil.register(testAssetIndexer);
AssetCategoryLocalServiceUtil.deleteCategory(assetCategory, true);
}
@DeleteAfterTestRun
private Group _group;
@DeleteAfterTestRun
private Organization _organization;
private Indexer<Organization> _organizationIndexer;
}