/** * 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.message.boards.lar.test; import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; import com.liferay.message.boards.kernel.model.MBCategory; import com.liferay.message.boards.kernel.model.MBCategoryConstants; import com.liferay.message.boards.kernel.service.MBCategoryLocalServiceUtil; import com.liferay.message.boards.kernel.service.MBCategoryServiceUtil; import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.model.StagedModel; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.test.rule.AggregateTestRule; import com.liferay.portal.kernel.test.rule.Sync; import com.liferay.portal.kernel.test.rule.SynchronousDestinationTestRule; 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.StringPool; import com.liferay.portal.lar.test.BaseStagedModelDataHandlerTestCase; import com.liferay.portal.test.rule.LiferayIntegrationTestRule; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.Assert; import org.junit.ClassRule; import org.junit.Rule; import org.junit.runner.RunWith; /** * @author Daniel Kocsis */ @RunWith(Arquillian.class) @Sync public class MBCategoryStagedModelDataHandlerTest extends BaseStagedModelDataHandlerTestCase { @ClassRule @Rule public static final AggregateTestRule aggregateTestRule = new AggregateTestRule( new LiferayIntegrationTestRule(), SynchronousDestinationTestRule.INSTANCE); @Override protected Map<String, List<StagedModel>> addDependentStagedModelsMap( Group group) throws Exception { Map<String, List<StagedModel>> dependentStagedModelsMap = new HashMap<>(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext( group.getGroupId(), TestPropsValues.getUserId()); MBCategory category = MBCategoryServiceUtil.addCategory( TestPropsValues.getUserId(), MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, RandomTestUtil.randomString(), StringPool.BLANK, serviceContext); addDependentStagedModel( dependentStagedModelsMap, MBCategory.class, category); return dependentStagedModelsMap; } @Override protected StagedModel addStagedModel( Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception { List<StagedModel> dependentStagedModels = dependentStagedModelsMap.get( MBCategory.class.getSimpleName()); MBCategory category = (MBCategory)dependentStagedModels.get(0); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext( group.getGroupId(), TestPropsValues.getUserId()); return MBCategoryServiceUtil.addCategory( TestPropsValues.getUserId(), category.getCategoryId(), RandomTestUtil.randomString(), StringPool.BLANK, serviceContext); } @Override protected StagedModel getStagedModel(String uuid, Group group) { try { return MBCategoryLocalServiceUtil.getMBCategoryByUuidAndGroupId( uuid, group.getGroupId()); } catch (Exception e) { return null; } } @Override protected Class<? extends StagedModel> getStagedModelClass() { return MBCategory.class; } @Override protected void validateImport( Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception { List<StagedModel> dependentStagedModels = dependentStagedModelsMap.get( MBCategory.class.getSimpleName()); Assert.assertEquals( dependentStagedModels.toString(), 1, dependentStagedModels.size()); MBCategory category = (MBCategory)dependentStagedModels.get(0); MBCategoryLocalServiceUtil.getMBCategoryByUuidAndGroupId( category.getUuid(), group.getGroupId()); } @Override protected void validateImportedStagedModel( StagedModel stagedModel, StagedModel importedStagedModel) throws Exception { super.validateImportedStagedModel(stagedModel, importedStagedModel); MBCategory category = (MBCategory)stagedModel; MBCategory importedCategory = (MBCategory)importedStagedModel; Assert.assertEquals(category.getName(), importedCategory.getName()); Assert.assertEquals( category.getDescription(), importedCategory.getDescription()); Assert.assertEquals( category.getDisplayStyle(), importedCategory.getDisplayStyle()); Assert.assertEquals( category.getThreadCount(), importedCategory.getThreadCount()); Assert.assertEquals( category.getMessageCount(), importedCategory.getMessageCount()); Assert.assertEquals( category.getLastPostDate(), importedCategory.getLastPostDate()); } }